def test_property_type_checking(self): test_artifact = artifact.Artifact(_TEST_SIMPLE_INSTANCE_SCHEMA) with self.assertRaises(RuntimeError): test_artifact.property1 = '45.5' test_artifact_2 = artifact.Artifact(_TEST_SIMPLE_INSTANCE_SCHEMA) test_artifact_2.metadata['property1'] = '45.4' with self.assertRaises(RuntimeError): test_artifact_2.serialize()
def test_setting_metadata(self): test_artifact = artifact.Artifact(_TEST_SIMPLE_INSTANCE_SCHEMA) test_artifact.property1 = 45.5 test_artifact.metadata['property2'] = 'test string' test_artifact.metadata['custom_property'] = 4 test_artifact.metadata['custom_arr'] = [2, 4] expected_json = json.loads( '{ "property1": 45.5, "property2": "test string", "custom_property": 4, "custom_arr": [2, 4]}' ) self.assertEqual(expected_json, test_artifact.metadata)
def get_artifact(self) -> artifact.Artifact: """Gets an artifact object by parsing metadata or creating one from uri.""" if self.metadata_file and self.output_name: return entrypoint_utils.get_artifact_from_output( self.metadata_file, self.output_name) else: # Provide an empty schema when returning a raw Artifact. result = artifact.Artifact( instance_schema=artifact.DEFAULT_ARTIFACT_SCHEMA) result.uri = self.uri return result
def test_complete_artifact(self): test_artifact = artifact.Artifact(_TEST_SIMPLE_INSTANCE_SCHEMA) test_artifact.property1 = 45.5 test_artifact.metadata['property2'] = 'test string' test_artifact.metadata['custom_property'] = 4 test_artifact.metadata['custom_arr'] = [2, 4] test_artifact.name = 'test_artifact' test_artifact.uri = 'gcs://some_bucket/some_object' with open( os.path.join(os.path.dirname(__file__), 'test_data', 'expected_complete_artifact.json')) as json_file: expected_artifact_json = json.load(json_file) self.assertEqual(expected_artifact_json, json.loads(test_artifact.serialize()))