diff options
author | Eric Lin <anselor@gmail.com> | 2020-07-07 15:57:02 -0400 |
---|---|---|
committer | anselor <anselor@gmail.com> | 2020-07-11 17:30:40 -0400 |
commit | 601a8e271020ca1b0918deabf70ad0778ded7d4a (patch) | |
tree | 48f2134a71a2478c00eb9df33e69b30c0ae39002 /plugins | |
parent | 28e43bf24f8a5bc0b2e896938e76e17524d12ed3 (diff) | |
download | cmd2-git-601a8e271020ca1b0918deabf70ad0778ded7d4a.tar.gz |
external test plugin tests and coverage should now run
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ext_test/CHANGELOG.md (renamed from plugins/cmd2_ext_test/CHANGELOG.md) | 0 | ||||
-rw-r--r-- | plugins/ext_test/LICENSE (renamed from plugins/cmd2_ext_test/LICENSE) | 0 | ||||
-rw-r--r-- | plugins/ext_test/README.md (renamed from plugins/cmd2_ext_test/README.md) | 0 | ||||
-rw-r--r-- | plugins/ext_test/build-pyenvs.sh (renamed from plugins/cmd2_ext_test/build-pyenvs.sh) | 0 | ||||
-rw-r--r-- | plugins/ext_test/cmd2_ext_test/__init__.py (renamed from plugins/cmd2_ext_test/cmd2_ext_test/__init__.py) | 5 | ||||
-rw-r--r-- | plugins/ext_test/cmd2_ext_test/cmd2_ext_test.py (renamed from plugins/cmd2_ext_test/cmd2_ext_test/cmd2_ext_test.py) | 0 | ||||
-rw-r--r-- | plugins/ext_test/cmd2_ext_test/pylintrc (renamed from plugins/cmd2_ext_test/cmd2_ext_test/pylintrc) | 0 | ||||
-rw-r--r-- | plugins/ext_test/examples/example.py (renamed from plugins/cmd2_ext_test/examples/example.py) | 0 | ||||
-rw-r--r-- | plugins/ext_test/setup.py (renamed from plugins/cmd2_ext_test/setup.py) | 15 | ||||
-rw-r--r-- | plugins/ext_test/tasks.py (renamed from plugins/cmd2_ext_test/tasks.py) | 122 | ||||
-rw-r--r-- | plugins/ext_test/tests/__init__.py (renamed from plugins/cmd2_ext_test/tests/__init__.py) | 0 | ||||
-rw-r--r-- | plugins/ext_test/tests/pylintrc (renamed from plugins/cmd2_ext_test/tests/pylintrc) | 0 | ||||
-rw-r--r-- | plugins/ext_test/tests/test_ext_test.py (renamed from plugins/cmd2_ext_test/tests/test_ext_test.py) | 0 | ||||
-rw-r--r-- | plugins/tasks.py | 86 |
14 files changed, 111 insertions, 117 deletions
diff --git a/plugins/cmd2_ext_test/CHANGELOG.md b/plugins/ext_test/CHANGELOG.md index c6eae3f7..c6eae3f7 100644 --- a/plugins/cmd2_ext_test/CHANGELOG.md +++ b/plugins/ext_test/CHANGELOG.md diff --git a/plugins/cmd2_ext_test/LICENSE b/plugins/ext_test/LICENSE index b1784d5d..b1784d5d 100644 --- a/plugins/cmd2_ext_test/LICENSE +++ b/plugins/ext_test/LICENSE diff --git a/plugins/cmd2_ext_test/README.md b/plugins/ext_test/README.md index 6f8a2b8c..6f8a2b8c 100644 --- a/plugins/cmd2_ext_test/README.md +++ b/plugins/ext_test/README.md diff --git a/plugins/cmd2_ext_test/build-pyenvs.sh b/plugins/ext_test/build-pyenvs.sh index 39c28aa1..39c28aa1 100644 --- a/plugins/cmd2_ext_test/build-pyenvs.sh +++ b/plugins/ext_test/build-pyenvs.sh diff --git a/plugins/cmd2_ext_test/cmd2_ext_test/__init__.py b/plugins/ext_test/cmd2_ext_test/__init__.py index da3fae9a..50a3f5a5 100644 --- a/plugins/cmd2_ext_test/cmd2_ext_test/__init__.py +++ b/plugins/ext_test/cmd2_ext_test/__init__.py @@ -9,6 +9,11 @@ from pkg_resources import get_distribution, DistributionNotFound from .cmd2_ext_test import ExternalTestMixin +__all__ = [ + 'ExternalTestMixin' +] + + try: __version__ = get_distribution(__name__).version except DistributionNotFound: diff --git a/plugins/cmd2_ext_test/cmd2_ext_test/cmd2_ext_test.py b/plugins/ext_test/cmd2_ext_test/cmd2_ext_test.py index 02fd29b1..02fd29b1 100644 --- a/plugins/cmd2_ext_test/cmd2_ext_test/cmd2_ext_test.py +++ b/plugins/ext_test/cmd2_ext_test/cmd2_ext_test.py diff --git a/plugins/cmd2_ext_test/cmd2_ext_test/pylintrc b/plugins/ext_test/cmd2_ext_test/pylintrc index 2f6d3de2..2f6d3de2 100644 --- a/plugins/cmd2_ext_test/cmd2_ext_test/pylintrc +++ b/plugins/ext_test/cmd2_ext_test/pylintrc diff --git a/plugins/cmd2_ext_test/examples/example.py b/plugins/ext_test/examples/example.py index 649f8627..649f8627 100644 --- a/plugins/cmd2_ext_test/examples/example.py +++ b/plugins/ext_test/examples/example.py diff --git a/plugins/cmd2_ext_test/setup.py b/plugins/ext_test/setup.py index cb55c16a..41d97316 100644 --- a/plugins/cmd2_ext_test/setup.py +++ b/plugins/ext_test/setup.py @@ -12,7 +12,12 @@ with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: setuptools.setup( name='cmd2-ext-test', - use_scm_version=True, + version='0.2.0', + # use_scm_version={ + # 'root': '../..', + # 'relative_to': __file__, + # 'git_describe_command': 'git describe --dirty --tags --long --match plugin-ext-test*' + # }, description='External test plugin for cmd2. Allows for external invocation of commands as if from a cmd2 pyscript', long_description=long_description, @@ -28,7 +33,7 @@ setuptools.setup( python_requires='>=3.4', install_requires=['cmd2 >= 0.9.4, <=2'], - setup_requires=['setuptools_scm'], + setup_requires=['setuptools_scm >= 3.0'], classifiers=[ 'Development Status :: 4 - Beta', @@ -46,6 +51,12 @@ setuptools.setup( # dependencies for development and testing # $ pip install -e .[dev] extras_require={ + 'test': [ + 'codecov', + 'coverage', + 'pytest', + 'pytest-cov', + ], 'dev': ['setuptools_scm', 'pytest', 'codecov', 'pytest-cov', 'pylint', 'invoke', 'wheel', 'twine'] }, diff --git a/plugins/cmd2_ext_test/tasks.py b/plugins/ext_test/tasks.py index 6bb8d307..2f5955ae 100644 --- a/plugins/cmd2_ext_test/tasks.py +++ b/plugins/ext_test/tasks.py @@ -10,9 +10,7 @@ Make sure you satisfy the following Python module requirements if you are trying """ import os import pathlib -import re import shutil -import sys import invoke @@ -22,7 +20,7 @@ TASK_ROOT_STR = str(TASK_ROOT) # shared function def rmrf(items, verbose=True): - "Silently remove a list of directories or files" + """Silently remove a list of directories or files""" if isinstance(items, str): items = [items] @@ -47,44 +45,58 @@ namespace.add_collection(namespace_clean, 'clean') # pytest, tox, pylint, and codecov # ##### + + @invoke.task -def pytest(context): - "Run tests and code coverage using pytest" - with context.cd(TASK_ROOT_STR): - context.run("pytest --cov=cmd2_ext_test --cov-report=term --cov-report=html", pty=True) +def pytest(context, junit=False, pty=True, append_cov=False): + """Run tests and code coverage using pytest""" + ROOT_PATH = TASK_ROOT.parent.parent + + with context.cd(str(ROOT_PATH)): + command_str = 'pytest --cov=cmd2_ext_test --cov-report=term --cov-report=html' + if append_cov: + command_str += ' --cov-append' + if junit: + command_str += ' --junitxml=junit/test-results.xml' + command_str += ' ' + str((TASK_ROOT/'tests').relative_to(ROOT_PATH)) + context.run(command_str, pty=pty) + + namespace.add_task(pytest) -@invoke.task -def pytest_junit(context): - "Run tests and code coverage using pytest" - with context.cd(TASK_ROOT_STR): - context.run("pytest --cov --junitxml=junit/test-results.xml", pty=True) -namespace.add_task(pytest_junit) @invoke.task def pytest_clean(context): - "Remove pytest cache and code coverage files and directories" - #pylint: disable=unused-argument + """Remove pytest cache and code coverage files and directories""" + # pylint: disable=unused-argument with context.cd(TASK_ROOT_STR): dirs = ['.pytest_cache', '.cache', 'htmlcov', '.coverage'] rmrf(dirs) + + namespace_clean.add_task(pytest_clean, 'pytest') + @invoke.task def mypy(context): - "Run mypy optional static type checker" + """Run mypy optional static type checker""" with context.cd(TASK_ROOT_STR): - context.run("mypy main.py") + context.run("mypy cmd2_ext_test") namespace.add_task(mypy) + + namespace.add_task(mypy) + @invoke.task def mypy_clean(context): - "Remove mypy cache directory" - #pylint: disable=unused-argument + """Remove mypy cache directory""" + # pylint: disable=unused-argument with context.cd(TASK_ROOT_STR): dirs = ['.mypy_cache', 'dmypy.json', 'dmypy.sock'] rmrf(dirs) + + namespace_clean.add_task(mypy_clean, 'mypy') @@ -103,95 +115,89 @@ namespace_clean.add_task(mypy_clean, 'mypy') BUILDDIR = 'build' DISTDIR = 'dist' + @invoke.task def build_clean(context): - "Remove the build directory" - #pylint: disable=unused-argument + """Remove the build directory""" + # pylint: disable=unused-argument with context.cd(TASK_ROOT_STR): rmrf(BUILDDIR) + namespace_clean.add_task(build_clean, 'build') + @invoke.task def dist_clean(context): - "Remove the dist directory" - #pylint: disable=unused-argument + """Remove the dist directory""" + # pylint: disable=unused-argument with context.cd(TASK_ROOT_STR): rmrf(DISTDIR) -namespace_clean.add_task(dist_clean, 'dist') -@invoke.task -def eggs_clean(context): - "Remove egg directories" - #pylint: disable=unused-argument - with context.cd(TASK_ROOT_STR): - dirs = set() - dirs.add('.eggs') - for name in os.listdir(os.curdir): - if name.endswith('.egg-info'): - dirs.add(name) - if name.endswith('.egg'): - dirs.add(name) - rmrf(dirs) -namespace_clean.add_task(eggs_clean, 'eggs') -@invoke.task -def pycache_clean(context): - "Remove __pycache__ directories" - #pylint: disable=unused-argument - with context.cd(TASK_ROOT_STR): - dirs = set() - for root, dirnames, _ in os.walk(os.curdir): - if '__pycache__' in dirnames: - dirs.add(os.path.join(root, '__pycache__')) - print("Removing __pycache__ directories") - rmrf(dirs, verbose=False) -namespace_clean.add_task(pycache_clean, 'pycache') +namespace_clean.add_task(dist_clean, 'dist') + # # make a dummy clean task which runs all the tasks in the clean namespace clean_tasks = list(namespace_clean.tasks.values()) @invoke.task(pre=list(namespace_clean.tasks.values()), default=True) def clean_all(context): - "Run all clean tasks" - #pylint: disable=unused-argument + """Run all clean tasks""" + # pylint: disable=unused-argument pass + + namespace_clean.add_task(clean_all, 'all') @invoke.task(pre=[clean_all]) def sdist(context): - "Create a source distribution" + """Create a source distribution""" with context.cd(TASK_ROOT_STR): context.run('python setup.py sdist') + + namespace.add_task(sdist) + @invoke.task(pre=[clean_all]) def wheel(context): - "Build a wheel distribution" + """Build a wheel distribution""" with context.cd(TASK_ROOT_STR): context.run('python setup.py bdist_wheel') + + namespace.add_task(wheel) + @invoke.task(pre=[sdist, wheel]) def pypi(context): - "Build and upload a distribution to pypi" + """Build and upload a distribution to pypi""" with context.cd(TASK_ROOT_STR): context.run('twine upload dist/*') + + namespace.add_task(pypi) + @invoke.task(pre=[sdist, wheel]) def pypi_test(context): - "Build and upload a distribution to https://test.pypi.org" + """Build and upload a distribution to https://test.pypi.org""" with context.cd(TASK_ROOT_STR): context.run('twine upload --repository-url https://test.pypi.org/legacy/ dist/*') + + namespace.add_task(pypi_test) # Flake8 - linter and tool for style guide enforcement and linting @invoke.task def flake8(context): - "Run flake8 linter and tool for style guide enforcement" + """Run flake8 linter and tool for style guide enforcement""" with context.cd(TASK_ROOT_STR): - context.run("flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics --exclude=.git,__pycache__,.tox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov") + context.run("flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics " + "--exclude=.git,__pycache__,.tox,.nox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov") + + namespace.add_task(flake8) diff --git a/plugins/cmd2_ext_test/tests/__init__.py b/plugins/ext_test/tests/__init__.py index eb198dc0..eb198dc0 100644 --- a/plugins/cmd2_ext_test/tests/__init__.py +++ b/plugins/ext_test/tests/__init__.py diff --git a/plugins/cmd2_ext_test/tests/pylintrc b/plugins/ext_test/tests/pylintrc index 1dd17c1c..1dd17c1c 100644 --- a/plugins/cmd2_ext_test/tests/pylintrc +++ b/plugins/ext_test/tests/pylintrc diff --git a/plugins/cmd2_ext_test/tests/test_ext_test.py b/plugins/ext_test/tests/test_ext_test.py index cf5429b8..cf5429b8 100644 --- a/plugins/cmd2_ext_test/tests/test_ext_test.py +++ b/plugins/ext_test/tests/test_ext_test.py diff --git a/plugins/tasks.py b/plugins/tasks.py index 4aac4f77..7edcc08d 100644 --- a/plugins/tasks.py +++ b/plugins/tasks.py @@ -14,7 +14,7 @@ import shutil import sys import invoke -from plugins.cmd2_ext_test import tasks as ext_test_tasks +from plugins.ext_test import tasks as ext_test_tasks # create namespaces namespace = invoke.Collection() @@ -26,22 +26,19 @@ namespace.add_collection(namespace_clean, 'clean') # pytest, tox, pylint, and codecov # ##### -@invoke.task(pre=[ext_test_tasks.pytest]) -def pytest(_): - """Run tests and code coverage using pytest""" - pass - - -namespace.add_task(pytest) -@invoke.task(pre=[ext_test_tasks.pytest_junit]) -def pytest_junit(_): +@invoke.task() +def pytest(_, junit=False, pty=True): """Run tests and code coverage using pytest""" - pass + iexec = invoke.Executor([]) + iexec.execute([ + invoke.call(ext_test_tasks.pytest, junit=junit, pty=pty, append_cov=True) + ]) -namespace.add_task(pytest_junit) + +namespace.add_task(pytest) @invoke.task(pre=[ext_test_tasks.pytest_clean]) @@ -54,17 +51,18 @@ namespace_clean.add_task(pytest_clean, 'pytest') @invoke.task(pre=[ext_test_tasks.mypy]) -def mypy(context): +def mypy(_): """Run mypy optional static type checker""" pass namespace.add_task(mypy) + @invoke.task(pre=[ext_test_tasks.mypy_clean]) -def mypy_clean(context): +def mypy_clean(_): """Remove mypy cache directory""" - #pylint: disable=unused-argument + # pylint: disable=unused-argument pass @@ -79,9 +77,11 @@ namespace_clean.add_task(mypy_clean, 'mypy') BUILDDIR = 'build' DISTDIR = 'dist' + @invoke.task(pre=[ext_test_tasks.build_clean]) def build_clean(_): """Remove the build directory""" + pass namespace_clean.add_task(build_clean, 'build') @@ -96,32 +96,14 @@ def dist_clean(_): namespace_clean.add_task(dist_clean, 'dist') -@invoke.task(pre=[ext_test_tasks.eggs_clean]) -def eggs_clean(context): - """Remove egg directories""" - pass - - -namespace_clean.add_task(eggs_clean, 'eggs') - - -@invoke.task(pre=[ext_test_tasks.pycache_clean]) -def pycache_clean(context): - """Remove __pycache__ directories""" - pass - - -namespace_clean.add_task(pycache_clean, 'pycache') - - # make a dummy clean task which runs all the tasks in the clean namespace clean_tasks = list(namespace_clean.tasks.values()) @invoke.task(pre=list(namespace_clean.tasks.values()), default=True) -def clean_all(context): +def clean_all(_): """Run all clean tasks""" - #pylint: disable=unused-argument + # pylint: disable=unused-argument pass @@ -129,38 +111,28 @@ namespace_clean.add_task(clean_all, 'all') @invoke.task(pre=[clean_all], post=[ext_test_tasks.sdist]) -def sdist(context): - "Create a source distribution" - context.run('python setup.py sdist') +def sdist(_): + """Create a source distribution""" + pass namespace.add_task(sdist) @invoke.task(pre=[clean_all], post=[ext_test_tasks.wheel]) -def wheel(context): - "Build a wheel distribution" - context.run('python setup.py bdist_wheel') -namespace.add_task(wheel) - - -@invoke.task(pre=[sdist, wheel]) -def pypi(context): - "Build and upload a distribution to pypi" - context.run('twine upload dist/*') -namespace.add_task(pypi) +def wheel(_): + """Build a wheel distribution""" + pass -@invoke.task(pre=[sdist, wheel]) -def pypi_test(context): - "Build and upload a distribution to https://test.pypi.org" - context.run('twine upload --repository-url https://test.pypi.org/legacy/ dist/*') -namespace.add_task(pypi_test) +namespace.add_task(wheel) # Flake8 - linter and tool for style guide enforcement and linting @invoke.task(pre=[ext_test_tasks.flake8]) -def flake8(context): - "Run flake8 linter and tool for style guide enforcement" - context.run("flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics --exclude=.git,__pycache__,.tox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov") +def flake8(_): + """Run flake8 linter and tool for style guide enforcement""" + pass + + namespace.add_task(flake8) |