Skip to content

Commit cced906

Browse files
authored
Restructuring and adding tests (#8)
* add tests requirements * initial test files * update git ignore for test repos * create a package structure with hatch * update json to use full payload with example values * update tests to use mocks * update noxfile to lint python files in src and tests dirs * add pytest plugins for mypy * make isort compatible with black * attempt to simplify things + url tests * gitignore dst/tmp directory * addressing review comments * add some docs for running tests
1 parent c85d1a8 commit cced906

14 files changed

Lines changed: 644 additions & 16 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ dmypy.json
132132

133133
# VScode stuff
134134
.vscode/
135+
136+
# Repository clone directory
137+
dst/tmp/output

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,27 @@ For example, to upgrade the `isort` package only:
7171
``` bash
7272
nox -s "pip-compile-3.12(formatters)" -- --no-upgrade --upgrade-package=isort
7373
```
74+
75+
## Running tests
76+
77+
This project contains several tests to verify functionality.
78+
To run the tests, do the following:
79+
80+
1. Install test requirements.
81+
82+
``` bash
83+
python -m pip install -r requirements/tests.in -c requirements/tests.txt
84+
```
85+
86+
1. From the repository root, run `pytest` in one of the following ways:
87+
88+
``` bash
89+
# Run all tests
90+
pytest
91+
92+
# Run a specific test class
93+
pytest tests/test_parser_functions.py::TestParseArguments
94+
95+
# Run a specific test function
96+
pytest tests/test_parser_functions.py::TestParseArguments::test_with_url_arg
97+
```

noxfile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import nox
55

6-
LINT_FILES = glob.glob("*.py")
6+
LINT_FILES = glob.glob("src/**/*.py", recursive=True) + glob.glob(
7+
"tests/**/*.py", recursive=True
8+
)
79

810
requirements_directory = Path("requirements")
911

pyproject.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "forge-webhook-parser"
7+
dynamic = ["version"]
8+
description = 'Parse webhook payloads from popular git forges.'
9+
readme = "README.md"
10+
requires-python = ">=3.9"
11+
license = "GPL-3.0-or-later"
12+
authors = [
13+
{ name = "Don Naro", email = "dnaro@redhat.com" },
14+
]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Programming Language :: Python",
18+
"Programming Language :: Python :: 3.8",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: Implementation :: CPython",
24+
"Programming Language :: Python :: Implementation :: PyPy",
25+
]
26+
dependencies = [
27+
"requests",
28+
]
29+
30+
[project.urls]
31+
Documentation = "https://github.com/fedora-copr/forge-webhook-parser/blob/main/README.md"
32+
Issues = "https://github.com/fedora-copr/forge-webhook-parser/issues"
33+
Source = "https://github.com/fedora-copr/forge-webhook-parser"
34+
35+
[project.scripts]
36+
forge-webhook-parser = "forge_webhook_parser.main:main"
37+
38+
[tool.hatch.version]
39+
path = "src/forge_webhook_parser/__init__.py"
40+
41+
[tool.hatch.build.targets.wheel]
42+
packages = ["src/forge_webhook_parser"]
43+
44+
[tool.hatch.envs.test]
45+
dependencies = [
46+
"pytest",
47+
"pytest-cov",
48+
]
49+
50+
[tool.hatch.envs.test.scripts]
51+
test = "pytest {args:tests}"
52+
test-cov = "pytest --cov=forge_webhook_parser {args:tests}"
53+
54+
[tool.pytest.ini_options]
55+
pythonpath = ["src"]
56+
57+
[tool.isort]
58+
profile = "black"

requirements/tests.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest

requirements/tests.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --output-file=requirements/tests.txt --strip-extras requirements/tests.in
6+
#
7+
iniconfig==2.0.0
8+
# via pytest
9+
packaging==24.1
10+
# via pytest
11+
pluggy==1.5.0
12+
# via pytest
13+
pytest==8.3.3
14+
# via -r requirements/tests.in

requirements/typing.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mypy
22
nox
33
types-requests
4+
pytest-mypy-plugins

