Skip to content

Commit 58c6103

Browse files
committed
Mock schema_empty module
1 parent 5fed6a5 commit 58c6103

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

tests/test_schema.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import types
12
import pytest
3+
import inspect
24
import datajoint as dj
5+
from unittest.mock import patch
36
from inspect import getmembers
47
from . import schema
58
from . import PREFIX
69

710

811
class Ephys(dj.Imported):
9-
definition = """ # This is already declared in ./schema.py
12+
definition = """ # This is already declare in ./schema.py
1013
"""
1114

1215

@@ -24,19 +27,42 @@ def part_selector(attr):
2427
return False
2528

2629

30+
@pytest.fixture
31+
def schema_empty_module(schema_any, schema_empty):
32+
# Mimic tests_old/schema_empty
33+
namespace_dict = {
34+
'_': schema_any,
35+
'schema': schema_empty,
36+
'Ephys': Ephys,
37+
}
38+
module = types.ModuleType('schema_empty')
39+
40+
# Add classes to the module's namespace
41+
for k, v in namespace_dict.items():
42+
setattr(module, k, v)
43+
44+
# Spawn missing classes in the caller's (self) namespace.
45+
# Then add them to the mock module's namespace.
46+
module.schema.context = None
47+
module.schema.spawn_missing_classes(context=None)
48+
for k, v in locals().items():
49+
if inspect.isclass(v):
50+
setattr(module, k, v)
51+
return module
52+
53+
2754
@pytest.fixture
2855
def schema_empty(connection_test, schema_any):
2956
context = {
3057
**schema.LOCALS_ANY,
3158
"Ephys": Ephys
3259
}
33-
schema_emp = dj.Schema(PREFIX + "_test1", context=context, connection=connection_test)
34-
schema_emp(Ephys)
60+
schema_empty = dj.Schema(PREFIX + "_test1", context=context, connection=connection_test)
61+
schema_empty(Ephys)
3562
# load the rest of the classes
36-
schema_emp.spawn_missing_classes()
37-
breakpoint()
38-
yield schema_emp
39-
schema_emp.drop()
63+
schema_empty.spawn_missing_classes(context=context)
64+
yield schema_empty
65+
schema_empty.drop()
4066

4167

4268
def test_schema_size_on_disk(schema_any):
@@ -55,10 +81,10 @@ def test_drop_unauthorized():
5581
info_schema.drop()
5682

5783

58-
def test_namespace_population(schema_empty, schema_any):
84+
def test_namespace_population(schema_empty_module):
5985
for name, rel in getmembers(schema, relation_selector):
60-
assert hasattr(schema_empty, name), "{name} not found in schema_empty".format(name=name)
61-
assert rel.__base__ is getattr(schema_empty, name).__base__, "Wrong tier for {name}".format(name=name)
86+
assert hasattr(schema_empty_module, name), "{name} not found in schema_empty".format(name=name)
87+
assert rel.__base__ is getattr(schema_empty_module, name).__base__, "Wrong tier for {name}".format(name=name)
6288

6389
for name_part in dir(rel):
6490
if name_part[0].isupper() and part_selector(getattr(rel, name_part)):

0 commit comments

Comments
 (0)