def test_artifact_extension(tmp_path: Path) -> None: a0 = Artifact(tmp_path / 'a0') a0.b = [b'hello'] a0.c__bin = data_file(tmp_path / 'c0.bin') a0.d = {'e': [[0.0, 1.0]], 'f.bin': data_file(tmp_path / 'f0.bin')} a1 = Artifact(tmp_path / 'a1') a1.b = [b'good', b'bye'] a1.c__bin = data_file(tmp_path / 'c1.bin') a1.d = {'e': np.empty((0, 2)), 'f.bin': data_file(tmp_path / 'f1.bin')} a2 = Artifact(tmp_path / 'a2') a2.extend('subartifact', a0) a2.extend('subartifact', a1) assert_artifact_equals( a2, { 'subartifact': { 'b': [b'hello', b'good', b'bye'], 'c.bin': data_file_concat(tmp_path / 'c2.bin', [tmp_path / 'c0.bin', tmp_path / 'c1.bin']), 'd': { 'e': [[0.0, 1.0]], 'f.bin': data_file_concat( tmp_path / 'f2.bin', [tmp_path / 'f0.bin', tmp_path / 'f1.bin']) } } })
def test_array_assignment(tmp_path: Path) -> None: a = Artifact(tmp_path) a.b = np.ones((2, 3), dtype='float32') a.b = np.zeros((4, 5, 6), dtype='float32') a['c'] = np.ones((4, 5, 6), dtype='float32') a['c'] = np.ones((2, 3), dtype='uint16') assert_artifact_equals( a, { 'b': np.zeros((4, 5, 6), dtype='float32'), 'c': np.ones((2, 3), dtype='uint16') })
def test_byte_string_assignment(tmp_path: Path) -> None: a = Artifact(tmp_path) a.b = b'bee' a.b = b'buzz' a['c'] = b'sea' a['c'] = b'ahoy!' assert_artifact_equals(a, {'b': b'buzz', 'c': b'ahoy!'})
def test_float_assignment(tmp_path: Path) -> None: a = Artifact(tmp_path) a.b = 1.5 a.b = 2.5 a['c'] = 3.5 a['c'] = 4.5 assert_artifact_equals(a, {'b': 2.5, 'c': 4.5})
def test_list_assignment(tmp_path: Path) -> None: a = Artifact(tmp_path) a.b = [1, 2, 3] a.b = [4, 5, 6] a['c'] = [[7, 8], [9, 10]] a['c'] = [[11, 12, 13], [14, 15, 16]] assert_artifact_equals(a, { 'b': [4, 5, 6], 'c': [[11, 12, 13], [14, 15, 16]] })
def test_artifact_deletion(tmp_path: Path) -> None: a = Artifact(tmp_path / 'a') a.b = {'aa': {'bb': 0, 'cc': 1}} a.c = {'dd': {'ee': [2, 3, 4]}} a.d = [7, 8] a.e = {'blue': b'jeans'} a.f__bin = data_file(tmp_path / 'data.bin') del a.b del a['c'] assert_artifact_equals(a, { 'd': [7, 8], 'e': { 'blue': b'jeans' }, 'f.bin': tmp_path / 'data.bin' })
def test_array_file_deletion(tmp_path: Path) -> None: a = Artifact(tmp_path / 'a') a.b = [1, 2, 3] a.c = b'four five six' a.d = [7, 8] a.e = {'blue': b'jeans'} a.f__bin = data_file(tmp_path / 'data.bin') del a.b del a['c'] assert_artifact_equals(a, { 'd': [7, 8], 'e': { 'blue': b'jeans' }, 'f.bin': tmp_path / 'data.bin' })