Skip to content

Commit

Permalink
Add unit tests for init (#42)
Browse files Browse the repository at this point in the history
* Add unit tests for init

Signed-off-by: NilashishC <[email protected]>

* Updates and fixes

Signed-off-by: NilashishC <[email protected]>

* Add more options for toml-sort

Signed-off-by: NilashishC <[email protected]>

* Update tests

Signed-off-by: NilashishC <[email protected]>

* config updates

Signed-off-by: NilashishC <[email protected]>

* Remove type checking code from tests

Signed-off-by: NilashishC <[email protected]>

---------

Signed-off-by: NilashishC <[email protected]>
  • Loading branch information
NilashishC authored Dec 6, 2023
1 parent c8585ea commit b178ca1
Show file tree
Hide file tree
Showing 55 changed files with 1,225 additions and 24 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ autosectionlabel
basesystem
BUILDDIR
caplog
capsys
cliconf # Ansible network cli abstraction plugin
codeclimate
colname
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ build/

*.mypy_cache/

*.pytest_cache/

*.tox/

__pycache__/
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ repos:
- pytest
args:
- src
- tests
- --python-version=3.9
pass_filenames: false
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"editor.defaultFormatter": "ms-python.black-formatter"
},
"mypy.runUsingActiveInterpreter": true,
"mypy.targets": ["src", "tests"],
"mypy.targets": ["src"],
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ documentation = "https://ansible-creator.readthedocs.io/en/latest/"
homepage = "https://github.com/ansible-community/ansible-creator"
repository = "https://github.com/ansible-community/ansible-creator"

[tool.black]
exclude = "tests/fixtures"

[tool.mypy]
files = ["src", "tests"]
files = ["src"]

[tool.pydoclint]
allow-init-docstring = true

[tool.pylint]

[tool.pylint.MASTER]
ignore-patterns = 'test_*'

[tool.pylint.format]
max-line-length = 100

