1
+ import types
1
2
import pytest
3
+ import inspect
2
4
import datajoint as dj
5
+ from unittest .mock import patch
3
6
from inspect import getmembers
4
7
from . import schema
5
8
from . import PREFIX
6
9
7
10
8
11
class Ephys (dj .Imported ):
9
- definition = """ # This is already declared in ./schema.py
12
+ definition = """ # This is already declare in ./schema.py
10
13
"""
11
14
12
15
@@ -24,19 +27,42 @@ def part_selector(attr):
24
27
return False
25
28
26
29
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
+
27
54
@pytest .fixture
28
55
def schema_empty (connection_test , schema_any ):
29
56
context = {
30
57
** schema .LOCALS_ANY ,
31
58
"Ephys" : Ephys
32
59
}
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 )
35
62
# 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 ()
40
66
41
67
42
68
def test_schema_size_on_disk (schema_any ):
@@ -55,10 +81,10 @@ def test_drop_unauthorized():
55
81
info_schema .drop ()
56
82
57
83
58
- def test_namespace_population (schema_empty , schema_any ):
84
+ def test_namespace_population (schema_empty_module ):
59
85
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 )
62
88
63
89
for name_part in dir (rel ):
64
90
if name_part [0 ].isupper () and part_selector (getattr (rel , name_part )):
0 commit comments