-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: NilashishC <[email protected]>
- Loading branch information
1 parent
b7312ca
commit a16c037
Showing
12 changed files
with
207 additions
and
1 deletion.
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
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,3 @@ | ||
pytest | ||
pytest-xdist | ||
tox |
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,67 @@ | ||
--- | ||
name: tox | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
pre: | ||
name: pre | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
matrix: ${{ steps.generate_matrix.outputs.matrix }} | ||
steps: | ||
- name: Determine matrix | ||
id: generate_matrix | ||
uses: coactions/dynamic-matrix@v1 | ||
with: | ||
min_python: "3.9" | ||
max_python: "3.11" | ||
default_python: "3.11" | ||
other_names: lint | ||
|
||
tox: | ||
name: ${{ matrix.name }} / python ${{ matrix.python_version }} | ||
runs-on: ubuntu-20.04 | ||
needs: pre | ||
strategy: | ||
fail-fast: false | ||
matrix: ${{ fromJson(needs.pre.outputs.matrix) }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # needed by setuptools-scm | ||
|
||
- name: Set up Python ${{ matrix.python_version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python_version }} | ||
|
||
- name: Install tox | ||
run: python3 -m pip install --upgrade "tox>=4.0.2" | ||
|
||
- name: Log Python info (${{ matrix.python_version }}) | ||
run: | | ||
command -v python | ||
python --version --version | ||
python3 -m pip freeze --all | ||
- name: "tox -e ${{ matrix.passed_name }}" | ||
continue-on-error: ${{ matrix.devel || false }} | ||
run: python3 -m tox -e ${{ matrix.passed_name }} | ||
|
||
tox_passed: | ||
needs: tox | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: >- | ||
python -c "assert set([ | ||
'${{ needs.tox.result }}', | ||
]) == {'success'}" |
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 |
---|---|---|
|
@@ -11,4 +11,6 @@ build/ | |
|
||
*.mypy_cache/ | ||
|
||
*.tox/ | ||
|
||
__pycache__/ |
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
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,2 @@ | ||
[pytest] | ||
testpaths = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Unit tests for ansible-creator.""" |
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,6 @@ | ||
"""conftest.""" | ||
import os | ||
|
||
|
||
os.environ["HOME"] = "/home/ansible" | ||
os.environ["DEV_WORKSPACE"] = "collections/ansible_collections" |
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,89 @@ | ||
"""Basic unit tests for ansible-creator.""" | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from ansible_creator.cli import Cli | ||
from ansible_creator.config import Config | ||
from ansible_creator.utils import expand_path | ||
|
||
|
||
def test_expand_path() -> None: | ||
"""Test expand_path utils.""" | ||
assert ( | ||
expand_path("~/$DEV_WORKSPACE/namespace/collection") | ||
== "/home/ansible/collections/ansible_collections/namespace/collection" | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
argnames=["sysargs", "expected"], | ||
argvalues=[ | ||
[ | ||
["ansible-creator", "init", "testorg.testcol"], | ||
{ | ||
"subcommand": "init", | ||
"no_ansi": False, | ||
"log_file": str(Path.cwd() / "ansible-creator.log"), | ||
"log_level": "notset", | ||
"log_append": "true", | ||
"json": False, | ||
"verbose": 0, | ||
"collection": "testorg.testcol", | ||
"init_path": "./", | ||
"force": False, | ||
}, | ||
], | ||
[ | ||
[ | ||
"ansible-creator", | ||
"init", | ||
"testorg.testcol", | ||
"--init-path=/home/ansible", | ||
"-vvv", | ||
"--json", | ||
"--no-ansi", | ||
"--la=false", | ||
"--lf=test.log", | ||
"--ll=debug", | ||
"--force", | ||
], | ||
{ | ||
"subcommand": "init", | ||
"no_ansi": True, | ||
"log_file": "test.log", | ||
"log_level": "debug", | ||
"log_append": "false", | ||
"json": True, | ||
"verbose": 3, | ||
"collection": "testorg.testcol", | ||
"init_path": "/home/ansible", | ||
"force": True, | ||
}, | ||
], | ||
], | ||
) | ||
def test_cli_parser(monkeypatch, sysargs, expected) -> None: # noqa: ANN001 | ||
"""Test CLI args parsing.""" | ||
monkeypatch.setattr("sys.argv", sysargs) | ||
assert vars(Cli().parse_args()) == expected | ||
|
||
|
||
def test_configuration_class() -> None: | ||
"""Test Config() dataclass post_init.""" | ||
cli_args: dict = { | ||
"creator_version": "0.0.1", | ||
"json": True, | ||
"log_append": True, | ||
"log_file": "./ansible-creator.log", | ||
"log_level": "debug", | ||
"no_ansi": False, | ||
"subcommand": "init", | ||
"verbose": 2, | ||
"collection": "testorg.testcol", | ||
"init_path": "$HOME", | ||
} | ||
app_config = Config(**cli_args) | ||
assert app_config.namespace == "testorg" | ||
assert app_config.collection_name == "testcol" | ||
assert app_config.init_path == "/home/ansible" |
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,26 @@ | ||
[tox] | ||
requires = | ||
tox>=4.2 | ||
env_list = | ||
py | ||
lint | ||
no_package = true | ||
skip_missing_interpreters = true | ||
work_dir = {env:TOX_WORK_DIR:.tox} | ||
|
||
[testenv:py] | ||
description = Run pytest under {basepython} ({envpython}) | ||
deps = | ||
-e .[test] | ||
commands = | ||
python --version | ||
pip list | ||
pytest {posargs:tests} | ||
|
||
[testenv:lint] | ||
description = Enforce quality standards under {basepython} ({envpython}) | ||
skip_install = true | ||
deps = | ||
pre-commit | ||
commands = | ||
pre-commit run --show-diff-on-failure --all-files |