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_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_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_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]]})