Skip to content

Commit

Permalink
Merge pull request #51 from sola-st/aryaz/multiprocess
Browse files Browse the repository at this point in the history
Major changes to support coverage gathering and multiprocess support
  • Loading branch information
AryazE authored Feb 28, 2024
2 parents 830f9a7 + aaa77d4 commit f253772
Show file tree
Hide file tree
Showing 38 changed files with 735 additions and 157 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/end2end-tests.yml
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
pip install .
- name: Test with pytest
run: |
pytest
pytest tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ myenv
*~
*.json
!src/dynapyt/utils/hierarchy.json
!*tests/**/*.json
__pycache__
workspace.code-workspace
*.egg-info
Expand Down
10 changes: 10 additions & 0 deletions end2end_tests/README.md
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.
9 changes: 9 additions & 0 deletions end2end_tests/projects/simple-with-pytest/LICENSE.txt
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.
21 changes: 21 additions & 0 deletions end2end_tests/projects/simple-with-pytest/README.md
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.
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 end2end_tests/projects/simple-with-pytest/expected_output.json
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 end2end_tests/projects/simple-with-pytest/pyproject.toml
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:",
]
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"
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
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}")
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
4 changes: 4 additions & 0 deletions end2end_tests/projects/simple-with-pytest/tests/__init__.py
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 end2end_tests/projects/simple-with-pytest/tests/test_simple.py
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
Loading

0 comments on commit f253772

Please sign in to comment.