Expand All @@ -71,6 +77,7 @@ disable = [

[tool.ruff]
builtins = ["__"]
exclude = ['tests']
fix = true
ignore = [
"C901",
Expand Down Expand Up @@ -114,5 +121,6 @@ local_scheme = "no-local-version"
write_to = "src/ansible_creator/_version.py"

[tool.tomlsort]
all = true
in_place = true
sort_inline_tables = true
sort_table_keys = true
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[pytest]
testpaths = tests
tmp_path_retention_policy=failed
addopts = --ignore=tests/fixtures
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
pull_request:
branches: [main]
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"

jobs:
ansible-lint:
Expand Down Expand Up @@ -39,4 +39,4 @@ jobs:
'${{ needs.sanity.result }}',
'${{ needs.unit-galaxy.result }}'
]) == {'success'}"
{% endraw %}
{%- endraw %}
3 changes: 2 additions & 1 deletion src/ansible_creator/resources/new_collection/README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ Please check the included content on the [Ansible Galaxy page for this collectio
```
ansible-galaxy collection install {{ namespace }}.{{ collection_name }}
```

You can also include it in a `requirements.yml` file and install it via `ansible-galaxy collection install -r requirements.yml` using the format:

```yaml
collections:
- name: {{ namespace }}.{{ collection_name }}
- name: {{ namespace }}.{{ collection_name }}
```

To upgrade the collection to the latest available version, run the following command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ scenario:
- converge
destroy_sequence:
- destroy
{% endraw %}
{%- endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
vars:
test_path: "{{ integration_tests_path }}{{ test_name }}"
test_name: "{{ molecule_scenario_name.replace('integration_', '') }}"
{% endraw %}
{%- endraw %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% raw %}
collection_root: "{{ lookup( 'pipe', 'git rev-parse --show-toplevel') }}"
{% raw %}collection_root: "{{ lookup( 'pipe', 'git rev-parse --show-toplevel') }}"
integration_tests_path: "{{ collection_root }}/tests/integration/targets/"
molecule_scenario_name: "{{ molecule_scenario_directory | basename }}"
{% endraw %}
{%- endraw %}
3 changes: 1 addition & 2 deletions src/ansible_creator/resources/new_collection/galaxy.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: "{{ collection_name }}"
version: 1.0.0
readme: README.md
authors:
- your name <example@domain.com>
- your name <example@domain.com>

description: your collection description
license_file: LICENSE
Expand All @@ -26,7 +26,6 @@ issues: http://example.com/issue/tracker
build_ignore:
- .gitignore
- changelogs/.plugin-cache.yaml

# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a
# list of MANIFEST.in style
# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__metaclass__ = type # pylint: disable=C0103


def _hello_world(name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ line-length = 100

[tool.pytest.ini_options]
addopts = ["-vvv", "-n", "2", "--log-level", "WARNING", "--color", "yes"]
testpaths = ["tests"]
filterwarnings = ['ignore:AnsibleCollectionFinder has already been configured']
testpaths = ["tests"]
6 changes: 0 additions & 6 deletions src/ansible_creator/resources/new_collection/tests/unit/.keep
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
Will be updated by antsibull-changelog. Do not edit this manually!

See https://github.com/ansible-community/antsibull-changelog/blob/main/docs/changelogs.rst for information
on how to use antsibull-changelog.

Check out changelogs/config.yaml for its configuration. You need to change at least the title field in there.
6 changes: 6 additions & 0 deletions tests/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Constants with default values used throughout the tests."""

from pathlib import Path


FIXTURES_DIR = (Path(__file__).parent / "fixtures").resolve()
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: GHA for testorg.testcol

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on: # yamllint disable-line rule:truthy
pull_request:
branches: [main]
workflow_dispatch:
schedule:
- cron: "0 0 * * *"

jobs:
ansible-lint:
uses: ansible-network/github_actions/.github/workflows/ansible-lint.yml@main
changelog:
uses: ansible-network/github_actions/.github/workflows/changelog.yml@main
integration:
uses: ansible-network/github_actions/.github/workflows/integration_simple.yml@main
sanity:
uses: ansible-network/github_actions/.github/workflows/sanity.yml@main
unit-galaxy:
uses: ansible-network/github_actions/.github/workflows/unit_galaxy.yml@main

all_green:
if: ${{ always() && (github.event_name != 'schedule') }}
needs:
- changelog
- integration
- sanity
- unit-galaxy
runs-on: ubuntu-latest
steps:
- run: >-
python -c "assert set([
'${{ needs.changelog.result }}',
'${{ needs.integration.result }}',
'${{ needs.sanity.result }}',
'${{ needs.unit-galaxy.result }}'
]) == {'success'}"
6 changes: 6 additions & 0 deletions tests/fixtures/collection/testorg/testcol/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
known_first_party=ansible_collections.testorg.testcol
line_length=100
lines_after_imports=2
lines_between_types=1
profile=black
45 changes: 45 additions & 0 deletions tests/fixtures/collection/testorg/testcol/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
repos:
- repo: https://github.com/ansible-network/collection_prep
rev: 1.1.1
hooks:
- id: update-docs

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: end-of-file-fixer
- id: no-commit-to-branch
args: [--branch, main]
- id: trailing-whitespace

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0"
hooks:
- id: prettier
entry: env CI=1 bash -c "prettier --list-different . || ec=$? && prettier --loglevel=error --write . && exit $ec"
pass_filenames: false
args: []
additional_dependencies:
- prettier
- prettier-plugin-toml

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
name: Sort import statements using isort
args: ["--filter-files"]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
19 changes: 19 additions & 0 deletions tests/fixtures/collection/testorg/testcol/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# files we don't want prettier to ever to look into
.*/
coverage/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# A linked collection directory created by pytest-ansible-units
collections/

tests/output/

README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["redhat.ansible"]
}
6 changes: 6 additions & 0 deletions tests/fixtures/collection/testorg/testcol/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This should be updated by antsibull-changelog. Do not edit this manually!

See https://github.com/ansible-community/antsibull-changelog/blob/main/docs/changelogs.rst for
information on how to use antsibull-changelog.

Check out ``changelogs/config.yaml`` for its configuration. You need to change at least the ``title`` field in there.
3 changes: 3 additions & 0 deletions tests/fixtures/collection/testorg/testcol/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Community Code of Conduct

Please see the official [Ansible Community Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html).
3 changes: 3 additions & 0 deletions tests/fixtures/collection/testorg/testcol/CONTRIBUTING
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing

Refer to the [Ansible community guide](https://docs.ansible.com/ansible/devel/community/index.html).
Loading

0 comments on commit b178ca1

Please sign in to comment.