@@ -29,7 +29,11 @@ def part_selector(attr):
2929
3030@pytest .fixture
3131def 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+ """
3337 namespace_dict = {
3438 '_' : schema_any ,
3539 'schema' : schema_empty ,
@@ -41,13 +45,6 @@ def schema_empty_module(schema_any, schema_empty):
4145 for k , v in namespace_dict .items ():
4246 setattr (module , k , v )
4347
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 )
5148 return module
5249
5350
@@ -82,6 +79,19 @@ def test_drop_unauthorized():
8279
8380
8481def 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+
8595 for name , rel in getmembers (schema , relation_selector ):
8696 assert hasattr (schema_empty_module , name ), "{name} not found in schema_empty" .format (name = name )
8797 assert rel .__base__ is getattr (schema_empty_module , name ).__base__ , "Wrong tier for {name}" .format (name = name )
0 commit comments