-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
98 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
/tests/MPh.ini | ||
**/__pycache__ | ||
**/.pytest_cache | ||
.coverage | ||
coverage.xml | ||
flake8.txt | ||
.spyproject | ||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
"""Builds the installation package.""" | ||
__license__ = 'MIT' | ||
|
||
from subprocess import run | ||
from pathlib import Path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
"""Deletes cache and build artifacts.""" | ||
__license__ = 'MIT' | ||
"""Deletes build and test artifacts.""" | ||
|
||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
root = Path(__file__).resolve().parent.parent | ||
|
||
for folder in root.rglob('__pycache__'): | ||
rmtree(folder, ignore_errors=True) | ||
folders = [ | ||
root/'deploy'/'docs', | ||
root/'deploy'/'coverage', | ||
root/'deploy'/'dist', | ||
root/'dist', | ||
] | ||
folder_names = [ | ||
'__pycache__', | ||
'.pytest_cache', | ||
] | ||
for folder_name in folder_names: | ||
for folder in root.rglob(folder_name): | ||
folders.append(folder) | ||
for folder in folders: | ||
if folder.is_dir(): | ||
rmtree(folder, ignore_errors=True) | ||
|
||
for folder in root.rglob('.pytest_cache'): | ||
rmtree(folder) | ||
|
||
for folder in ('docs', 'dist', 'coverage'): | ||
rmtree(root/'deploy'/folder, ignore_errors=True) | ||
files = [ | ||
root/'.coverage', | ||
root/'coverage.xml', | ||
] | ||
for file in files: | ||
if file.is_file(): | ||
file.unlink() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Uploads the coverage report to CodeCov.""" | ||
|
||
from subprocess import run | ||
from pathlib import Path | ||
from os import environ | ||
|
||
token = environ.get('MPh_CodeCov_token', None) | ||
if not token: | ||
raise RuntimeError('CodeCov upload token not set in environment.') | ||
|
||
root = Path(__file__).resolve().parent.parent.parent | ||
run(['codecov', '--file', 'coverage.xml', '--token', token], cwd=root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
"""Measures code coverage by test suite.""" | ||
__license__ = 'MIT' | ||
|
||
""" | ||
Measures code coverage by test suite. | ||
We cannot just run pyTest on the entire test suite (in the `tests` folder | ||
of the repo) because the individual scripts there all start a client in | ||
their respective setup routine. That is, they all start the Java VM, | ||
which will fail once pyTest gets to the second script in the sequence. | ||
Instead, we run pyTest for each script seperately, with the coverage | ||
plug-in enabled, and generate the coverage report incrementally. | ||
If the coverage report file (`coverage.xml`) already exists, we instead | ||
render it as HTML for inspection. This is helpful during development. | ||
The coverage report may also be uploaded to an online service such as | ||
CodeCov for each published release or even commit. | ||
""" | ||
|
||
from subprocess import run | ||
from pathlib import Path | ||
from sys import argv | ||
|
||
|
||
here = Path(__file__).resolve().parent | ||
root = here.parent | ||
file = here/'coverage.sqlite' | ||
|
||
rerun = 'rerun' in argv[1:] | ||
append = 'append' in argv[1:] | ||
|
||
if rerun and not append and file.exists(): | ||
file.unlink() | ||
|
||
if file.exists() and not append: | ||
print('Coverage report already exists.') | ||
else: | ||
command = ['pytest', '--cov', '--cov-append'] | ||
tests = ['config', 'discovery', 'server', 'client', 'client-server', | ||
'stand-alone', 'node', 'model', 'processes'] | ||
file = root/'coverage.xml' | ||
if not file.exists(): | ||
command = ['pytest', '--cov', '--cov-append', '--cov-report', 'xml'] | ||
tests = ['config', 'discovery', 'server', 'client', 'client-server', | ||
'stand-alone', 'node', 'model', 'processes'] | ||
for test in tests: | ||
run(command + [f'tests/test_{test}.py'], cwd=root) | ||
|
||
print('Rendering coverage report.') | ||
folder = (here/'coverage').relative_to(root) | ||
run(['coverage', 'html', f'--directory={folder}'], cwd=root) | ||
|
||
badge = root/'tests'/file.with_suffix('.svg').name | ||
if badge.exists(): | ||
print('Coverage badge already exists.') | ||
else: | ||
print('Rendering coverage badge.') | ||
run(['coverage-badge', '-f', '-o', str(badge)], cwd=root) | ||
print('Rendering existing coverage report as HTML.') | ||
folder = (here/'coverage').relative_to(root) | ||
run(['coverage', 'html', f'--directory={folder}'], cwd=root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
"""Publishes the package on PyPI.""" | ||
__license__ = 'MIT' | ||
|
||
from subprocess import run | ||
from pathlib import Path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
"""Renders the documentation.""" | ||
__license__ = 'MIT' | ||
|
||
from subprocess import run | ||
from pathlib import Path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Runs all tests in the intended order. | ||
This script does not use pyTest, but runs the test scripts as is, | ||
in a subprocess. We impose the intended order, from the most basic | ||
functionality to the high-level abstractions. | ||
Pass 'log' as a command-line argument to have the scripts print log | ||
messages to the console while the tests are running. Pass 'debug' to | ||
increase the verbosity of the log. | ||
""" | ||
|
||
from subprocess import run | ||
from pathlib import Path | ||
from timeit import default_timer as now | ||
import sys | ||
|
||
tests = ['config', 'discovery', 'server', 'client', 'client-server', | ||
'stand-alone', 'node', 'model', 'processes'] | ||
folder = Path(__file__).parent.parent / 'tests' | ||
python = sys.executable | ||
arguments = sys.argv[1:] | ||
for test in tests: | ||
print(f'test_{test}') | ||
t0 = now() | ||
process = run([python, f'test_{test}.py'] + arguments, cwd=folder) | ||
if process.returncode == 0: | ||
print(f'Passed in {now()-t0:.0f} s.') | ||
else: | ||
print(f'Failed after {now()-t0:.0f} s.') | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters