From e800659b64fb0dfebe35410e280ba1f2b9076c21 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Sun, 19 Feb 2023 14:09:29 +0100 Subject: [PATCH] Cleaner test config initialization. --- tests/__init__.py | 11 +++++++++++ .../resources}/test_resource_fr.po | 0 tests/data/test_config.toml | 5 +++++ tests/test_api.py | 15 +++++++++------ tests/test_cli.py | 19 ++++++++++++------- 5 files changed, 37 insertions(+), 13 deletions(-) rename tests/{input => data/resources}/test_resource_fr.po (100%) create mode 100644 tests/data/test_config.toml diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..c967a96 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,11 @@ +import logging +from pathlib import Path + +import toml + +logging.basicConfig(level=logging.INFO) + +p = Path.cwd().joinpath("./tests/data/test_config.toml") +test_config = toml.load(p) + +logging.info(f"Running tests with this test_config: {test_config}") diff --git a/tests/input/test_resource_fr.po b/tests/data/resources/test_resource_fr.po similarity index 100% rename from tests/input/test_resource_fr.po rename to tests/data/resources/test_resource_fr.po diff --git a/tests/data/test_config.toml b/tests/data/test_config.toml new file mode 100644 index 0000000..56f6796 --- /dev/null +++ b/tests/data/test_config.toml @@ -0,0 +1,5 @@ +organization_slug = "test_pytransifex" +project_slug = "test_project_pytransifex" +project_name = "Python Transifex API testing" +resource_slug = "test_resource_fr" +resource_name = "Test Resource FR" diff --git a/tests/test_api.py b/tests/test_api.py index a80bd32..5bb82ee 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,6 +4,7 @@ from pytransifex.api import Transifex from pytransifex.interfaces import Tx +from tests import test_config class TestNewApi(unittest.TestCase): @@ -12,14 +13,16 @@ def setUpClass(cls): client = Transifex(defer_login=True) assert client - cls.tx = client - cls.project_slug = "test_project_pytransifex" - cls.project_name = "Test Project PyTransifex" - cls.resource_slug = "test_resource_fr" - cls.resource_name = "Test Resource FR" - cls.path_to_file = Path.cwd().joinpath("tests", "input", "test_resource_fr.po") + cls.path_to_input_dir = Path.cwd().joinpath("tests", "data", "resources") + cls.path_to_file = cls.path_to_input_dir.joinpath("test_resource_fr.po") cls.output_dir = Path.cwd().joinpath("tests", "output") + cls.tx = client + cls.project_slug = test_config["project_slug"] + cls.project_name = test_config["project_name"] + cls.resource_slug = test_config["resource_slug"] + cls.resource_name = test_config["resource_name"] + if missing := next(filter(lambda p: not p.exists(), [cls.path_to_file]), None): raise ValueError( f"Unable to complete test with broken tests inputs. Found missing: {missing}" diff --git a/tests/test_cli.py b/tests/test_cli.py index 3b8af21..5e40646 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,20 +6,25 @@ from pytransifex.api import Transifex from pytransifex.cli import cli +from tests import test_config class TestCli(unittest.TestCase): @classmethod def setUpClass(cls): - cls.tx = Transifex(defer_login=True) - cls.project_slug = "test_project_pytransifex" - cls.project_name = "Test Project PyTransifex" - cls.resource_slug = "test_resource_fr" - cls.resource_name = "Test Resource FR" - cls.path_to_input_dir = Path.cwd().joinpath("tests", "input") + client = Transifex(defer_login=True) + assert client + + cls.path_to_input_dir = Path.cwd().joinpath("tests", "data", "resources") cls.path_to_file = cls.path_to_input_dir.joinpath("test_resource_fr.po") cls.output_dir = Path.cwd().joinpath("tests", "output") + cls.tx = client + cls.project_slug = test_config["project_slug"] + cls.project_name = test_config["project_name"] + cls.resource_slug = test_config["resource_slug"] + cls.resource_name = test_config["resource_name"] + if missing := next( filter(lambda p: not p.exists(), [cls.path_to_file, cls.path_to_input_dir]), None, @@ -53,7 +58,7 @@ def test1_init(self): assert passed def test2_push(self): - result = self.runner.invoke(cli, ["push", "-in", str(self.path_to_input_dir)]) + result = self.runner.invoke(cli, ["push", "-in", str(self.path_to_file)]) passed = result.exit_code == 0 print(result.output) assert passed