diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-10-13 05:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-10-13 05:34:54 +0000 |
commit | b8d423e7d13686d6627571d6c4adf12661d82147 (patch) | |
tree | 11d64ff26fb53c3c01ee35d062ca0c51fb883550 /qa/base.py | |
parent | Adding upstream version 0.15.1. (diff) | |
download | gitlint-upstream/0.16.0.tar.xz gitlint-upstream/0.16.0.zip |
Adding upstream version 0.16.0.upstream/0.16.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/base.py')
-rw-r--r-- | qa/base.py | 40 |
1 files changed, 18 insertions, 22 deletions
@@ -29,25 +29,20 @@ class BaseTestCase(TestCase): GITLINT_USE_SH_LIB = os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]") GIT_CONTEXT_ERROR_CODE = 254 - - @classmethod - def setUpClass(cls): - """ Sets up the integration tests by creating a new temporary git repository """ - cls.tmp_git_repos = [] - cls.tmp_git_repo = cls.create_tmp_git_repo() - - @classmethod - def tearDownClass(cls): - """ Cleans up the temporary git repositories """ - for repo in cls.tmp_git_repos: - shutil.rmtree(repo) + GITLINT_USAGE_ERROR = 253 def setUp(self): + """ Sets up the integration tests by creating a new temporary git repository """ self.tmpfiles = [] + self.tmp_git_repos = [] + self.tmp_git_repo = self.create_tmp_git_repo() def tearDown(self): + # Clean up temporary files and repos for tmpfile in self.tmpfiles: os.remove(tmpfile) + for repo in self.tmp_git_repos: + shutil.rmtree(repo) def assertEqualStdout(self, output, expected): # pylint: disable=invalid-name self.assertIsInstance(output, RunningCommand) @@ -55,16 +50,15 @@ class BaseTestCase(TestCase): output = output.replace('\r', '') self.assertMultiLineEqual(output, expected) - @classmethod - def generate_temp_path(cls): + @staticmethod + def generate_temp_path(): timestamp = datetime.now().strftime("%Y%m%d-%H%M%S-%f") return os.path.realpath(f"/tmp/gitlint-test-{timestamp}") - @classmethod - def create_tmp_git_repo(cls): + def create_tmp_git_repo(self): """ Creates a temporary git repository and returns its directory path """ - tmp_git_repo = cls.generate_temp_path() - cls.tmp_git_repos.append(tmp_git_repo) + tmp_git_repo = self.generate_temp_path() + self.tmp_git_repos.append(tmp_git_repo) git("init", tmp_git_repo) # configuring name and email is required in every git repot @@ -86,6 +80,7 @@ class BaseTestCase(TestCase): def create_file(parent_dir): """ Creates a file inside a passed directory. Returns filename.""" test_filename = "test-fïle-" + str(uuid4()) + # pylint: disable=consider-using-with io.open(os.path.join(parent_dir, test_filename), 'a', encoding=DEFAULT_ENCODING).close() return test_filename @@ -158,11 +153,12 @@ class BaseTestCase(TestCase): specified by variable_dict. """ expected_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "expected") expected_path = os.path.join(expected_dir, filename) - expected = io.open(expected_path, encoding=DEFAULT_ENCODING).read() + with io.open(expected_path, encoding=DEFAULT_ENCODING) as file: + expected = file.read() - if variable_dict: - expected = expected.format(**variable_dict) - return expected + if variable_dict: + expected = expected.format(**variable_dict) + return expected @staticmethod def get_system_info_dict(): |