Skip to content

Commit

Permalink
Added type information to tests (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Aug 24, 2020
1 parent 5987d7d commit aeef022
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/ansiblelint/rules/__init__.py
Expand Up @@ -190,7 +190,7 @@ def __init__(self, rulesdirs=None) -> None:
self.extend(load_plugins(rulesdir))
self.rules = sorted(self.rules, key=lambda r: r.id)

def register(self, obj):
def register(self, obj: AnsibleLintRule):
self.rules.append(obj)

def __iter__(self):
Expand Down
8 changes: 4 additions & 4 deletions lib/ansiblelint/runner.py
@@ -1,7 +1,7 @@
"""Runner implementation."""
import logging
import os
from typing import TYPE_CHECKING, Any, FrozenSet, Generator, List, Set
from typing import TYPE_CHECKING, Any, FrozenSet, Generator, List, Optional, Set

import ansiblelint.file_utils
import ansiblelint.skip_utils
Expand All @@ -23,9 +23,9 @@ def __init__(
self,
rules: "RulesCollection",
playbook: str,
tags: FrozenSet[Any],
skip_list: FrozenSet[Any],
exclude_paths: List[str],
tags: FrozenSet[Any] = frozenset(),
skip_list: Optional[FrozenSet[Any]] = frozenset(),
exclude_paths: List[str] = [],
verbosity: int = 0,
checked_files: Set[str] = None) -> None:
"""Initialize a Runner instance."""
Expand Down
3 changes: 0 additions & 3 deletions mypy.ini
Expand Up @@ -8,9 +8,6 @@ disallow_untyped_calls = True
[mypy-ansiblelint.*]
ignore_missing_imports = True

[mypy-test.*]
ignore_errors = True

# 3rd party ignores
[mypy-ansible]
ignore_missing_imports = True
Expand Down
12 changes: 8 additions & 4 deletions test/__init__.py
Expand Up @@ -5,12 +5,16 @@
import subprocess
import sys
import tempfile
from typing import Dict
from typing import TYPE_CHECKING, Dict, List

from ansible import __version__ as ansible_version_str

from ansiblelint.runner import Runner

if TYPE_CHECKING:
from ansiblelint.errors import MatchError


ANSIBLE_MAJOR_VERSION = tuple(map(int, ansible_version_str.split('.')[:2]))


Expand All @@ -21,8 +25,8 @@ def __init__(self, collection):
"""Initialize a RunFromText instance with rules collection."""
self.collection = collection

def _call_runner(self, path):
runner = Runner(self.collection, path, [], [], [])
def _call_runner(self, path) -> List["MatchError"]:
runner = Runner(self.collection, path)
return runner.run()

def run_playbook(self, playbook_text):
Expand Down Expand Up @@ -65,7 +69,7 @@ def run_ansible_lint(
else:
command = [sys.executable, "-m", "ansiblelint", "-v"]
if role_path:
command.append(role_path)
command.append(str(role_path))

result, err = subprocess.Popen(
command,
Expand Down
9 changes: 0 additions & 9 deletions test/custom_rules/example_com/ExampleComRule.py
Expand Up @@ -22,16 +22,7 @@
import ansiblelint.rules.AlwaysRunRule


def _false(*_args):
"""Return const False."""
return False


class ExampleComRule(ansiblelint.rules.AlwaysRunRule.AlwaysRunRule):
"""A dummy custom rule class."""

id = '100002'

match = _false
matchtask = _false
matchplay = _false
9 changes: 0 additions & 9 deletions test/custom_rules/example_inc/CustomAlwaysRunRule.py
Expand Up @@ -22,16 +22,7 @@
import ansiblelint.rules.AlwaysRunRule


def _false(*_args):
"""Return const False."""
return False


class CustomAlwaysRunRule(ansiblelint.rules.AlwaysRunRule.AlwaysRunRule):
"""Dummy custom rule class."""

id = '100001'

match = _false
matchtask = _false
matchplay = _false
2 changes: 1 addition & 1 deletion test/rules/EMatcherRule.py
Expand Up @@ -6,7 +6,7 @@ class EMatcherRule(AnsibleLintRule):
description = 'This is a test rule that looks for lines ' + \
'containing the letter e'
shortdesc = 'The letter "e" is present'
tags = {'fake', 'dummy', 'test1'}
tags = ['fake', 'dummy', 'test1']

def match(self, filename, line):
return "e" in line
2 changes: 1 addition & 1 deletion test/rules/UnsetVariableMatcherRule.py
Expand Up @@ -6,7 +6,7 @@ class UnsetVariableMatcherRule(AnsibleLintRule):
shortdesc = 'Line contains untemplated variable'
description = 'This is a test rule that looks for lines ' + \
'post templating that still contain {{'
tags = {'fake', 'dummy', 'test2'}
tags = ['fake', 'dummy', 'test2']

def match(self, filename, line):
return "{{" in line

0 comments on commit aeef022

Please sign in to comment.