@@ -29,7 +29,11 @@ def part_selector(attr):
29
29
30
30
@pytest .fixture
31
31
def schema_empty_module (schema_any , schema_empty ):
32
- # Mimic tests_old/schema_empty
32
+ """
33
+ Mock the module tests_old.schema_empty.
34
+ The test `test_namespace_population` will check that the module contains all the
35
+ classes in schema_any, after running `spawn_missing_classes`.
36
+ """
33
37
namespace_dict = {
34
38
'_' : schema_any ,
35
39
'schema' : schema_empty ,
@@ -41,13 +45,6 @@ def schema_empty_module(schema_any, schema_empty):
41
45
for k , v in namespace_dict .items ():
42
46
setattr (module , k , v )
43
47
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
48
return module
52
49
53
50
@@ -82,6 +79,19 @@ def test_drop_unauthorized():
82
79
83
80
84
81
def test_namespace_population (schema_empty_module ):
82
+ """
83
+ With the schema_empty_module fixture, this test
84
+ mimics the behavior of `spawn_missing_classes`, as if the schema
85
+ was declared in a separate module and `spawn_missing_classes` was called in that namespace.
86
+ """
87
+ # Spawn missing classes in the caller's (self) namespace.
88
+ schema_empty_module .schema .context = None
89
+ schema_empty_module .schema .spawn_missing_classes (context = None )
90
+ # Then add them to the mock module's namespace.
91
+ for k , v in locals ().items ():
92
+ if inspect .isclass (v ):
93
+ setattr (schema_empty_module , k , v )
94
+
85
95
for name , rel in getmembers (schema , relation_selector ):
86
96
assert hasattr (schema_empty_module , name ), "{name} not found in schema_empty" .format (name = name )
87
97
assert rel .__base__ is getattr (schema_empty_module , name ).__base__ , "Wrong tier for {name}" .format (name = name )
0 commit comments