-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from sola-st/aryaz/multiprocess
Major changes to support coverage gathering and multiprocess support
- Loading branch information
Showing
38 changed files
with
735 additions
and
157 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: end2end tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.11", "3.12"] | ||
os: ["ubuntu-latest"] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install hatch | ||
pip install pytest | ||
- name: Install DynaPyt | ||
run: | | ||
pip install -e . | ||
- name: Run the test script | ||
run: | | ||
hatch run end2end:run |
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 |
---|---|---|
|
@@ -27,4 +27,4 @@ jobs: | |
pip install . | ||
- name: Test with pytest | ||
run: | | ||
pytest | ||
pytest tests |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# End-to-end Tests | ||
This directory holds the projects and scripts used for testing DynaPyt end-to-end. | ||
The `projects` directory contains the projects used for testing. | ||
Each project should also have an `analysis` module from its root. For example, a project named `foo` should have `foo.analysis`, which is the analysis class used for the tests. | ||
The `scripts` directory contains the scripts required to run the tests. | ||
|
||
To run the end-to-end tests: | ||
- Install `hatch` with `pip install hatch`. | ||
- Run `hatch run end2end:run`. | ||
- Since the execution does not use pytest, the success of the tests depend on the exit code of the previous step. |
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,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024-present Aryaz Eghbali <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,21 @@ | ||
# Simple with Pytest | ||
|
||
[![PyPI - Version](https://img.shields.io/pypi/v/simple-with-pytest.svg)](https://pypi.org/project/simple-with-pytest) | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/simple-with-pytest.svg)](https://pypi.org/project/simple-with-pytest) | ||
|
||
----- | ||
|
||
**Table of Contents** | ||
|
||
- [Installation](#installation) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
```console | ||
pip install simple-with-pytest | ||
``` | ||
|
||
## License | ||
|
||
`simple-with-pytest` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. |
7 changes: 7 additions & 0 deletions
7
end2end_tests/projects/simple-with-pytest/expected_coverage.json
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,7 @@ | ||
{ | ||
"simple-with-pytest/src/simple_with_pytest/simple.py.orig": { | ||
"2": {"Analysis": 2}, | ||
"6": {"Analysis": 2}, | ||
"10": {"Analysis": 2} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
end2end_tests/projects/simple-with-pytest/expected_output.json
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,37 @@ | ||
{ | ||
"config": { | ||
"workers": 6 | ||
}, | ||
"output": [ | ||
[ | ||
"begin execution", | ||
"1 Add 1 = 2", | ||
"end execution" | ||
], | ||
[ | ||
"begin execution", | ||
"2 Add 1 = 3", | ||
"end execution" | ||
], | ||
[ | ||
"begin execution", | ||
"1 Multiply 2 = 2", | ||
"end execution" | ||
], | ||
[ | ||
"begin execution", | ||
"2 Multiply 2 = 4", | ||
"end execution" | ||
], | ||
[ | ||
"begin execution", | ||
"1 Add 2 = 3", | ||
"end execution" | ||
], | ||
[ | ||
"begin execution", | ||
"2 Add 3 = 5", | ||
"end execution" | ||
] | ||
] | ||
} |
157 changes: 157 additions & 0 deletions
157
end2end_tests/projects/simple-with-pytest/pyproject.toml
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,157 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "simple-with-pytest" | ||
dynamic = ["version"] | ||
description = '' | ||
readme = "README.md" | ||
requires-python = ">=3.7" | ||
license = "MIT" | ||
keywords = [] | ||
authors = [ | ||
{ name = "Aryaz Eghbali", email = "[email protected]" }, | ||
] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dependencies = [] | ||
|
||
[project.urls] | ||
Documentation = "https://github.com/unknown/simple-with-pytest#readme" | ||
Issues = "https://github.com/unknown/simple-with-pytest/issues" | ||
Source = "https://github.com/unknown/simple-with-pytest" | ||
|
||
[tool.hatch.version] | ||
path = "src/simple_with_pytest/__about__.py" | ||
|
||
[tool.hatch.envs.default] | ||
dependencies = [ | ||
"coverage[toml]>=6.5", | ||
"pytest", | ||
] | ||
[tool.hatch.envs.default.scripts] | ||
test = "pytest {args:tests}" | ||
test-cov = "coverage run -m pytest {args:tests}" | ||
cov-report = [ | ||
"- coverage combine", | ||
"coverage report", | ||
] | ||
cov = [ | ||
"test-cov", | ||
"cov-report", | ||
] | ||
|
||
[[tool.hatch.envs.all.matrix]] | ||
python = ["3.7", "3.8", "3.9", "3.10", "3.11"] | ||
|
||
[tool.hatch.envs.lint] | ||
detached = true | ||
dependencies = [ | ||
"black>=23.1.0", | ||
"mypy>=1.0.0", | ||
"ruff>=0.0.243", | ||
] | ||
[tool.hatch.envs.lint.scripts] | ||
typing = "mypy --install-types --non-interactive {args:src/simple_with_pytest tests}" | ||
style = [ | ||
"ruff {args:.}", | ||
"black --check --diff {args:.}", | ||
] | ||
fmt = [ | ||
"black {args:.}", | ||
"ruff --fix {args:.}", | ||
"style", | ||
] | ||
all = [ | ||
"style", | ||
"typing", | ||
] | ||
|
||
[tool.black] | ||
target-version = ["py37"] | ||
line-length = 120 | ||
skip-string-normalization = true | ||
|
||
[tool.ruff] | ||
target-version = "py37" | ||
line-length = 120 | ||
select = [ | ||
"A", | ||
"ARG", | ||
"B", | ||
"C", | ||
"DTZ", | ||
"E", | ||
"EM", | ||
"F", | ||
"FBT", | ||
"I", | ||
"ICN", | ||
"ISC", | ||
"N", | ||
"PLC", | ||
"PLE", | ||
"PLR", | ||
"PLW", | ||
"Q", | ||
"RUF", | ||
"S", | ||
"T", | ||
"TID", | ||
"UP", | ||
"W", | ||
"YTT", | ||
] | ||
ignore = [ | ||
# Allow non-abstract empty methods in abstract base classes | ||
"B027", | ||
# Allow boolean positional values in function calls, like `dict.get(... True)` | ||
"FBT003", | ||
# Ignore checks for possible passwords | ||
"S105", "S106", "S107", | ||
# Ignore complexity | ||
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915", | ||
] | ||
unfixable = [ | ||
# Don't touch unused imports | ||
"F401", | ||
] | ||
|
||
[tool.ruff.isort] | ||
known-first-party = ["simple_with_pytest"] | ||
|
||
[tool.ruff.flake8-tidy-imports] | ||
ban-relative-imports = "all" | ||
|
||
[tool.ruff.per-file-ignores] | ||
# Tests can use magic values, assertions, and relative imports | ||
"tests/**/*" = ["PLR2004", "S101", "TID252"] | ||
|
||
[tool.coverage.run] | ||
source_pkgs = ["simple_with_pytest", "tests"] | ||
branch = true | ||
parallel = true | ||
omit = [ | ||
"src/simple_with_pytest/__about__.py", | ||
] | ||
|
||
[tool.coverage.paths] | ||
simple_with_pytest = ["src/simple_with_pytest", "*/simple-with-pytest/src/simple_with_pytest"] | ||
tests = ["tests", "*/simple-with-pytest/tests"] | ||
|
||
[tool.coverage.report] | ||
exclude_lines = [ | ||
"no cov", | ||
"if __name__ == .__main__.:", | ||
"if TYPE_CHECKING:", | ||
] |
5 changes: 5 additions & 0 deletions
5
end2end_tests/projects/simple-with-pytest/src/simple_with_pytest/__about__.py
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,5 @@ | ||
# SPDX-FileCopyrightText: 2024-present Aryaz Eghbali <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# DYNAPYT: DO NOT INSTRUMENT | ||
__version__ = "0.0.1" |
4 changes: 4 additions & 0 deletions
4
end2end_tests/projects/simple-with-pytest/src/simple_with_pytest/__init__.py
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,4 @@ | ||
# SPDX-FileCopyrightText: 2024-present Aryaz Eghbali <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# DYNAPYT: DO NOT INSTRUMENT |
22 changes: 22 additions & 0 deletions
22
end2end_tests/projects/simple-with-pytest/src/simple_with_pytest/analysis.py
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,22 @@ | ||
# DYNAPYT: DO NOT INSTRUMENT | ||
|
||
import json | ||
from uuid import uuid4 | ||
from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
|
||
class Analysis(BaseAnalysis): | ||
def __init__(self, output_dir: str = None): | ||
self.output_dir = output_dir | ||
self.output = [] | ||
|
||
def begin_execution(self): | ||
self.output.append("begin execution") | ||
|
||
def end_execution(self): | ||
self.output.append("end execution") | ||
with open(f"{self.output_dir}/output-{str(uuid4())}.json", "w") as f: | ||
json.dump(self.output, f, indent=2) | ||
|
||
def binary_operation(self, dyn_ast, iid, op, left, right, result): | ||
self.output.append(f"{left} {op} {right} = {result}") |
10 changes: 10 additions & 0 deletions
10
end2end_tests/projects/simple-with-pytest/src/simple_with_pytest/simple.py
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,10 @@ | ||
def add_one(x: int) -> int: | ||
return x + 1 | ||
|
||
|
||
def multiply_two(x: int) -> int: | ||
return x * 2 | ||
|
||
|
||
def add_together(x: int, y: int) -> int: | ||
return x + y |
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,4 @@ | ||
# SPDX-FileCopyrightText: 2024-present Aryaz Eghbali <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# DYNAPYT: DO NOT INSTRUMENT |
25 changes: 25 additions & 0 deletions
25
end2end_tests/projects/simple-with-pytest/tests/test_simple.py
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,25 @@ | ||
from simple_with_pytest.simple import add_one, multiply_two, add_together | ||
|
||
|
||
def test_add_one_1(): | ||
assert add_one(1) == 2 | ||
|
||
|
||
def test_add_one_2(): | ||
assert add_one(2) == 3 | ||
|
||
|
||
def test_multiply_two_1(): | ||
assert multiply_two(1) == 2 | ||
|
||
|
||
def test_multiply_two_2(): | ||
assert multiply_two(2) == 4 | ||
|
||
|
||
def test_add_together_1_2(): | ||
assert add_together(1, 2) == 3 | ||
|
||
|
||
def test_add_together_2_3(): | ||
assert add_together(2, 3) == 5 |
Oops, something went wrong.