def test_multiple_namespaces(self): exepected_parent_src = """import pyschema from pyschema.types import * from pyschema.core import NO_DEFAULT from test.pyschema_test_child import ChildWithOwnNameSpace class ChildWithSameNamespace(pyschema.Record): # WARNING: This class was generated by pyschema.to_python_source # there is a risk that any modification made to this class will be overwritten _namespace = 'pyschema_test_parent' pass class ParentWithNameSpace(pyschema.Record): # WARNING: This class was generated by pyschema.to_python_source # there is a risk that any modification made to this class will be overwritten _namespace = 'pyschema_test_parent' child = SubRecord(schema=ChildWithOwnNameSpace, nullable=True, default=None) other = SubRecord(schema=ChildWithSameNamespace, nullable=True, default=None) """ to_python_package([ParentWithNameSpace], self.tmp_path) src1 = self.get_file_content("pyschema_test_parent.py") self.assertEquals(src1, exepected_parent_src) src2 = self.get_file_content("test/pyschema_test_child.py") self.assertContainsOnlyClasses(src2, ["ChildWithOwnNameSpace"]) src3 = self.get_file_content("test/pyschema_test_grand_child.py") self.assertContainsOnlyClasses(src3, ["GrandChildWithOwnNameSpace"])
def test_package_generation_namespace(self): to_python_package([FooRecord], self.tmp_path) src = self.get_file_content("my/foo/bar.py") expected_src = header_source() + "\n" + TestSourceConversion.correct self.assertEquals(src, expected_src) expected_output_files = {"my/foo/bar.py", "my/foo/__init__.py", "my/__init__.py", "__init__.py"} output_files = set() for root, dirs, files in os.walk(self.tmp_path): for f in files: rel_path = os.path.relpath(os.path.join(root, f), self.tmp_path) output_files.add(rel_path) self.assertEquals(output_files, expected_output_files)
def test_package_generation_namespace(self): to_python_package([FooRecord], self.tmp_path) src = self.get_file_content("my/foo/bar.py") expected_src = header_source() + "\n" + TestSourceConversion.correct self.assertEquals(src, expected_src) expected_output_files = { 'my/foo/bar.py', 'my/foo/__init__.py', 'my/__init__.py', '__init__.py' } output_files = set() for root, dirs, files in os.walk(self.tmp_path): for f in files: rel_path = os.path.relpath(os.path.join(root, f), self.tmp_path) output_files.add(rel_path) self.assertEquals(output_files, expected_output_files)
def test_package_generation_no_namespace(self): to_python_package([Parent], self.tmp_path) src = self.get_file_content("__init__.py") expected_src = header_source() + "\n" + TestSubRecord.correct self.assertEquals(src, expected_src)