Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Cleaner test config initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Feb 19, 2023
1 parent 1328ff6 commit e800659
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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}")
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/data/test_config.toml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 9 additions & 6 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pytransifex.api import Transifex
from pytransifex.interfaces import Tx
from tests import test_config


class TestNewApi(unittest.TestCase):
Expand All @@ -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}"
Expand Down
19 changes: 12 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e800659

Please sign in to comment.