Skip to content

Commit

Permalink
New layout separating src and tests. Fixes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain MARIE committed Oct 6, 2021
1 parent 7d43daa commit 501a67a
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 18 deletions.
8 changes: 5 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ def tests(session: PowerSession, coverage, pkg_specs):
# finally run all tests
if not coverage:
# simple: pytest only
session.run2("python -m pytest --cache-clear -v %s/tests/" % pkg_name)
session.run2("python -m pytest --cache-clear -v tests/")
else:
# coverage + junit html reports + badge generation
session.install_reqs(phase="coverage",
phase_reqs=["coverage", "pytest-html", "genbadge[tests,coverage]"],
versions_dct=pkg_specs)

# --coverage + junit html reports
session.run2("coverage run --source {pkg_name} "
"-m pytest --cache-clear --junitxml={test_xml} --html={test_html} -v {pkg_name}/tests/"
session.run2("coverage run --source src/{pkg_name} "
"-m pytest --cache-clear --junitxml={test_xml} --html={test_html} -v tests/"
"".format(pkg_name=pkg_name, test_xml=Folders.test_xml, test_html=Folders.test_html))
session.run2("coverage report")
session.run2("coverage xml -o {covxml}".format(covxml=Folders.coverage_xml))
Expand All @@ -148,6 +148,8 @@ def flake8(session: PowerSession):
Folders.flake8_reports.mkdir(parents=True, exist_ok=True)
rm_file(Folders.flake8_intermediate_file)

session.cd("src")

# Options are set in `setup.cfg` file
session.run("flake8", pkg_name, "--exit-zero", "--format=html", "--htmldir", str(Folders.flake8_reports),
"--statistics", "--tee", "--output-file", str(Folders.flake8_intermediate_file))
Expand Down
9 changes: 5 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ tests_require =
zip_safe = False
# explicitly setting zip_safe=False to avoid downloading `ply` see https://github.com/smarie/python-getversion/pull/5
# and makes mypy happy see https://mypy.readthedocs.io/en/latest/installed_packages.html
package_dir=
=src
packages = find:
# see [options.packages.find] below
# IMPORTANT: DO NOT set the `include_package_data` flag !! It triggers inclusion of all git-versioned files
# see https://github.com/pypa/setuptools_scm/issues/190#issuecomment-351181286
# include_package_data = True
[options.packages.find]
where=src
exclude =
contrib
docs
Expand Down Expand Up @@ -84,7 +87,7 @@ test = pytest

# pytest default configuration
[tool:pytest]
testpaths = makefun/tests/
testpaths = tests/
addopts =
--verbose
--doctest-modules
Expand Down Expand Up @@ -133,6 +136,4 @@ exclude =
tests
noxfile.py
setup.py
makefun/tests
_version.py
makefun/_version.py
*/_version.py
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
setup(
download_url=DOWNLOAD_URL,
use_scm_version={
"write_to": "makefun/_version.py"
"write_to": "src/makefun/_version.py"
}, # we can't put `use_scm_version` in setup.cfg yet unfortunately
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions makefun/tests/test_advanced.py → tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_empty_name_in_string():
def test_same_than_wraps_basic():
"""Tests that the metadata set by @wraps is correct"""

from makefun.tests.test_doc import test_from_sig_wrapper
from tests.test_doc import test_from_sig_wrapper
from functools import wraps as functools_wraps

def foo_wrapper(*args, **kwargs):
Expand Down Expand Up @@ -133,7 +133,7 @@ def g(self):
def test_type_hint_error():
""" Test for https://github.com/smarie/python-makefun/issues/32 """

from makefun.tests._test_py35 import make_ref_function
from tests._test_py35 import make_ref_function
ref_f = make_ref_function()

@wraps(ref_f)
Expand All @@ -147,7 +147,7 @@ def foo(a):
def test_type_hint_error2():
""" Test for https://github.com/smarie/python-makefun/issues/32 """

from makefun.tests._test_py35 import make_ref_function2
from tests._test_py35 import make_ref_function2
ref_f = make_ref_function2()

@wraps(ref_f)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_native_coroutine():
""" Tests that we can use a native async coroutine as function_handler in `create_function`"""

# define the handler that should be called
from makefun.tests._test_py35 import make_native_coroutine_handler
from tests._test_py35 import make_native_coroutine_handler
my_native_coroutine_handler = make_native_coroutine_handler()

# create the dynamic function
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions makefun/tests/test_so.py → tests/test_so.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def my_func(x):
with capsys.disabled():
print(captured.out)

assert captured.out == """Help on function my_func in module makefun.tests.test_so:
assert captured.out == """Help on function my_func in module tests.test_so:
my_func(x)
my function
Expand Down Expand Up @@ -223,7 +223,7 @@ def funny_function(x, y, z=3):

assert captured.out == """wrapper executes
22
Help on function funny_function in module makefun.tests.test_so:
Help on function funny_function in module tests.test_so:
funny_function(x, y, z=3)
Computes x*y + 2*z
Expand Down Expand Up @@ -255,7 +255,7 @@ def foo(a, b, c=1):
sig_actual_call = "(a, b=10, c=1)"
sig = sig_actual_call if PY2 else "(a, *, b=10, c=1)"

assert captured.out == """Help on function foo in module makefun.tests.test_so:
assert captured.out == """Help on function foo in module tests.test_so:
foo{sig}
<This function is equivalent to 'foo{sig_actual_call}', see original 'foo' doc below.>
Expand Down Expand Up @@ -302,12 +302,12 @@ def test(a, b, x, y):

ref_str = """hello world
1 2
Help on function test in module makefun.tests.test_so:
Help on function test in module tests.test_so:
test{sig}
<This function is equivalent to 'test{sig_actual_call}'.>
Help on function test in module makefun.tests.test_so:
Help on function test in module tests.test_so:
test{sig}
<This function is equivalent to 'test{sig_actual_call}', see original 'test' doc below.>
Expand Down Expand Up @@ -340,7 +340,7 @@ def test(a, b, x, y):
sig_actual_call = "('hello', b='world', x, y)"
sig = "(b='world', x=KW_ONLY_ARG!, y=KW_ONLY_ARG!)" if PY2 else "(*, b='world', x, y)"

ref_str = """Help on function test in module makefun.tests.test_so:
ref_str = """Help on function test in module tests.test_so:
test{sig}
<This function is equivalent to 'test{sig_actual_call}'.>
Expand Down

0 comments on commit 501a67a

Please sign in to comment.