def test_single_struct(self): """ Make a StructDef out of a Unimodel class """ schema_reader = PythonSchemaReader(NodeData) ast = schema_reader.get_ast() self.assertEquals(ast.root_struct_name, NodeData.get_name()) self.assertEquals(len(ast.structs), 1) self.assertEquals(ast.structs[0].common.name, NodeData.get_name())
def test_manually_added(self): """ tests whether dependant structs are detected and pulled into the schema """ schema_reader = PythonSchemaReader( NodeData, struct_classes=[A]) ast = schema_reader.get_ast() self.assertEquals(ast.root_struct_name, NodeData.get_name()) struct_names = sorted( [s.common.name for s in ast.structs]) expected_struct_names = sorted([ A.get_name(), NodeData.get_name()]) self.assertEquals( struct_names, expected_struct_names)
def test_recursive_datatype(self): """ tests whether ASTs can be built for recursive data types. """ schema_reader = PythonSchemaReader(TreeNode) ast = schema_reader.get_ast() self.assertEquals(ast.root_struct_name, TreeNode.get_name()) struct_names = sorted( [s.common.name for s in ast.structs]) expected_struct_names = sorted([ TreeNode.get_name(), NodeData.get_name()]) self.assertEquals( struct_names, expected_struct_names)
def test_all_fields(self): schema_reader = PythonSchemaReader(AllTypes) ast = schema_reader.get_ast() self.assertEquals(ast.root_struct_name, AllTypes.get_name()) struct_names = sorted( [s.common.name for s in ast.structs]) expected_struct_names = sorted([ AllTypes.get_name(), NodeData.get_name(), A.get_name(), TestUnion.get_name()]) self.assertEquals( struct_names, expected_struct_names)