class TestRepository(unittest.TestCase): def setUp(self) -> None: self.di = DirectoryInfo() path = os.getcwd() self.di.init(path) self.di.add_branch_path('master') self.file_path = os.path.join(self.di.working_path, 'TESTING.txt') with open(self.file_path, "w+") as file: file.write('SOME STRING') self.rep = Repository() self.rep.set_directory_info(self.di) self.rep.init() def tearDown(self) -> None: if os.path.exists(self.di.cvs_path): shutil.rmtree(self.di.cvs_path) if os.path.exists(self.file_path): os.remove(self.file_path) def test_add_commit__should_copy_commit_files(self): index = Index() index.init_config() index.set_directory_info(self.di) index.add_new_file('TESTING.txt') commit = index.make_commit('Testing commit', 'master') self.rep.add_commit(commit) commits_path = self.di.get_commits_path('master') commit_path = os.path.join(commits_path, commit.commit_number) full_path = os.path.join(commit_path, 'TESTING.txt') self.assertTrue(os.path.exists(full_path))
def make_branch(self, name): self.load_config() di = DirectoryInfo() if di.branch_exists(name): print(f'Branch \'{name}\' already exists!') return di.add_branch_path(name) self.current_branch.copy_to_branch(name) print(f'Successfully made branch {name}')
class DirectoryInfoTest(unittest.TestCase): def setUp(self) -> None: self.info = DirectoryInfo() self.info.init(os.getcwd()) def test_init_should_initialize_working_path(self): result = self.info.working_path self.assertIsNotNone(result) def test_init_should_initialize_cvs_path(self): result = self.info.cvs_path self.assertTrue(result.endswith('CVS')) def test_init_should_initialize_index_path(self): result = self.info.index_path self.assertTrue(result.endswith('INDEX')) def test_add_branch_path_should_add_path_to_branch(self): self.info.add_branch_path("master") count = len(self.info.branches_paths) self.assertGreater(count, 0) def test_add_branch_path_should_add_path_to_commits(self): self.info.add_branch_path("master") count = len(self.info.branches_commits_paths) self.assertGreater(count, 0) def test_get_branch_path_should_get_path_to_branch(self): self.info.add_branch_path("master") path = self.info.get_branch_path("master") self.assertTrue(path.endswith("master")) def test_get_commits_path_should_get_commits_path(self): self.info.add_branch_path("master") path = self.info.get_commits_path("master") self.assertTrue(path.endswith("COMMITS"))