1
0
Fork 0

Merging upstream version 0.16.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 06:05:35 +01:00
parent 40df5416c1
commit 72676ec535
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
56 changed files with 615 additions and 161 deletions

View file

@ -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():