requirements/typing.txt

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,76 @@
44
#
55
# pip-compile --allow-unsafe --output-file=requirements/typing.txt --strip-extras requirements/typing.in
66
#
7-
argcomplete==3.5.0
7+
argcomplete==3.6.0
88
# via nox
9-
colorlog==6.8.2
9+
attrs==25.3.0
10+
# via
11+
# jsonschema
12+
# nox
13+
# referencing
14+
colorlog==6.9.0
1015
# via nox
11-
distlib==0.3.8
16+
decorator==5.2.1
17+
# via pytest-mypy-plugins
18+
dependency-groups==1.3.0
19+
# via nox
20+
distlib==0.3.9
1221
# via virtualenv
13-
filelock==3.16.1
22+
filelock==3.18.0
1423
# via virtualenv
15-
mypy==1.11.2
16-
# via -r requirements/typing.in
24+
iniconfig==2.1.0
25+
# via pytest
26+
jinja2==3.1.6
27+
# via pytest-mypy-plugins
28+
jsonschema==4.23.0
29+
# via pytest-mypy-plugins
30+
jsonschema-specifications==2024.10.1
31+
# via jsonschema
32+
markupsafe==3.0.2
33+
# via jinja2
34+
mypy==1.15.0
35+
# via
36+
# -r requirements/typing.in
37+
# pytest-mypy-plugins
1738
mypy-extensions==1.0.0
1839
# via mypy
19-
nox==2024.4.15
40+
nox==2025.2.9
2041
# via -r requirements/typing.in
21-
packaging==24.1
22-
# via nox
23-
platformdirs==4.3.6
42+
packaging==24.2
43+
# via
44+
# dependency-groups
45+
# nox
46+
# pytest
47+
# pytest-mypy-plugins
48+
platformdirs==4.3.7
2449
# via virtualenv
25-
types-requests==2.32.0.20241016
50+
pluggy==1.5.0
51+
# via pytest
52+
pytest==8.3.5
53+
# via pytest-mypy-plugins
54+
pytest-mypy-plugins==3.2.0
55+
# via -r requirements/typing.in
56+
pyyaml==6.0.2
57+
# via pytest-mypy-plugins
58+
referencing==0.36.2
59+
# via
60+
# jsonschema
61+
# jsonschema-specifications
62+
regex==2024.11.6
63+
# via pytest-mypy-plugins
64+
rpds-py==0.23.1
65+
# via
66+
# jsonschema
67+
# referencing
68+
tomlkit==0.13.2
69+
# via pytest-mypy-plugins
70+
types-requests==2.32.0.20250306
2671
# via -r requirements/typing.in
2772
typing-extensions==4.12.2
28-
# via mypy
29-
urllib3==2.2.3
73+
# via
74+
# mypy
75+
# referencing
76+
urllib3==2.3.0
3077
# via types-requests
31-
virtualenv==20.26.5
78+
virtualenv==20.29.3
3279
# via nox
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from .main import (
2+
PayloadFields,
3+
clean_clone_path,
4+
clone_repo,
5+
extract_project_name,
6+
extract_repository_url,
7+
load_json_data,
8+
main,
9+
parse_arguments,
10+
parse_commits,
11+
)
12+
13+
__all__ = [
14+
"PayloadFields",
15+
"clean_clone_path",
16+
"clone_repo",
17+
"extract_project_name",
18+
"extract_repository_url",
19+
"load_json_data",
20+
"main",
21+
"parse_arguments",
22+
"parse_commits",
23+
]
24+
25+
__version__ = "0.1.0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def main():
106106
data = load_json_data(args)
107107
repo_url = extract_repository_url(data)
108108
project_name = extract_project_name(repo_url)
109-
clone_path = Path.cwd() / project_name
109+
clone_path = Path.cwd() / "dst" / "tmp" / "output" / project_name
110110

111111
clean_clone_path(clone_path)
112112
clone_repo(repo_url, clone_path)

0 commit comments

Comments
 (0)