From 354ae119c6696b3cf31ca15e2fe33fa7251f55e3 Mon Sep 17 00:00:00 2001 From: nvbn Date: Wed, 26 Aug 2015 12:12:52 +0300 Subject: [PATCH] Don't duplicate project root in tests --- tests/functional/utils.py | 6 +++--- tests/test_readme.py | 7 +++---- tests/utils.py | 4 ++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/functional/utils.py b/tests/functional/utils.py index 2a7c1627..6efe05e6 100644 --- a/tests/functional/utils.py +++ b/tests/functional/utils.py @@ -1,3 +1,4 @@ +import pytest import os import subprocess import shutil @@ -5,9 +6,8 @@ from tempfile import mkdtemp from pathlib import Path import sys import pexpect -import pytest +from tests.utils import root -root = str(Path(__file__).parent.parent.parent.resolve()) bare = os.environ.get('BARE') enabled = os.environ.get('FUNCTIONAL') @@ -18,7 +18,7 @@ def build_container(tag, dockerfile): with Path(tmpdir).joinpath('Dockerfile').open('w') as file: file.write(dockerfile) if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir], - cwd=root) != 0: + cwd=str(root)) != 0: raise Exception("Can't build a container") finally: shutil.rmtree(tmpdir) diff --git a/tests/test_readme.py b/tests/test_readme.py index 715f3bc7..5a5ccab4 100644 --- a/tests/test_readme.py +++ b/tests/test_readme.py @@ -1,12 +1,11 @@ -from pathlib import Path +from tests.utils import root def test_readme(): - project_root = Path(__file__).parent.parent - with project_root.joinpath('README.md').open() as f: + with root.joinpath('README.md').open() as f: readme = f.read() - bundled = project_root \ + bundled = root \ .joinpath('thefuck') \ .joinpath('rules') \ .glob('*.py') diff --git a/tests/utils.py b/tests/utils.py index 23a55b84..70a409ea 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,3 +1,4 @@ +from pathlib import Path from thefuck import types from thefuck.conf import DEFAULT_PRIORITY @@ -19,3 +20,6 @@ def Rule(name='', match=lambda *_: True, def CorrectedCommand(script='', side_effect=None, priority=DEFAULT_PRIORITY): return types.CorrectedCommand(script, side_effect, priority) + + +root = Path(__file__).parent.parent.resolve()