From 8e6869d8e36ac33939e8ba36f346b45a14cc0e6f Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 11 Dec 2023 17:36:18 +0100 Subject: [PATCH] move tests into cmdeploy --- .github/workflows/ci.yaml | 2 +- cmdeploy/pyproject.toml | 5 +++-- cmdeploy/src/cmdeploy/cmdeploy.py | 15 ++++++--------- cmdeploy/src/cmdeploy/tests/__init__.py | 0 cmdeploy/src/cmdeploy/tests/online/__init__.py | 0 .../src/cmdeploy/tests}/online/benchmark.py | 0 .../src/cmdeploy/tests}/online/test_0_login.py | 0 .../src/cmdeploy/tests}/online/test_0_qr.py | 0 .../src/cmdeploy/tests}/online/test_1_basic.py | 0 .../cmdeploy/tests}/online/test_2_deltachat.py | 0 .../src/cmdeploy/tests/plugin.py | 2 +- {tests => cmdeploy/src/cmdeploy/tests}/pytest.ini | 0 .../src/cmdeploy/tests}/test_cmdeploy.py | 0 .../src/cmdeploy/tests}/test_helpers.py | 0 14 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 cmdeploy/src/cmdeploy/tests/__init__.py create mode 100644 cmdeploy/src/cmdeploy/tests/online/__init__.py rename {tests => cmdeploy/src/cmdeploy/tests}/online/benchmark.py (100%) rename {tests => cmdeploy/src/cmdeploy/tests}/online/test_0_login.py (100%) rename {tests => cmdeploy/src/cmdeploy/tests}/online/test_0_qr.py (100%) rename {tests => cmdeploy/src/cmdeploy/tests}/online/test_1_basic.py (100%) rename {tests => cmdeploy/src/cmdeploy/tests}/online/test_2_deltachat.py (100%) rename tests/conftest.py => cmdeploy/src/cmdeploy/tests/plugin.py (99%) rename {tests => cmdeploy/src/cmdeploy/tests}/pytest.ini (100%) rename {tests => cmdeploy/src/cmdeploy/tests}/test_cmdeploy.py (100%) rename {tests => cmdeploy/src/cmdeploy/tests}/test_helpers.py (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e2f523b5..921b2f2f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,7 +31,7 @@ jobs: run: cmdeploy fmt -v - name: run deploy-chatmail offline tests - run: pytest tests + run: pytest --pyargs cmdeploy - name: initialize with chatmail domain run: cmdeploy init chat.example.org diff --git a/cmdeploy/pyproject.toml b/cmdeploy/pyproject.toml index 69d34638..060865cc 100644 --- a/cmdeploy/pyproject.toml +++ b/cmdeploy/pyproject.toml @@ -3,8 +3,8 @@ requires = ["setuptools>=68"] build-backend = "setuptools.build_meta" [project] -name = "deploy-chatmail" -version = "0.1" +name = "cmdeploy" +version = "0.2" dependencies = [ "pyinfra", "pillow", @@ -26,6 +26,7 @@ cmdeploy = "cmdeploy.cmdeploy:main" [project.entry-points.pytest11] "chatmaild.testplugin" = "chatmaild.tests.plugin" +"cmdeploy.testplugin" = "cmdeploy.tests.plugin" [tool.pytest.ini_options] addopts = "-v -ra --strict-markers" diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index c862d90d..3fb8770c 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -122,7 +122,7 @@ def test_cmd(args, out): pytest_path = shutil.which("pytest") ret = out.run_ret( - [pytest_path, "tests/", "-n4", "-rs", "-x", "-vrx", "--durations=5"] + [pytest_path, "cmdeploy/src/", "-n4", "-rs", "-x", "-vrx", "--durations=5"] ) return ret @@ -147,11 +147,7 @@ def fmt_cmd_options(parser): def fmt_cmd(args, out): """Run formattting fixes (fuff and black) on all chatmail source code.""" - chatmaild = importlib.resources.files("chatmaild") - cmdeploy = importlib.resources.files("cmdeploy") - tests = cmdeploy.joinpath("../../../tests") - sources = list(str(x) for x in [chatmaild, cmdeploy, tests]) - + sources = [str(importlib.resources.files(x)) for x in ("chatmaild", "cmdeploy")] black_args = [shutil.which("black")] ruff_args = [shutil.which("ruff")] @@ -174,9 +170,10 @@ def fmt_cmd(args, out): def bench_cmd(args, out): """Run benchmarks against an online chatmail instance.""" - pytest_path = shutil.which("pytest") - benchmark = "tests/online/benchmark.py" - subprocess.check_call([pytest_path, benchmark, "-vrx"]) + args = ["pytest", "--pyargs", "cmdeploy.tests.online.benchmark", "-vrx"] + cmdstring = " ".join(args) + out.green(f"[$ {cmdstring}]") + subprocess.check_call(args) def webdev_cmd(args, out): diff --git a/cmdeploy/src/cmdeploy/tests/__init__.py b/cmdeploy/src/cmdeploy/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cmdeploy/src/cmdeploy/tests/online/__init__.py b/cmdeploy/src/cmdeploy/tests/online/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/online/benchmark.py b/cmdeploy/src/cmdeploy/tests/online/benchmark.py similarity index 100% rename from tests/online/benchmark.py rename to cmdeploy/src/cmdeploy/tests/online/benchmark.py diff --git a/tests/online/test_0_login.py b/cmdeploy/src/cmdeploy/tests/online/test_0_login.py similarity index 100% rename from tests/online/test_0_login.py rename to cmdeploy/src/cmdeploy/tests/online/test_0_login.py diff --git a/tests/online/test_0_qr.py b/cmdeploy/src/cmdeploy/tests/online/test_0_qr.py similarity index 100% rename from tests/online/test_0_qr.py rename to cmdeploy/src/cmdeploy/tests/online/test_0_qr.py diff --git a/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py similarity index 100% rename from tests/online/test_1_basic.py rename to cmdeploy/src/cmdeploy/tests/online/test_1_basic.py diff --git a/tests/online/test_2_deltachat.py b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py similarity index 100% rename from tests/online/test_2_deltachat.py rename to cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py diff --git a/tests/conftest.py b/cmdeploy/src/cmdeploy/tests/plugin.py similarity index 99% rename from tests/conftest.py rename to cmdeploy/src/cmdeploy/tests/plugin.py index 2e96facd..b0f4bc20 100644 --- a/tests/conftest.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -38,7 +38,7 @@ def pytest_runtest_setup(item): @pytest.fixture def chatmail_config(pytestconfig): - current = basedir = Path() + current = basedir = Path().resolve() while 1: path = current.joinpath("chatmail.ini").resolve() if path.exists(): diff --git a/tests/pytest.ini b/cmdeploy/src/cmdeploy/tests/pytest.ini similarity index 100% rename from tests/pytest.ini rename to cmdeploy/src/cmdeploy/tests/pytest.ini diff --git a/tests/test_cmdeploy.py b/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py similarity index 100% rename from tests/test_cmdeploy.py rename to cmdeploy/src/cmdeploy/tests/test_cmdeploy.py diff --git a/tests/test_helpers.py b/cmdeploy/src/cmdeploy/tests/test_helpers.py similarity index 100% rename from tests/test_helpers.py rename to cmdeploy/src/cmdeploy/tests/test_helpers.py