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_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_dict_extension(tmp_path: Path) -> None: a = Artifact(tmp_path / 'a') a.extend( 'b', { 'c': np.empty((0, 2), dtype='uint16'), 'd.bin': data_file(tmp_path / 'd0.bin'), 'e': { 'f': [0.1, 0.2] } }) a.extend( 'b', { 'c': np.uint16([[1, 2], [3, 4]]), 'd.bin': data_file(tmp_path / 'd1.bin'), 'e': { 'f': [0.3, 0.4, 0.5] } }) assert_artifact_equals( a, { 'b': { 'c': np.uint16([[1, 2], [3, 4]]), 'd.bin': data_file_concat(tmp_path / 'd2.bin', [tmp_path / 'd0.bin', tmp_path / 'd1.bin']), 'e': { 'f': [0.1, 0.2, 0.3, 0.4, 0.5] } } })
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_path_extension(tmp_path: Path) -> None: a = Artifact(tmp_path / 'a') a.extend('b.bin', data_file(tmp_path / 'b0.bin')) a.extend('b.bin', data_file(tmp_path / 'b1.bin')) assert_artifact_equals( a, { 'b.bin': data_file_concat(tmp_path / 'b2.bin', [tmp_path / 'b0.bin', tmp_path / 'b1.bin']) })
def test_path_assignment(tmp_path: Path) -> None: a = Artifact(tmp_path / 'artifact') a.b__bin = data_file(tmp_path / 'b0.bin') a.b__bin = data_file(tmp_path / 'b1.bin') a['c.bin'] = data_file(tmp_path / 'c0.bin') a['c.bin'] = data_file(tmp_path / 'c1.bin') assert_artifact_equals(a, { 'b.bin': tmp_path / 'b1.bin', 'c.bin': tmp_path / 'c1.bin' })
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_empty_artifact_with_existing_dir(tmp_path: Path) -> None: a = Artifact(tmp_path) assert_artifact_equals( a, dict(__path__=tmp_path, __conf__={}, __meta__={ 'spec': None, 'status': 'done' })) assert isinstance(a.nonexistent_entry, Artifact)
def test_dict_assignment(tmp_path: Path) -> None: a = Artifact(tmp_path) a.dict = dict(a=[1, 2, 3], b=dict(c=[4], d=[5, 6])) assert_artifact_equals( a, {'dict': { 'a': [1, 2, 3], 'b': { 'c': [4], 'd': [5, 6] } }})
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_artifact_assignment(tmp_path: Path) -> None: a_src = Artifact(tmp_path / 'a_src') a_src.b.c = b'bee sea' a_src.d.e = [1, 2, 3, 4] a_src.f.g__bin = data_file(tmp_path / 'effigy.bin') a_dst = Artifact(tmp_path / 'a_dst') a_dst.a = a_src assert_artifact_equals( a_dst, { 'a': { 'b': { 'c': b'bee sea' }, 'd': { 'e': [1, 2, 3, 4] }, 'f': { 'g.bin': tmp_path / 'effigy.bin' } } })
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_opaque_file_deletion(tmp_path: Path) -> None: a = Artifact(tmp_path / 'a') a.b__bin = data_file(tmp_path / 'b.bin') a.c__bin = data_file(tmp_path / 'c.bin') a.d = [7, 8] a.e = {'blue': b'jeans'} a.f__bin = data_file(tmp_path / 'data.bin') del a.b__bin del a['c.bin'] 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' })
def test_array_extension(tmp_path: Path) -> None: a = Artifact(tmp_path) a.extend('b', np.uint16([[7, 8], [9, 10]])) a.extend('b', np.uint16([[11, 12]])) assert_artifact_equals(a, {'b': np.uint16([[7, 8], [9, 10], [11, 12]])})
def test_list_extension(tmp_path: Path) -> None: a = Artifact(tmp_path) a.extend('b', [[7, 8], [9, 10]]) a.extend('b', [[11, 12]]) assert_artifact_equals(a, {'b': [[7, 8], [9, 10], [11, 12]]})