def from_json_dict(cls, json_dict) -> 'Schema.Attribute': name = json_dict.get('name', None) data_type = qualified_name_to_object( json_dict.get('data_type', None)) # TODO (nf, 20160627): convert JSON value to Python value value = json_dict.get('value', None) return Schema.Attribute(name, data_type, value=value)
def test_qualified_name_to_object(self): self.assertIs(qualified_name_to_object('float'), float) self.assertIs(qualified_name_to_object('builtins.float'), float) self.assertIs(qualified_name_to_object('unittest.case.TestCase'), TestCase) self.assertIs(qualified_name_to_object('xml.etree.ElementTree.ElementTree'), ElementTree) with self.assertRaisesRegex(ImportError, "No module named 'numpi'"): qualified_name_to_object('numpi.ndarray') with self.assertRaisesRegex(AttributeError, "module 'builtins' has no attribute 'flaot'"): qualified_name_to_object('flaot')
def test_qualified_name_to_object(self): self.assertIs(qualified_name_to_object('float'), float) self.assertIs(qualified_name_to_object('builtins.float'), float) self.assertIs(qualified_name_to_object('unittest.case.TestCase'), TestCase) self.assertIs( qualified_name_to_object('xml.etree.ElementTree.ElementTree'), ElementTree) with self.assertRaisesRegex(ImportError, "No module named 'numpi'"): qualified_name_to_object('numpi.ndarray') with self.assertRaisesRegex( AttributeError, "module 'builtins' has no attribute 'flaot'"): qualified_name_to_object('flaot')
def from_json_dict(cls, json_dict) -> 'Schema.Variable': name = json_dict.get('name', None) data_type = qualified_name_to_object( json_dict.get('data_type', None)) dimension_names = json_dict.get('dimension_names', []) json_attributes = json_dict.get('attributes', []) attributes = [] for json_attribute in json_attributes: attributes.append( Schema.Attribute.from_json_dict(json_attribute)) return Schema.Variable(name, data_type, dimension_names=dimension_names, attributes=attributes)