def test_checkout_basic(runner): with runner.isolated_filesystem(): assert runner.invoke(init).exit_code == 0 filename = 'file1.onnx' create_file(filename, 100) shutil.copyfile(filename, './copy') assert runner.invoke(commit, [filename]).exit_code == 0 mutate_file(filename, 100) assert runner.invoke(commit, [filename]).exit_code == 0 log = deserialize_log() checkout_hash = log[filename][0]['hash'] result = runner.invoke(checkout, [checkout_hash]) meta = deserialize_meta() assert result.exit_code == 0 assert cmp_files('./copy', filename) assert meta['file_head'][filename]['hash'] == checkout_hash assert meta['file_head'][filename]['index'] == 0
def test_checkout_invalid_commit(runner): with runner.isolated_filesystem(): assert runner.invoke(init).exit_code == 0 filename = 'file1.onnx' create_file(filename, 100) assert runner.invoke(commit, [filename]).exit_code == 0 mutate_file(filename, 100) assert runner.invoke(commit, [filename]).exit_code == 0 result = runner.invoke(checkout, ['foobar']) assert result.exit_code == 1 assert result.output == 'Commit hash not found\n'
def test_commit_no_spec_file(runner): with runner.isolated_filesystem(): lamby_dir = './.lamby' os.mkdir(lamby_dir) os.mkdir(lamby_dir + '/commit_objects') config_file = open(lamby_dir + '/config', "w+") config_file.write('{}') config_file.close() log_file = open(lamby_dir + '/log', "w+") log_file.write('{}') log_file.close() meta_file = open(lamby_dir + '/meta', "w+") meta_file.write('''{ \"file_head\": {}, \"latest_commit\": {} }''') meta_file.close() os.mkdir('dir1') create_file('file1.onnx', 100) create_file('dir1/file2.onnx', 100) result = runner.invoke(commit, ['-m', 'Foo Bar!']) assert result.exit_code == 0 log_file = deserialize_log() compressed_filename = './.lamby/commit_objects/' + \ log_file['file1.onnx'][0]['hash'] uncompressed_filename = log_file['file1.onnx'][0]['hash'] assert os.path.isfile(compressed_filename) copy_file(compressed_filename, uncompressed_filename) assert cmp_files('file1.onnx', uncompressed_filename) compressed_filename = './.lamby/commit_objects/' + \ log_file['file2.onnx'][0]['hash'] uncompressed_filename = log_file['file2.onnx'][0]['hash'] assert os.path.isfile(compressed_filename) copy_file(compressed_filename, uncompressed_filename) assert cmp_files('dir1/file2.onnx', uncompressed_filename)
def test_checkout_uncommitted_changes(runner): with runner.isolated_filesystem(): assert runner.invoke(init).exit_code == 0 filename = 'file1.onnx' create_file(filename, 100) assert runner.invoke(commit, [filename]).exit_code == 0 mutate_file(filename, 100) assert runner.invoke(commit, [filename]).exit_code == 0 mutate_file(filename, 100) log = deserialize_log() result = runner.invoke(checkout, [log[filename][0]['hash']]) assert result.exit_code == 1 assert result.output == 'Cannot checkout with uncommitted changes\n'
def test_commit_basic(runner): with runner.isolated_filesystem(): lamby_dir = './.lamby' os.mkdir(lamby_dir) os.mkdir(lamby_dir + '/commit_objects') config_file = open(lamby_dir + '/config', "w+") config_file.write('{}') config_file.close() log_file = open(lamby_dir + '/log', "w+") log_file.write('{}') log_file.close() meta_file = open(lamby_dir + '/meta', "w+") meta_file.write('''{ \"file_head\": {}, \"latest_commit\": {} }''') meta_file.close() filename = 'file1.onnx' message = 'Foo Bar!' create_file(filename, 100) result = runner.invoke(commit, [filename, '-m', message]) assert result.exit_code == 0 log_file = deserialize_log() compressed_filename = './.lamby/commit_objects/' + \ log_file[filename][0]['hash'] uncompressed_filename = log_file[filename][0]['hash'] assert log_file[filename][0]['message'] == message assert os.path.isfile(compressed_filename) copy_file(compressed_filename, uncompressed_filename) assert cmp_files(filename, uncompressed_filename)
def test_status_previous(runner): with runner.isolated_filesystem(): runner.invoke(init) create_file('f1.onnx', 100) result = runner.invoke(commit) assert result.exit_code == 0 create_file('f1.onnx', 200) result = runner.invoke(commit) assert result.exit_code == 0 log = deserialize_log() checkout_hash = log['f1.onnx'][0]['hash'] result = runner.invoke(checkout, [checkout_hash]) assert result.exit_code == 0 result = runner.invoke(status) assert result.exit_code == 0
def test_status_update(runner): with runner.isolated_filesystem(): runner.invoke(init) create_file('f1.onnx', 100) create_file('f2.onnx', 100) result = runner.invoke(commit) assert result.exit_code == 0 create_file('f1.onnx', 200) result = runner.invoke(status) assert result.exit_code == 0
def test_status_basic(runner): with runner.isolated_filesystem(): os.mkdir('./.lamby') os.mkdir('./.lamby/commit_objects') meta_str = """ { "file_head": { "f1.onnx": { "hash": "hash1", "index": 0 }, "f2.onnx": { "hash": "hash2", "index": 0 }, "f3.onnx": { "hash": "hash3", "index": 0 } }, "latest_commit": { "f1.onnx": "hash1", "f2.onnx": "hash2", "f3.onnx": "hash3" } } """ file = open('./.lamby/meta', 'w+') file.write(meta_str) file.close() create_file('f1.onnx', 500) create_file('f2.onnx', 500) create_file('f3.onnx', 500) copy_file('f1.onnx', './.lamby/commit_objects/' + "hash1") copy_file('f2.onnx', './.lamby/commit_objects/' + "hash2") copy_file('f3.onnx', './.lamby/commit_objects/' + "hash3") result = runner.invoke(status) assert result.exit_code == 0