Skip to content

Commit

Permalink
Enable CSpell check (#188)
Browse files Browse the repository at this point in the history
Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
  • Loading branch information
cristianonicolai and ssbarnea committed Oct 11, 2023
1 parent 4de3315 commit 0f67041
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 23 deletions.
37 changes: 37 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
argparsing
caplog
cidrblock
filterwarnings
pathsep
pytest
setenv
setuptools
startpath
metafunc
testpaths
udring
webservers
addoption
Rominger
Barroso
Laska
runas
runtask
pluginmanager
modifyitems
fixturenames
getfixturevalue
getplugin
pytestmark
autouse
rootpath
VIRSH
pytester
getgroup
addini
addinivalue_line
lineinfile
pandoc
funcargs
pytrace
reportinfo
fspath
NOTESTSCOLLECTED
TESTSFAILED
USAGEERROR
makepyfile
runpytest_subprocess
parseoutcomes
runpytest
errlines
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ repos:
hooks:
- id: black
language_version: python3
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v7.3.1
hooks:
- id: cspell
name: Spell check with cspell
- repo: https://github.com/pycqa/pylint
rev: v3.0.1
hooks:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_uptime(ansible_adhoc):

The `HostManager` object returned by the `ansible_adhoc()` function provides
numerous ways of calling ansible modules against some, or all, of the
inventory. The following demonstates sample usage.
inventory. The following demonstrates sample usage.

```python
def test_host_manager(ansible_adhoc):
Expand Down Expand Up @@ -301,11 +301,11 @@ such as cloud modules (ec2, gce etc...).
def test_do_something_cloudy(localhost, ansible_adhoc):
"""Deploy an ec2 instance using multiple fixtures."""
params = dict(
key_name='somekey',
key_name='some_key',
instance_type='t2.micro',
image='ami-123456',
wait=True,
group='webserver',
group='webservers',
count=1,
vpc_subnet_id='subnet-29e63245',
assign_public_ip=True,
Expand Down Expand Up @@ -395,7 +395,7 @@ def test_terminate_us_east_1_instances(ansible_adhoc):
'''do some testing'''
```

#### Parameterizing with `pytest.mark.ansible`
#### Parameterize with `pytest.mark.ansible`

Perhaps the `--ansible-inventory=<inventory>` includes many systems, but you
only wish to interact with a subset. The `pytest.mark.ansible` marker can be
Expand Down Expand Up @@ -477,7 +477,7 @@ def test_adhoc_result(ansible_adhoc):
# With __getattr__
assert contacted.localhost.is_successful

# Or __gettem__
# Or __getitem__
assert contacted['localhost'].is_successful
```

Expand All @@ -488,7 +488,7 @@ on that use by way of the `ModuleResult` interface. The `ModuleResult`
class represents the dictionary returned by the ansible module for a particular
host. The contents of the dictionary depend on the module called.

The `ModuleResult` interface provides some convenient proprerties to
The `ModuleResult` interface provides some convenient properties to
determine the success of the module call. Examples are included below.

```python
Expand Down
23 changes: 23 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
dictionaryDefinitions:
- name: words
path: .config/dictionary.txt
addWords: true
dictionaries:
- bash
- networking-terms
- python
- words
- en_US
ignorePaths:
# All dot files in the root
- \.*
# This file
- cspell.config.yaml
# The shared file for tool configuration
- pyproject.toml
# requirements files
- .config/requirements*
# The tox configuration file
- tox.ini
languageSettings:
- languageId: python
2 changes: 1 addition & 1 deletion src/pytest_ansible/module_dispatcher/v213.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
try:
# init_plugin_loader was introduced in Ansible-core change here, v2.15
# https://github.com/ansible/ansible/pull/78915
# Whenever a new vXYZ.py dispather module is introduced, make this static import
# Whenever a new vXYZ.py dispatcher module is introduced, make this static import
# pylint: disable=ungrouped-imports
from ansible.plugins.loader import init_plugin_loader
except ImportError:
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_ansible/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def __init__(self, name, parent) -> None:
"""Construct MoleculeItem."""
self.funcargs = {}
super().__init__(name, parent)
moleculeyml = self.path
with Path(moleculeyml).open(encoding="utf-8") as stream:
molecule_yml = self.path
with Path(molecule_yml).open(encoding="utf-8") as stream:
# If the molecule.yml file is empty, YAML loader returns None. To
# simplify things down the road, we replace None with an empty
# dict.
Expand Down Expand Up @@ -227,7 +227,7 @@ def runtest(self):

def reportinfo(self):
"""Return representation of test location when in verbose mode."""
return self.fspath, 0, f"usecase: {self.name}"
return self.fspath, 0, f"use_case: {self.name}"

def __str__(self) -> str:
"""Return name of the test."""
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_ansible/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def pytest_addoption(parser):
"--ansible-unit-inject-only",
action="store_true",
default=False,
help="Enable support for ansible collection unit tests by only injecting exisiting ANSIBLE_COLLECTIONS_PATH.",
help="Enable support for ansible collection unit tests by only injecting existing ANSIBLE_COLLECTIONS_PATH.",
)
group.addoption(
"--molecule",
Expand Down Expand Up @@ -323,7 +323,7 @@ def __init__(self, config) -> None:
"""Initialize plugin."""
self.config = config

def pytest_report_header(self, config, startdir):
def pytest_report_header(self):
"""Return the version of ansible."""
return f"ansible: {ansible.__version__}"

Expand Down
4 changes: 2 additions & 2 deletions src/pytest_ansible/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def get_collection_name(start_path: Path) -> tuple[str | None, str | None]:
logger.info("Looking for collection info in %s", info_file)

try:
with info_file.open(encoding="utf-8") as fhand:
galaxy_info = yaml.safe_load(fhand)
with info_file.open(encoding="utf-8") as file_handler:
galaxy_info = yaml.safe_load(file_handler)
except FileNotFoundError:
logger.error("No galaxy.yml file found, plugin not activated")
return None, None
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_molecule_disabled() -> None:


def test_molecule_runtest() -> None:
"""Test running the molecule scenarion via pytest."""
"""Test running the molecule scenario via pytest."""
try:
proc = subprocess.run(
f"{sys.executable} -m pytest --molecule tests/fixtures/molecule/default/molecule.yml",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_func(ansible_module):
'to create when becoming an unprivileged user')
else:
assert 'msg' in result, "Missing expected field in JSON response: msg"
assert 'sudo: unknown user: asdfasdf' in result['msg']
assert 'sudo: unknown user: unknown_user' in result['msg']
"""

testdir.makepyfile(src)
Expand All @@ -183,7 +183,7 @@ def test_func(ansible_module):
"localhost", # run against a single host
"--ansible-become", # Enable become support
"--ansible-become-user",
"asdfasdf", # Connect as asdfasdf
"unknown_user", # Connect as unknown_user
],
)
assert result.ret == EXIT_OK
Expand Down
18 changes: 12 additions & 6 deletions tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_func(ansible_module):
or parse_version(ansible.__version__) >= parse_version("2.4.0"),
reason="requires ansible >= 2.0 and < 2.4",
)
def test_params_required_with_bogus_inventory_v2(testdir, option, recwarn):
def test_params_required_with_bogus_inventory_v2(testdir, option):
src = """
import pytest
def test_func(ansible_module):
Expand All @@ -207,7 +207,7 @@ def test_func(ansible_module):
) as mock_exists:
result = testdir.runpytest(
*[
"-vvvvvs",
*option.args,
"--ansible-inventory",
"bogus",
"--ansible-host-pattern",
Expand All @@ -224,7 +224,7 @@ def test_func(ansible_module):

@pytest.mark.requires_ansible_v24()
@pytest.mark.skipif(has_ansible_v28, reason="requires ansible < 2.8")
def test_params_required_with_bogus_inventory_v24(testdir, option, recwarn):
def test_params_required_with_bogus_inventory_v24(testdir, option):
src = """
import pytest
def test_func(ansible_module):
Expand All @@ -239,7 +239,13 @@ def test_func(ansible_module):
testdir.makepyfile(src)

result = testdir.runpytest(
*["-vvvvvs", "--ansible-inventory", "bogus", "--ansible-host-pattern", "all"],
*[
*option.args,
"--ansible-inventory",
"bogus",
"--ansible-host-pattern",
"all",
],
)

# Assert pytest exit code
Expand Down Expand Up @@ -282,7 +288,7 @@ def test_func(ansible_module):
assert result.ret == EXIT_OK


def test_param_override_with_marker(testdir):
def test_param_override_with_marker(testdir, option):
src = """
import pytest
@pytest.mark.ansible(inventory='local,', connection='local', host_pattern='all')
Expand All @@ -292,7 +298,7 @@ def test_func(ansible_module):
testdir.makepyfile(src)
result = testdir.runpytest(
*[
"-vvvvvs",
*option.args,
"--tb",
"native",
"--ansible-inventory",
Expand Down

0 comments on commit 0f67041

Please sign in to comment.