Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.5.3
- repo: https://github.com/PyCQA/isort
rev: 5.6.4
hooks:
- id: isort
- repo: https://github.com/python/black.git
Expand All @@ -9,7 +9,7 @@ repos:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v3.2.0
rev: v3.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -19,7 +19,7 @@ repos:
- id: check-merge-conflict
- id: debug-statements
- repo: https://gitlab.com/pycqa/flake8.git
rev: 3.8.3
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/adrienverge/yamllint.git
Expand All @@ -29,3 +29,11 @@ repos:
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.6.0
hooks:
- id: pylint
additional_dependencies:
- pytest
- pyyaml
- tox
21 changes: 21 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[MESSAGES CONTROL]

disable =
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
invalid-name,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
no-member,
no-self-use,
redefined-outer-name,
too-few-public-methods,
unused-argument,
useless-object-inheritance,

[REPORTS]
output-format = colorized

[IMPORTS]
preferred-modules =
ansible:,
3 changes: 1 addition & 2 deletions src/tox_ansible/ansible/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ def requirements(self):
requirements_txt = path.join(self.directory, "requirements.txt")
if path.isfile(requirements_txt):
return requirements_txt
else:
return None
return None
9 changes: 4 additions & 5 deletions src/tox_ansible/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from tox import hookimpl

from tox_ansible import tox_helper as tox_helper

from .ansible import Ansible
from .filter import Filter
from .options import (
from tox_ansible import tox_helper
from tox_ansible.ansible import Ansible
from tox_ansible.filter import Filter
from tox_ansible.options import (
DRIVER_ENV_NAME,
DRIVER_OPTION_NAME,
SCENARIO_ENV_NAME,
Expand Down
2 changes: 1 addition & 1 deletion src/tox_ansible/matrix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def __init__(self):
self.axes = []

def add_axis(self, axis):
"""Add an exansion axis to this matrix. Axes can be found in the
"""Add an extension axis to this matrix. Axes can be found in the
axes.py file and are subclasses of the MatrixAxisBase class.

:param axis: An expansion axis to add to this matrix."""
Expand Down
5 changes: 4 additions & 1 deletion src/tox_ansible/tox_base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ def _expand(self, name):
:param name: An additional field to be added to the name factors
:return: A copy of this object with the additional name factor"""
if hasattr(self, "scenario"):
# pylint: disable=too-many-function-args
copy = self.__class__(self.scenario, [name] + self._name_parts)
else:
copy = self.__class__(self._cases, [name] + self._name_parts)
copy = self.__class__( # pylint: disable=too-many-function-args
self._cases, [name] + self._name_parts
)
copy.python = self.python
copy.ansible = self.ansible
return copy
Expand Down
2 changes: 2 additions & 0 deletions src/tox_ansible/tox_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get_reader(self, section, prefix=None):
:param section: Config section name to read from
:param prefix: Any applicable prefix to the ini section name. Default
None"""
# pylint: disable=protected-access
reader = SectionReader(section, self.config._cfg, prefix=prefix)
distshare_default = join(str(self.config.homedir), ".tox", "distshare")
reader.addsubstitutions(
Expand Down Expand Up @@ -88,6 +89,7 @@ def add_envconfigs(self, tox_cases, options):
self.config.ansible_envlist = []
for tox_case in tox_cases:
section = testenvprefix + tox_case.get_name()
# pylint: disable=protected-access
config = make_envconfig(
self.config, tox_case.get_name(), section, reader._subs, self.config
)
Expand Down
7 changes: 3 additions & 4 deletions src/tox_ansible/tox_lint_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@


class ToxLintCase(ToxBaseCase):
def __init__(self, cases, name_parts=[]):
def __init__(self, cases, name_parts=None):
self._cases = copy(cases)
self._name_parts = name_parts
self._name_parts = name_parts or []
self._config = Tox()
super(ToxLintCase, self).__init__()
super().__init__()

def get_commands(self, options):
cmds = []
Expand Down Expand Up @@ -47,4 +47,3 @@ def get_name(self):
@property
def description(self):
return "Auto-generated environment to run: molecule lint on all scenarios"
"scenarios"
6 changes: 3 additions & 3 deletions src/tox_ansible/tox_molecule_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class ToxMoleculeCase(ToxBaseCase):
"""Represents a generalized Test Case for an Ansible structure."""

def __init__(self, scenario, name_parts=[]):
def __init__(self, scenario, name_parts=None):
"""Create the base test case.

:param scenario: The scenario that this test case should run"""
Expand All @@ -36,8 +36,8 @@ def __init__(self, scenario, name_parts=[]):
"pytest",
"testinfra",
]
self._name_parts = name_parts
super(ToxMoleculeCase, self).__init__()
self._name_parts = name_parts or []
super().__init__()

def get_commands(self, options):
"""Get the commands that this scenario should execute.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
@pytest.mark.parametrize("scenarios,expected", [([1], True), ([], False)])
def test_with_scenarios(mocker, scenarios, expected):
ansible = Ansible()
ansible._scenarios = scenarios
ansible._scenarios = scenarios # pylint: disable=protected-access
assert ansible.is_ansible == expected
6 changes: 1 addition & 5 deletions tests/test_by_driver.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from unittest import TestCase
from unittest.mock import Mock

from tox_ansible.filter.by_driver import ByDriver

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock


class TestByDriver(TestCase):
def test_no_case(self):
Expand Down
9 changes: 2 additions & 7 deletions tests/test_by_scenario.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from unittest import TestCase

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from collections import namedtuple
from unittest import TestCase
from unittest.mock import Mock

from tox_ansible.filter.by_scenario import ByScenario

Expand Down
16 changes: 4 additions & 12 deletions tests/test_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import contextlib
import os
import subprocess
from unittest.mock import patch

import pytest

try:
from unittest.mock import patch
except ImportError:
from mock import patch


EXPECTED = {
"tests/fixtures/collection": "\n".join(
[
Expand Down Expand Up @@ -71,8 +66,6 @@ def cd(directory):
os.chdir(directory)
try:
yield
except Exception:
raise
finally:
os.chdir(cwd)

Expand All @@ -81,13 +74,12 @@ def run_tox(args, capture):
tox = ["tox"]
tox.extend(args)
try:
subprocess.run(tox)
subprocess.run(tox, check=True)
except SystemExit as s:
if s.code != 0:
raise
finally:
outs = capture.readouterr()
return outs.out.strip()
outs = capture.readouterr()
return outs.out.strip()


@pytest.mark.parametrize(
Expand Down
9 changes: 2 additions & 7 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# For rennamed/moved assert(Count|Item)Equal
from unittest import TestCase

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from collections import namedtuple
from unittest import TestCase
from unittest.mock import Mock

from tox_ansible.filter import Filter

Expand Down
6 changes: 1 addition & 5 deletions tests/test_options.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from unittest import TestCase
from unittest.mock import Mock

from tox_ansible.options import Options

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock


class TestOptions(TestCase):
def test_do_filter_scenario(self):
Expand Down
7 changes: 2 additions & 5 deletions tests/test_tox_lint_case.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from unittest.mock import Mock

from tox_ansible.ansible.scenario import Scenario
from tox_ansible.tox_lint_case import ToxLintCase

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock


def test_names_are_correct(mocker):
tc = ToxLintCase([])
Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def tox_envlist(self, arguments=None):

self.assertEqual(returncode, 0, stderr)

return [env for env in stdout.strip().splitlines()]
return stdout.strip().splitlines()