From: Thomas Jarosch Date: Fri, 3 Jul 2015 19:20:24 +0000 (+0200) Subject: Ability to the run the unit tests without a .git directory X-Git-Tag: v2.2~41 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=188b845dea3d3d16da449efe1a0d01159c75d3ce;p=python-delta-tar Ability to the run the unit tests without a .git directory Useful for executing the tests during every rpm build. --- diff --git a/testing/test_deltatar.py b/testing/test_deltatar.py index 48ac776..a40526f 100644 --- a/testing/test_deltatar.py +++ b/testing/test_deltatar.py @@ -42,6 +42,8 @@ class DeltaTarTest(BaseTest): PASSWORD = None + GIT_DIR = '.git' + def setUp(self): ''' Create base test data @@ -59,6 +61,14 @@ class DeltaTarTest(BaseTest): self.consoleLogger = logging.StreamHandler() self.consoleLogger.setLevel(logging.DEBUG) + if not os.path.isdir(self.GIT_DIR): + # Not running inside git tree, take our + # own testing directory as source. + self.GIT_DIR = 'testing' + + if not os.path.isdir(self.GIT_DIR): + raise Exception('No input directory found: ' + self.GIT_DIR) + def tearDown(self): ''' Remove temporal files created by unit tests @@ -288,7 +298,7 @@ class DeltaTarTest(BaseTest): deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD, logger=self.consoleLogger) - shutil.copytree(".git", "source_dir2") + shutil.copytree(self.GIT_DIR, "source_dir2") # create first backup deltatar.create_full_backup( @@ -309,7 +319,7 @@ class DeltaTarTest(BaseTest): deltatar.restore_backup(target_path="source_dir2", backup_tar_path=tar_path) - self.check_equal_dirs('.git', 'source_dir2', deltatar) + self.check_equal_dirs(self.GIT_DIR, 'source_dir2', deltatar) def test_restore_multivol_manual_from_index(self): ''' @@ -1181,7 +1191,7 @@ class DeltaTarTest(BaseTest): def test_restore_from_index_diff_backup3(self): ''' - Creates a full backup of .git, modifies some random files, creates a + Creates a full backup of self.GIT_DIR, modifies some random files, creates a diff backup, then restores the diff backup with the full backup as a starting point. ''' @@ -1193,8 +1203,8 @@ class DeltaTarTest(BaseTest): logger=self.consoleLogger) shutil.rmtree("source_dir") - shutil.copytree(".git", "source_dir") - shutil.copytree(".git", "source_dir_diff") + shutil.copytree(self.GIT_DIR, "source_dir") + shutil.copytree(self.GIT_DIR, "source_dir_diff") # create first backup deltatar.create_full_backup( @@ -1228,7 +1238,7 @@ class DeltaTarTest(BaseTest): deltatar.restore_backup("target_dir", backup_tar_path=tar_path) # and check that target_dir equals to source_dir (which is the same as - # ".git" initially) + # self.GIT_DIR initially) self.check_equal_dirs('source_dir', 'target_dir', deltatar) # then apply diff backup in target_dir @@ -1238,7 +1248,7 @@ class DeltaTarTest(BaseTest): backup_indexes_paths=[index_path, prev_index_path]) # and check that target_dir equals to source_dir_diff (the randomly - # altered ".git" directory) + # altered self.GIT_DIR directory) self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar) # then delete target_dir and apply diff backup from zero and check again @@ -1247,12 +1257,12 @@ class DeltaTarTest(BaseTest): backup_indexes_paths=[index_path, prev_index_path]) # and check that target_dir equals to source_dir_diff (the randomly - # altered ".git" directory) + # altered self.GIT_DIR directory) self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar) def test_restore_from_index_diff_backup3_multivol(self): ''' - Creates a full backup of .git, modifies some random files, creates a + Creates a full backup of self.GIT_DIR, modifies some random files, creates a diff backup, then restores the diff backup with the full backup as a starting point. ''' @@ -1264,8 +1274,8 @@ class DeltaTarTest(BaseTest): logger=self.consoleLogger) shutil.rmtree("source_dir") - shutil.copytree(".git", "source_dir") - shutil.copytree(".git", "source_dir_diff") + shutil.copytree(self.GIT_DIR, "source_dir") + shutil.copytree(self.GIT_DIR, "source_dir_diff") # create first backup deltatar.create_full_backup( @@ -1300,7 +1310,7 @@ class DeltaTarTest(BaseTest): deltatar.restore_backup("target_dir", backup_tar_path=tar_path) # and check that target_dir equals to source_dir (which is the same as - # ".git" initially) + # self.GIT_DIR initially) self.check_equal_dirs('source_dir', 'target_dir', deltatar) # then apply diff backup in target_dir @@ -1310,7 +1320,7 @@ class DeltaTarTest(BaseTest): backup_indexes_paths=[index_path, prev_index_path]) # and check that target_dir equals to source_dir_diff (the randomly - # altered ".git" directory) + # altered self.GIT_DIR directory) self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar) # then delete target_dir and apply diff backup from zero and check again @@ -1319,7 +1329,7 @@ class DeltaTarTest(BaseTest): backup_indexes_paths=[index_path, prev_index_path]) # and check that target_dir equals to source_dir_diff (the randomly - # altered ".git" directory) + # altered self.GIT_DIR directory) self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar) def check_equal_dirs(self, path1, path2, deltatar):