summaryrefslogtreecommitdiffstats
path: root/qa/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'qa/base.py')
-rw-r--r--qa/base.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/qa/base.py b/qa/base.py
index f9e520a..acb921d 100644
--- a/qa/base.py
+++ b/qa/base.py
@@ -10,18 +10,13 @@ import sys
import tempfile
from datetime import datetime
from uuid import uuid4
+from unittest import TestCase
import arrow
-try:
- # python 2.x
- from unittest2 import TestCase
-except ImportError:
- # python 3.x
- from unittest import TestCase
from qa.shell import git, gitlint, RunningCommand
-from qa.utils import DEFAULT_ENCODING, ustr
+from qa.utils import DEFAULT_ENCODING
class BaseTestCase(TestCase):
@@ -56,13 +51,14 @@ class BaseTestCase(TestCase):
def assertEqualStdout(self, output, expected): # pylint: disable=invalid-name
self.assertIsInstance(output, RunningCommand)
- output = ustr(output.stdout)
+ output = output.stdout.decode(DEFAULT_ENCODING)
output = output.replace('\r', '')
self.assertMultiLineEqual(output, expected)
@classmethod
def generate_temp_path(cls):
- return os.path.realpath("/tmp/gitlint-test-{0}".format(datetime.now().strftime("%Y%m%d-%H%M%S-%f")))
+ 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):
@@ -89,7 +85,7 @@ class BaseTestCase(TestCase):
@staticmethod
def create_file(parent_dir):
""" Creates a file inside a passed directory. Returns filename."""
- test_filename = u"test-fïle-" + str(uuid4())
+ test_filename = "test-fïle-" + str(uuid4())
io.open(os.path.join(parent_dir, test_filename), 'a', encoding=DEFAULT_ENCODING).close()
return test_filename
@@ -171,8 +167,8 @@ class BaseTestCase(TestCase):
@staticmethod
def get_system_info_dict():
""" Returns a dict with items related to system values logged by `gitlint --debug` """
- expected_gitlint_version = gitlint("--version").replace("gitlint, version ", "").replace("\n", "")
- expected_git_version = git("--version").replace("\n", "")
+ expected_gitlint_version = gitlint("--version").replace("gitlint, version ", "").strip()
+ expected_git_version = git("--version").strip()
return {'platform': platform.platform(), 'python_version': sys.version,
'git_version': expected_git_version, 'gitlint_version': expected_gitlint_version,
'GITLINT_USE_SH_LIB': BaseTestCase.GITLINT_USE_SH_LIB, 'DEFAULT_ENCODING': DEFAULT_ENCODING}