def test_reflect_deleted_files_on_merge_in(self, mock_create_labbooks): lb, client = mock_create_labbooks[0], mock_create_labbooks[1] with open('/tmp/s1.txt', 'w') as s1: s1.write('original-file\ndata') FileOperations.insert_file(lb, section='code', src_file=s1.name) bm = BranchManager(lb, username=UT_USERNAME) nb = bm.create_branch(f'new-branch') assert os.path.exists(os.path.join(lb.root_dir, 'code', 's1.txt')) FileOperations.delete_files(lb, 'code', ['s1.txt']) assert lb.is_repo_clean assert not os.path.exists(os.path.join(lb.root_dir, 'code', 's1.txt')) bm.workon_branch(bm.workspace_branch) assert os.path.exists(os.path.join(lb.root_dir, 'code', 's1.txt')) merge_q = f""" mutation x {{ mergeFromBranch(input: {{ owner: "{UT_USERNAME}", labbookName: "{UT_LBNAME}", otherBranchName: "{nb}" }}) {{ labbook{{ name description activeBranchName }} }} }} """ r = client.execute(merge_q) assert 'errors' not in r assert r['data']['mergeFromBranch']['labbook']['activeBranchName'] == 'master' assert not os.path.exists(os.path.join(lb.root_dir, 'code', 's1.txt'))
def test_remove_file_success(self, mock_labbook, sample_src_file): lb = mock_labbook[2] new_file_data = FO.insert_file(lb, "code", sample_src_file) base_name = os.path.basename(new_file_data['key']) assert os.path.exists(os.path.join(lb.root_dir, 'code', base_name)) FO.delete_files(lb, 'code', [base_name]) assert not os.path.exists(os.path.join(lb.root_dir, 'code', base_name))
def test_remove_file_fail_old_prototype(self, mock_labbook, sample_src_file): lb = mock_labbook[2] new_file_data = FO.insert_file(lb, "code", sample_src_file) base_name = os.path.basename(new_file_data['key']) assert os.path.exists(os.path.join(lb.root_dir, 'code', base_name)) with pytest.raises(ValueError): FO.delete_files(lb, 'code', base_name)
def mutate_and_get_payload(cls, root, info, owner, labbook_name, section, file_paths, client_mutation_id=None): username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) with lb.lock(): FileOperations.delete_files(lb, section, file_paths) return DeleteLabbookFiles(success=True)
def test_remove_empty_dir(self, mock_labbook, sample_src_file): lb = mock_labbook[2] FO.makedir(lb, "output/testdir") new_file_path = FO.insert_file(lb, "output", sample_src_file, "testdir") base_name = os.path.basename(new_file_path['key']) assert os.path.exists(os.path.join(lb.root_dir, 'output', 'testdir', base_name)) # Delete the directory FO.delete_files(lb, "output", ["testdir"]) assert not os.path.exists(os.path.join(lb.root_dir, 'output', 'testdir', base_name)) assert not os.path.exists(os.path.join(lb.root_dir, 'output', 'testdir'))
def test_remove_dir(self, mock_labbook, sample_src_file): lb = mock_labbook[2] FO.makedir(lb, "output/testdir") new_file_path = FO.insert_file(lb, "output", sample_src_file, "testdir") base_name = os.path.basename(new_file_path['key']) assert os.path.exists(os.path.join(lb.root_dir, 'output', 'testdir', base_name)) # Note! Now that remove() uses force=True, no special action is needed for directories. # Delete the directory FO.delete_files(lb, "output", ["testdir"]) assert not os.path.exists(os.path.join(lb.root_dir, 'output', 'testdir', base_name)) assert not os.path.exists(os.path.join(lb.root_dir, 'output', 'testdir'))
def test_remove_many_files(self, mock_labbook, sample_src_file): lb = mock_labbook[2] test_files = [f"testfile{x}.txt" for x in range(15)] for test_file in test_files: with open(os.path.join(lb.root_dir, 'code', test_file), 'wt') as sample_f: sample_f.write("blah") assert os.path.exists(os.path.join(lb.root_dir, 'code', test_file)) lb.git.add_all() lb.git.commit("making test data") FO.delete_files(lb, "code", test_files) for test_file in test_files: assert not os.path.exists(os.path.join(lb.root_dir, 'code', test_file))
def test_get_commits_with_local_changes(self, mock_config_file, remote_labbook_repo, mock_labbook_lfs_disabled): # When the branch is up to date, ensure it doesn't report being behind. lb = mock_labbook_lfs_disabled[2] lb.add_remote("origin", remote_labbook_repo) bm = BranchManager(lb, username='******') bm.workon_branch("testing-branch") # Do some stuff to make commits locally FileOperations.makedir(lb, 'code/rand_dir', create_activity_record=True) FileOperations.delete_files(lb, 'code', ['rand_dir']) behind = bm.get_commits_behind() ahead = bm.get_commits_ahead() assert ahead == 4 assert behind == 0
def test_remove_file_fail(self, mock_labbook, sample_src_file): lb = mock_labbook[2] FO.insert_file(lb, "code", sample_src_file) new_file_path = os.path.join('blah', 'invalid.txt') with pytest.raises(ValueError): FO.delete_files(lb, 'code', [new_file_path])
def test_with_the_whole_suite_of_file_operations_on_an_UNTRACKED_labbook( self, mock_labbook): x, y, lb = mock_labbook hash_0 = lb.git.commit_hash FileOperations.set_untracked(labbook=lb, section='input') hash_1 = lb.git.commit_hash assert hash_0 != hash_1 with open('/tmp/unittestfile', 'wb') as f: f.write('àbčdęfghįjkłmñöpqrštūvwxÿż0123456789'.encode('utf-8')) assert not os.path.exists( os.path.join(lb.root_dir, 'input', 'unittestfile')) r = FileOperations.put_file(lb, section="input", src_file=f.name, dst_path='') assert os.path.exists( os.path.join(lb.root_dir, 'input', 'unittestfile')) hash_2 = lb.git.commit_hash FileOperations.delete_files(lb, section='input', relative_paths=['unittestfile']) hash_3 = lb.git.commit_hash target_path = os.path.join(lb.root_dir, 'input', 'unittestfile') assert not os.path.exists(target_path) assert lb.is_repo_clean # Hash_2 == hash_3 because we delete a file in an UNTRACKED section assert hash_2 == hash_3 FileOperations.makedir(lb, 'input/sample-untracked-dir/nested-dir') hash_4 = lb.git.commit_hash assert hash_3 == hash_4 with open('/tmp/unittestfile', 'wb') as f: f.write('aaaaaæ'.encode('utf-8')) FileOperations.put_file(lb, section='input', src_file=f.name, dst_path='sample-untracked-dir/nested-dir') hash_5 = lb.git.commit_hash assert hash_4 == hash_5 FileOperations.move_file( lb, section='input', src_rel_path='sample-untracked-dir/nested-dir/unittestfile', dst_rel_path='unittestfile') assert not os.path.exists( os.path.join(lb.root_dir, 'input', 'sample-untracked-dir/nested-dir/unittestfile')) assert os.path.exists( os.path.join(lb.root_dir, 'input', 'unittestfile')) hash_6 = lb.git.commit_hash assert hash_5 == hash_6 FileOperations.delete_files( lb, section='input', relative_paths=['sample-untracked-dir/nested-dir']) hash_7 = lb.git.commit_hash assert hash_6 == hash_7