Skip to content

Commit

Permalink
Merge pull request #74 from KeerthiVasudevan/main
Browse files Browse the repository at this point in the history
Added execution invariance test
  • Loading branch information
AryazE authored Sep 5, 2024
2 parents a132327 + 3a6d793 commit 8a497ed
Show file tree
Hide file tree
Showing 21 changed files with 488 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/execution-invariance-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: execution invariance tests

on: [push]

jobs:
test:

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-json-report
- name: Install DynaPyt
run: |
pip install -e .
- name: Run the test script
run: |
hatch run exec_invariance_test:run
4 changes: 4 additions & 0 deletions execution_invariance_test/__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
9 changes: 9 additions & 0 deletions execution_invariance_test/analysis/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2024-present Keerthi <[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 execution_invariance_test/analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# analysis

[![PyPI - Version](https://img.shields.io/pypi/v/analysis.svg)](https://pypi.org/project/analysis)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/analysis.svg)](https://pypi.org/project/analysis)

-----

## Table of Contents

- [Installation](#installation)
- [License](#license)

## Installation

```console
pip install analysis
```

## License

`analysis` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
66 changes: 66 additions & 0 deletions execution_invariance_test/analysis/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "analysis"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
keywords = []
authors = [
{ name = "Keerthi", email = "[email protected]" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []

[project.urls]
Documentation = "https://github.com/Keerthi/analysis#readme"
Issues = "https://github.com/Keerthi/analysis/issues"
Source = "https://github.com/Keerthi/analysis"

[tool.hatch.version]
path = "src/analysis/__about__.py"

[tool.hatch.envs.default]
dependencies = [
"pytest-json-report",
]

[tool.hatch.envs.types]
extra-dependencies = [
"mypy>=1.0.0",
]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/analysis tests}"

[tool.coverage.run]
source_pkgs = ["analysis", "tests"]
branch = true
parallel = true
omit = [
"src/analysis/__about__.py",
]

[tool.coverage.paths]
analysis = ["src/analysis", "*/analysis/src/analysis"]
tests = ["tests", "*/analysis/tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
4 changes: 4 additions & 0 deletions execution_invariance_test/analysis/src/analysis/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2024-present Keerthi <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "0.0.1"
3 changes: 3 additions & 0 deletions execution_invariance_test/analysis/src/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024-present Keerthi <[email protected]>
#
# SPDX-License-Identifier: MIT
8 changes: 8 additions & 0 deletions execution_invariance_test/analysis/src/analysis/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from dynapyt.analyses.BaseAnalysis import BaseAnalysis


class Analysis(BaseAnalysis):

def runtime_event(self, dyn_ast: str, iid: int) -> None:
pass
3 changes: 3 additions & 0 deletions execution_invariance_test/analysis/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024-present Keerthi <[email protected]>
#
# SPDX-License-Identifier: MIT
9 changes: 9 additions & 0 deletions execution_invariance_test/projects/simple-test/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2024-present Keerthi <[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 execution_invariance_test/projects/simple-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# simple-test

[![PyPI - Version](https://img.shields.io/pypi/v/simple-test.svg)](https://pypi.org/project/simple-test)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/simple-test.svg)](https://pypi.org/project/simple-test)

-----

## Table of Contents

- [Installation](#installation)
- [License](#license)

## Installation

```console
pip install simple-test
```

## License

`simple-test` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
61 changes: 61 additions & 0 deletions execution_invariance_test/projects/simple-test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "simple-test"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
keywords = []
authors = [
{ name = "Keerthi", email = "[email protected]" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []

[project.urls]
Documentation = "https://github.com/Keerthi/simple-test#readme"
Issues = "https://github.com/Keerthi/simple-test/issues"
Source = "https://github.com/Keerthi/simple-test"

[tool.hatch.version]
path = "src/simple_test/__about__.py"

[tool.hatch.envs.types]
extra-dependencies = [
"mypy>=1.0.0",
]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/simple_test tests}"

[tool.coverage.run]
source_pkgs = ["simple_test", "tests"]
branch = true
parallel = true
omit = [
"src/simple_test/__about__.py",
]

[tool.coverage.paths]
simple_test = ["src/simple_test", "*/simple-test/src/simple_test"]
tests = ["tests", "*/simple-test/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,17 @@
import traceback
import os.path

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


def get_stack():
return traceback.extract_stack()
10 changes: 10 additions & 0 deletions execution_invariance_test/projects/simple-test/tests/stack_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import traceback
from simple_test.simple import get_stack

def test_stack():
trace = get_stack()
trace_list = traceback.format_list(trace)
trace_length = len(trace_list)
expected_trace_str_length = 34
assert trace_length == expected_trace_str_length

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from simple_test.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
24 changes: 24 additions & 0 deletions execution_invariance_test/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

python3 -m venv venv
source venv/bin/activate
pip install -U pip setuptools
SCRIPTS_DIR=$(dirname $(realpath "$0"))
PARENT_DIR=$(dirname $SCRIPTS_DIR)
ANALYSIS_DIR=$SCRIPTS_DIR/analysis
pip install -e $ANALYSIS_DIR
pip install pytest-json-report
pip install $PARENT_DIR
uniqueID=$(python -c "import uuid; print(uuid.uuid4())")
export DYNAPYT_SESSION_ID=$uniqueID
echo "DYNAPYT_SESSION_ID=$DYNAPYT_SESSION_ID"
temp_dir="${TMPDIR:-/tmp}"
file_path=$temp_dir/dynapyt_analyses-$uniqueID.txt
touch $file_path
echo "analysis.analysis.Analysis" > $file_path
cat $file_path
python $SCRIPTS_DIR/test.py
deactivate
rm $temp_dir/dynapyt_analyses-$uniqueID.txt
rm -rf venv

Loading

0 comments on commit 8a497ed

Please sign in to comment.