def test_get_property_via_subscript(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) self.assertEqual(metadata['version'], 'v0.1') self.assertEqual(metadata['summary']['title'], 'test_title')
def test_get_property(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) self.assertEqual(metadata.get_property("version"), 'v0.1') self.assertDictEqual(metadata.get_property('summary'), {'title': 'test_title'})
def test_nested_get_property(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title', 'description': 'test_description'}) self.assertEqual(metadata.get_property("summary.title"), metadata["summary"]["title"]) self.assertEqual(metadata.get_property("summary.description"), metadata["summary"]["description"]) self.assertEqual(metadata.get_property('summary.title'), 'test_title') self.assertEqual(metadata.get_property('summary.description'), 'test_description')
def test_save_to_data(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) data = metadata.save_to_data() metadata = Metadata() metadata.load_from_data(data) self.assertEqual(metadata['version'], 'v0.1') self.assertEqual(metadata['summary']['title'], 'test_title')
def test_save_to_file(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) metadata.save_to_path('test-save-to-file.yaml') metadata = Metadata() metadata.load_from_path('test-save-to-file.yaml') self.assertEqual(metadata['version'], 'v0.1') self.assertEqual(metadata['summary']['title'], 'test_title') os.unlink('test-save-to-file.yaml')
def test_set_property(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) metadata.set_property('info', 'more info') metadata.set_property('schema', {'data': 'int'}) self.assertEqual(metadata['version'], 'v0.1') self.assertEqual(metadata['summary']['title'], 'test_title') self.assertEqual(metadata['info'], 'more info') self.assertEqual(metadata['schema'], {'data': 'int'})
def test_modify_nested_property(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) metadata.set_property('summary.title', 'another_test_title') self.assertEqual(metadata['summary']['title'], 'another_test_title')
def test_modify_property(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {'title': 'test_title'}) metadata.set_property('version', 'v0.2') self.assertEqual(metadata['version'], 'v0.2')
def test_set_nested_property(self): metadata = Metadata() metadata.set_property('version', 'v0.1') metadata.set_property('summary', {}) metadata.set_property("summary.title", 'test_title') self.assertIn('title', metadata['summary']) self.assertEqual(metadata['summary']['title'], 'test_title')