def testSimpleFork(self): with phlgitu_fixture.lone_worker_context() as worker: # pylint has faulty detection here # pylint: disable=not-callable worker.repo("branch", "fork") worker.commit_new_file("add ONLY_MASTER", "ONLY_MASTER") worker.repo("checkout", "fork") # pylint: enable=not-callable worker.commit_new_file("add ONLY_FORK", "ONLY_FORK") worker.commit_new_file("add ONLY_FORK2", "ONLY_FORK2") rawDiff = phlgit_diff.raw_diff_range_to_here(worker.repo, "master") rawDiff2 = phlgit_diff.raw_diff_range(worker.repo, "master", "fork") rawDiff3 = phlgit_diff.raw_diff_range(worker.repo, "master", "fork", 1000) self.assertEqual( set(["ONLY_FORK", "ONLY_FORK2"]), phlgit_diff.parse_filenames_from_raw_diff(rawDiff)) self.assertEqual( set(["ONLY_FORK", "ONLY_FORK2"]), phlgit_diff.parse_filenames_from_raw_diff(rawDiff2)) self.assertEqual( set(["ONLY_FORK", "ONLY_FORK2"]), phlgit_diff.parse_filenames_from_raw_diff(rawDiff3))
def test_C_ReduceAddMassiveFile(self): with phlgitu_fixture.lone_worker_context() as worker: # make a large file to base our changes on large_content = "lorem ipsum\n" * 1000 worker.commit_new_file_on_new_branch( "diff_branch", "add large_file", "large_file", large_content) def make_diff(max_bytes): return abdt_differ.make_raw_diff( worker.repo, "master", "diff_branch", max_bytes) # establish a baseline size for the diff diff_result = make_diff(100000) self.assertIn("lorem ipsum", diff_result.diff) original_diff_size = len(diff_result.diff) # [ C] a diff still outside the limits can be reduced # to the diffstat diff_result = make_diff(500) self.assertNotIn("lorem ipsum", diff_result.diff) diffstat_diff_size = len(diff_result.diff) self.assertTrue( any( isinstance(r, abdt_differ.DiffStatReduction) for r in diff_result.reduction_list)) self.assertLess( diffstat_diff_size, original_diff_size)
def testSimpleFork(self): with phlgitu_fixture.lone_worker_context() as worker: # pylint has faulty detection here # pylint: disable=not-callable worker.repo("branch", "fork") worker.commit_new_file("add ONLY_MASTER", "ONLY_MASTER") worker.repo("checkout", "fork") # pylint: enable=not-callable worker.commit_new_file("add ONLY_FORK", "ONLY_FORK") worker.commit_new_file("add ONLY_FORK2", "ONLY_FORK2") rawDiff = phlgit_diff.raw_diff_range_to_here( worker.repo, "master") rawDiff2 = phlgit_diff.raw_diff_range( worker.repo, "master", "fork") rawDiff3 = phlgit_diff.raw_diff_range( worker.repo, "master", "fork", 1000) self.assertEqual( set(["ONLY_FORK", "ONLY_FORK2"]), phlgit_diff.parse_filenames_from_raw_diff(rawDiff)) self.assertEqual( set(["ONLY_FORK", "ONLY_FORK2"]), phlgit_diff.parse_filenames_from_raw_diff(rawDiff2)) self.assertEqual( set(["ONLY_FORK", "ONLY_FORK2"]), phlgit_diff.parse_filenames_from_raw_diff(rawDiff3))
def test_C_ReduceAddMassiveFile(self): with phlgitu_fixture.lone_worker_context() as worker: # make a large file to base our changes on large_content = "lorem ipsum\n" * 1000 worker.commit_new_file_on_new_branch("diff_branch", "add large_file", "large_file", large_content) def make_diff(max_bytes): return abdt_differ.make_raw_diff(worker.repo, "master", "diff_branch", max_bytes) # establish a baseline size for the diff diff_result = make_diff(100000) self.assertIn("lorem ipsum", diff_result.diff) original_diff_size = len(diff_result.diff) # [ C] a diff still outside the limits can be reduced # to the diffstat diff_result = make_diff(500) self.assertNotIn("lorem ipsum", diff_result.diff) diffstat_diff_size = len(diff_result.diff) self.assertTrue( any( isinstance(r, abdt_differ.DiffStatReduction) for r in diff_result.reduction_list)) self.assertLess(diffstat_diff_size, original_diff_size)
def test_A_Breathing(self): with phlgitu_fixture.lone_worker_context() as worker: branch_name = "diff_branch" breakable_repo = _BreakableRepo(worker.repo) refcache_repo = phlgitx_refcache.Repo(breakable_repo) differ = abdt_differresultcache.Cache(refcache_repo) worker.repo("checkout", "-b", branch_name) def make_diff(max_bytes): return differ.checkout_make_raw_diff( "refs/heads/master", "refs/heads/{}".format(branch_name), max_bytes ) # make sure that the repo raises if used when disabled with self.assertRaises(_BreakableRepoUsedError): with breakable_repo.disabled_context(): with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # An empty diff raises abdt_differ.NoDiffError with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # An empty diff raises abdt_differ.NoDiffError again, this time the # refcache_repo won't be used to do diffing so it won't need to # reset the cache with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # An empty diff raises abdt_differ.NoDiffError again # make sure that the repo isn't used at all, by disabling it with breakable_repo.disabled_context(): with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # the differ will detach HEAD so attach to branch again before # making any more commits on the branch worker.repo("checkout", branch_name) worker.commit_new_file("make a test diff", "newfile", "test content") # a diff within the limits passes straight through diff_result = make_diff(1000) self.assertIn("test content", diff_result.diff) # a diff within the limits passes straight through again diff_result = make_diff(1000) self.assertIn("test content", diff_result.diff) # raise if a diff cannot be reduced to the limits with self.assertRaises(abdt_exception.LargeDiffException): make_diff(1) # raise if a diff cannot be reduced to the limits again with self.assertRaises(abdt_exception.LargeDiffException): make_diff(1)
def test_A_Breathing(self): with phlgitu_fixture.lone_worker_context() as worker: self.assertFalse( phlgitx_ignoreident.is_repo_definitely_ignoring( worker.repo.working_dir)) phlgitx_ignoreident.ensure_repo_ignoring( worker.repo.working_dir) self.assertTrue( phlgitx_ignoreident.is_repo_definitely_ignoring( worker.repo.working_dir)) phlgitx_ignoreident.ensure_repo_ignoring( worker.repo.working_dir)
def test_A_Breathing(self): with phlgitu_fixture.lone_worker_context() as worker: worker.commit_new_file_on_new_branch( "diff_branch", "make a test diff", "newfile", "test content") def make_diff(max_bytes): return abdt_differ.make_raw_diff( worker.repo, "master", "diff_branch", max_bytes) # [ A] a diff within the limits passes straight through diff_result = make_diff(1000) self.assertIn("test content", diff_result.diff) # [ A] raise if a diff cannot be reduced to the limits with self.assertRaises(abdt_exception.LargeDiffException): make_diff(1)
def test_B_ReduceSmallChangeOnLargeFile(self): with phlgitu_fixture.lone_worker_context() as worker: # make a large file to base our changes on large_content = "lorem ipsum\n" * 1000 worker.commit_new_file( "add large_file", "large_file", large_content) worker.append_to_file_on_new_branch( "diff_branch", "make small diff", "large_file", "test content") def make_diff(max_bytes): return abdt_differ.make_raw_diff( worker.repo, "master", "diff_branch", max_bytes) # establish a baseline size for the diff diff_result = make_diff(100000) self.assertIn("test content", diff_result.diff) original_diff_size = len(diff_result.diff) # [ B] a diff outside the limits can be reduced ok with less # context diff_result = make_diff(2000) self.assertIn("test content", diff_result.diff) reduced_context_diff_size = len(diff_result.diff) self.assertTrue( any( isinstance(r, abdt_differ.LessContextReduction) for r in diff_result.reduction_list)) self.assertLess( reduced_context_diff_size, original_diff_size) # [ B] a diff still outside the limits can be reduced ok with no # context diff_result = make_diff(500) self.assertIn("test content", diff_result.diff) no_context_diff_size = len(diff_result.diff) self.assertTrue( any( isinstance(r, abdt_differ.RemoveContextReduction) for r in diff_result.reduction_list)) self.assertLess( no_context_diff_size, reduced_context_diff_size)
def test_A_Breathing(self): with phlgitu_fixture.lone_worker_context() as worker: worker.commit_new_file_on_new_branch("diff_branch", "make a test diff", "newfile", "test content") def make_diff(max_bytes): return abdt_differ.make_raw_diff(worker.repo, "master", "diff_branch", max_bytes) # [ A] a diff within the limits passes straight through diff_result = make_diff(1000) self.assertIn("test content", diff_result.diff) # [ A] raise if a diff cannot be reduced to the limits with self.assertRaises(abdt_exception.LargeDiffException): make_diff(1)
def test_B_ReduceSmallChangeOnLargeFile(self): with phlgitu_fixture.lone_worker_context() as worker: # make a large file to base our changes on large_content = "lorem ipsum\n" * 1000 worker.commit_new_file("add large_file", "large_file", large_content) worker.append_to_file_on_new_branch("diff_branch", "make small diff", "large_file", "test content") def make_diff(max_bytes): return abdt_differ.make_raw_diff(worker.repo, "master", "diff_branch", max_bytes) # establish a baseline size for the diff diff_result = make_diff(100000) self.assertIn("test content", diff_result.diff) original_diff_size = len(diff_result.diff) # [ B] a diff outside the limits can be reduced ok with less # context diff_result = make_diff(2000) self.assertIn("test content", diff_result.diff) reduced_context_diff_size = len(diff_result.diff) self.assertTrue( any( isinstance(r, abdt_differ.LessContextReduction) for r in diff_result.reduction_list)) self.assertLess(reduced_context_diff_size, original_diff_size) # [ B] a diff still outside the limits can be reduced ok with no # context diff_result = make_diff(500) self.assertIn("test content", diff_result.diff) no_context_diff_size = len(diff_result.diff) self.assertTrue( any( isinstance(r, abdt_differ.RemoveContextReduction) for r in diff_result.reduction_list)) self.assertLess(no_context_diff_size, reduced_context_diff_size)
def test_D_UpdateInfoAttributes(self): all_attributes = list(phlgitx_ignoreattributes._REPO_ATTRIBUTES_TUPLE) all_attributes.append("") all_lines = itertools.combinations( all_attributes, len(all_attributes) - 1) for lines in all_lines: content = "\n".join(lines) print(content) print("---") with phlgitu_fixture.lone_worker_context() as worker: working_dir = worker.repo.working_dir attributes_path = os.path.join( working_dir, '.git/info/attributes') phlsys_fs.write_text_file(attributes_path, content) # should not throw phlgitx_ignoreattributes.ensure_repo_ignoring( worker.repo.working_dir)
def test_A_Breathing(self): with phlgitu_fixture.lone_worker_context() as worker: branch_name = 'diff_branch' breakable_repo = _BreakableRepo(worker.repo) refcache_repo = phlgitx_refcache.Repo(breakable_repo) differ = abdt_differresultcache.Cache(refcache_repo) # pylint has faulty detection here # pylint: disable=not-callable worker.repo('checkout', '-b', branch_name) # pylint: enable=not-callable def make_diff(max_bytes): return differ.checkout_make_raw_diff( "refs/heads/master", "refs/heads/{}".format(branch_name), max_bytes) # make sure that the repo raises if used when disabled with self.assertRaises(_BreakableRepoUsedError): with breakable_repo.disabled_context(): with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # An empty diff raises abdt_differ.NoDiffError with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # An empty diff raises abdt_differ.NoDiffError again, this time the # refcache_repo won't be used to do diffing so it won't need to # reset the cache with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # An empty diff raises abdt_differ.NoDiffError again # make sure that the repo isn't used at all, by disabling it with breakable_repo.disabled_context(): with self.assertRaises(abdt_differ.NoDiffError): make_diff(1) # the differ will detach HEAD so attach to branch again before # making any more commits on the branch # pylint has faulty detection here # pylint: disable=not-callable worker.repo('checkout', branch_name) # pylint: enable=not-callable worker.commit_new_file("make a test diff", "newfile", "test content") # a diff within the limits passes straight through diff_result = make_diff(1000) self.assertIn("test content", diff_result.diff) # a diff within the limits passes straight through again diff_result = make_diff(1000) self.assertIn("test content", diff_result.diff) # raise if a diff cannot be reduced to the limits with self.assertRaises(abdt_exception.LargeDiffException): make_diff(1) # raise if a diff cannot be reduced to the limits again with self.assertRaises(abdt_exception.LargeDiffException): make_diff(1)