From f59eccb47b0690c4832ccda066907f3c11f1dfa1 Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Fri, 23 Sep 2022 13:31:17 +0200 Subject: [PATCH] [project] Use src layout; Move tests to outside project runtime --- .gitignore | 18 +++------- MANIFEST.in | 2 +- pyproject.toml | 34 +++++++++---------- {exposed => src/exposed}/__init__.py | 0 {exposed => src/exposed}/click.py | 0 {exposed => src/exposed}/config.py | 1 + {exposed => src/exposed}/logging.py | 0 {exposed => src/exposed}/rc.py | 0 {exposed/tests => tests}/__init__.py | 0 {exposed/tests => tests}/conftest.py | 0 {exposed/tests => tests}/data/__init__.py | 0 {exposed/tests => tests}/data/basic_config.py | 0 {exposed/tests => tests}/data/complex.py | 0 {exposed/tests => tests}/data/oldjson.cfg | 0 .../tests => tests}/data/second_config.py | 0 .../tests => tests}/data/test_dump_config.py | 0 .../tests => tests}/data/test_dump_config2.py | 0 .../tests => tests}/data/userdefaults_ex1.cfg | 0 .../tests => tests}/data/verbose_config.py | 0 {exposed/tests => tests}/test_click.py | 8 ++--- {exposed/tests => tests}/test_config.py | 18 +++++----- {exposed/tests => tests}/test_logging.py | 0 {exposed/tests => tests}/test_rc.py | 0 23 files changed, 35 insertions(+), 46 deletions(-) rename {exposed => src/exposed}/__init__.py (100%) rename {exposed => src/exposed}/click.py (100%) rename {exposed => src/exposed}/config.py (99%) rename {exposed => src/exposed}/logging.py (100%) rename {exposed => src/exposed}/rc.py (100%) rename {exposed/tests => tests}/__init__.py (100%) rename {exposed/tests => tests}/conftest.py (100%) rename {exposed/tests => tests}/data/__init__.py (100%) rename {exposed/tests => tests}/data/basic_config.py (100%) rename {exposed/tests => tests}/data/complex.py (100%) rename {exposed/tests => tests}/data/oldjson.cfg (100%) rename {exposed/tests => tests}/data/second_config.py (100%) rename {exposed/tests => tests}/data/test_dump_config.py (100%) rename {exposed/tests => tests}/data/test_dump_config2.py (100%) rename {exposed/tests => tests}/data/userdefaults_ex1.cfg (100%) rename {exposed/tests => tests}/data/verbose_config.py (100%) rename {exposed/tests => tests}/test_click.py (96%) rename {exposed/tests => tests}/test_config.py (90%) rename {exposed/tests => tests}/test_logging.py (100%) rename {exposed/tests => tests}/test_rc.py (100%) diff --git a/.gitignore b/.gitignore index aba7906..13747f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,16 @@ *~ *.swp *.pyc -bin -eggs -parts -.installed.cfg -.mr.developer.cfg *.egg-info -src -develop-eggs -sphinx/ -html/ -doc/api/ -dist .nfs* -.gdb_history -build .coverage -record.txt *.DS_Store .envrc coverage.xml test_results.xml junit-coverage.xml .tox/ +html/ +build/ +doc/api/ +dist/ diff --git a/MANIFEST.in b/MANIFEST.in index 431d9f4..06be307 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include LICENSE README.rst recursive-include doc *.rst *.txt *.py *.ico *.png -recursive-include exposed/tests/data *.cfg +recursive-include tests/data *.py *.cfg diff --git a/pyproject.toml b/pyproject.toml index b1ecc55..7440a9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ [project] name = "exposed" version = "1.0.0b0" +requires-python = ">=3.9" description = "Configuration Support for Python Packages and CLIs" dynamic = ["readme"] license = {text = "BSD 3-Clause License"} @@ -48,24 +49,20 @@ test = [ ] [project.entry-points."exposed.test.config"] -first = "exposed.tests.data.basic_config" -first-a = "exposed.tests.data.basic_config:a" -first-b = "exposed.tests.data.basic_config:b" -second = "exposed.tests.data.second_config" -second-b = "exposed.tests.data.second_config:b" -second-c = "exposed.tests.data.second_config:c" -complex = "exposed.tests.data.complex" -complex-var = "exposed.tests.data.complex:cplx" -verbose-config = "exposed.tests.data.verbose_config" -error-config = "exposed.tests.data.doesnt_exist" +first = "tests.data.basic_config" +first-a = "tests.data.basic_config:a" +first-b = "tests.data.basic_config:b" +second = "tests.data.second_config" +second-b = "tests.data.second_config:b" +second-c = "tests.data.second_config:c" +complex = "tests.data.complex" +complex-var = "tests.data.complex:cplx" +verbose-config = "tests.data.verbose_config" +error-config = "tests.data.doesnt_exist" [tool.setuptools] -zip-safe = false -packages = [ - "exposed", - "exposed.tests", - "exposed.tests.data", - ] +zip-safe = true +package-dir = {"" = "src"} [tool.setuptools.dynamic] version = {file = "version.txt"} @@ -80,11 +77,12 @@ lines_between_types = 1 [tool.black] line-length = 80 -[tool.coverage.report] -omit = ["*/tests/*"] +[tool.coverage.run] +relative_files = true [tool.pytest.ini_options] addopts = [ + "--import-mode=append", "--cov-report=term-missing", "--cov=exposed", ] diff --git a/exposed/__init__.py b/src/exposed/__init__.py similarity index 100% rename from exposed/__init__.py rename to src/exposed/__init__.py diff --git a/exposed/click.py b/src/exposed/click.py similarity index 100% rename from exposed/click.py rename to src/exposed/click.py diff --git a/exposed/config.py b/src/exposed/config.py similarity index 99% rename from exposed/config.py rename to src/exposed/config.py index d572974..1734000 100644 --- a/exposed/config.py +++ b/src/exposed/config.py @@ -380,4 +380,5 @@ def resource_keys( and (not k.name.startswith(strip)) ) ] + ret_list = list(dict.fromkeys(ret_list)) # order-preserving uniq return sorted(ret_list) diff --git a/exposed/logging.py b/src/exposed/logging.py similarity index 100% rename from exposed/logging.py rename to src/exposed/logging.py diff --git a/exposed/rc.py b/src/exposed/rc.py similarity index 100% rename from exposed/rc.py rename to src/exposed/rc.py diff --git a/exposed/tests/__init__.py b/tests/__init__.py similarity index 100% rename from exposed/tests/__init__.py rename to tests/__init__.py diff --git a/exposed/tests/conftest.py b/tests/conftest.py similarity index 100% rename from exposed/tests/conftest.py rename to tests/conftest.py diff --git a/exposed/tests/data/__init__.py b/tests/data/__init__.py similarity index 100% rename from exposed/tests/data/__init__.py rename to tests/data/__init__.py diff --git a/exposed/tests/data/basic_config.py b/tests/data/basic_config.py similarity index 100% rename from exposed/tests/data/basic_config.py rename to tests/data/basic_config.py diff --git a/exposed/tests/data/complex.py b/tests/data/complex.py similarity index 100% rename from exposed/tests/data/complex.py rename to tests/data/complex.py diff --git a/exposed/tests/data/oldjson.cfg b/tests/data/oldjson.cfg similarity index 100% rename from exposed/tests/data/oldjson.cfg rename to tests/data/oldjson.cfg diff --git a/exposed/tests/data/second_config.py b/tests/data/second_config.py similarity index 100% rename from exposed/tests/data/second_config.py rename to tests/data/second_config.py diff --git a/exposed/tests/data/test_dump_config.py b/tests/data/test_dump_config.py similarity index 100% rename from exposed/tests/data/test_dump_config.py rename to tests/data/test_dump_config.py diff --git a/exposed/tests/data/test_dump_config2.py b/tests/data/test_dump_config2.py similarity index 100% rename from exposed/tests/data/test_dump_config2.py rename to tests/data/test_dump_config2.py diff --git a/exposed/tests/data/userdefaults_ex1.cfg b/tests/data/userdefaults_ex1.cfg similarity index 100% rename from exposed/tests/data/userdefaults_ex1.cfg rename to tests/data/userdefaults_ex1.cfg diff --git a/exposed/tests/data/verbose_config.py b/tests/data/verbose_config.py similarity index 100% rename from exposed/tests/data/verbose_config.py rename to tests/data/verbose_config.py diff --git a/exposed/tests/test_click.py b/tests/test_click.py similarity index 96% rename from exposed/tests/test_click.py rename to tests/test_click.py index 985af38..e43d219 100644 --- a/exposed/tests/test_click.py +++ b/tests/test_click.py @@ -266,7 +266,7 @@ def test_resource_option(): assert a == 1 runner = CliRunner() - result = runner.invoke(cli1, ["-a", "exposed.tests.data.basic_config"]) + result = runner.invoke(cli1, ["-a", "tests.data.basic_config"]) assert result.exit_code == 0 # test usage without ConfigCommand and without entry_point_group @@ -288,12 +288,12 @@ def test_resource_option(): "-a", "--a", cls=ResourceOption, - string_exceptions=("exposed.tests.data.basic_config"), + string_exceptions=("tests.data.basic_config"), entry_point_group="exposed.test.config", ) def cli3(a): - assert a == "exposed.tests.data.basic_config" + assert a == "tests.data.basic_config" runner = CliRunner() - result = runner.invoke(cli3, ["-a", "exposed.tests.data.basic_config"]) + result = runner.invoke(cli3, ["-a", "tests.data.basic_config"]) assert result.exit_code == 0 diff --git a/exposed/tests/test_config.py b/tests/test_config.py similarity index 90% rename from exposed/tests/test_config.py rename to tests/test_config.py index 44b7412..5a0a77b 100644 --- a/exposed/tests/test_config.py +++ b/tests/test_config.py @@ -48,9 +48,9 @@ def test_config_with_module(): c = load( [ - "exposed.tests.data.basic_config", - "exposed.tests.data.second_config", - "exposed.tests.data.complex", + "tests.data.basic_config", + "tests.data.second_config", + "tests.data.complex", ] ) assert hasattr(c, "a") and c.a == 1 @@ -79,7 +79,7 @@ def test_config_with_mixture(datadir): c = load( [ datadir / "basic_config.py", - "exposed.tests.data.second_config", + "tests.data.second_config", "complex", ], entry_point_group="exposed.test.config", @@ -97,14 +97,14 @@ def test_config_not_found(datadir): def test_config_load_attribute(): - a = load(["exposed.tests.data.basic_config"], attribute_name="a") + a = load(["tests.data.basic_config"], attribute_name="a") assert a == 1 def test_config_load_no_attribute(): with pytest.raises(ImportError): - _ = load(["exposed.tests.data.basic_config"], attribute_name="wrong") + _ = load(["tests.data.basic_config"], attribute_name="wrong") @pytest.fixture @@ -132,7 +132,7 @@ def test_config_click_config_list(cli_messages): runner = CliRunner() result = runner.invoke(cli, ["list"]) assert result.exit_code == 0 - assert result.output.startswith("module: exposed.tests.data") + assert result.output.startswith("module: tests.data") assert "(cannot be loaded; add another -v for details)" not in result.output @@ -142,7 +142,7 @@ def test_config_click_config_list_v(cli_messages): runner = CliRunner() result = runner.invoke(cli, ["list", "-v"]) assert result.exit_code == 0 - assert result.output.startswith("module: exposed.tests.data") + assert result.output.startswith("module: tests.data") assert "(cannot be loaded; add another -v for details)" in result.output assert "[module] Example configuration module" in result.output @@ -153,7 +153,7 @@ def test_config_click_config_list_vv(cli_messages): runner = CliRunner() result = runner.invoke(cli, ["list", "-vv"]) assert result.exit_code == 0 - assert result.output.startswith("module: exposed.tests.data") + assert result.output.startswith("module: tests.data") assert "(cannot be loaded; add another -v for details)" in result.output assert "[module] Example configuration module" in result.output assert "NameError" in messages.getvalue() diff --git a/exposed/tests/test_logging.py b/tests/test_logging.py similarity index 100% rename from exposed/tests/test_logging.py rename to tests/test_logging.py diff --git a/exposed/tests/test_rc.py b/tests/test_rc.py similarity index 100% rename from exposed/tests/test_rc.py rename to tests/test_rc.py -- GitLab