Skip to content

Commit

Permalink
0.1.2 minor refactoring and readme fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-bagerard committed Mar 21, 2021
1 parent fdc2e91 commit 0ad637d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ When both Flake8 and ``flake8-test-name`` are installed, the plugin
will show up when displaying the version of ``flake8``::

$ flake8 --version
3.6.0 (flake8-test-name: 0.1.0, […]
3.6.0 (flake8-test-name: 0.1.2, […]


Parameters
Expand All @@ -33,7 +33,7 @@ or

E.g usage with the regex::

$ flake8 myproject/tests/sample.py --test-func-name-validator-regex="test_funky_convention_.*" --select=II101
$ flake8 myproject/tests/sample.py --test-func-name-validator-regex="test_funky_convention_.*" --select=TN101

>>myproject/tests/sample.py:14:1: TN101 test function name does not match the convention (test_invalid_method_sample)

Expand All @@ -50,7 +50,7 @@ Assuming you have a funky_validator.py file with the following content::

You can then configure the plugin with::

$ flake8 myproject/tests/sample.py --test-func-name-validator-module=./funky_validator.py --select=II101
$ flake8 myproject/tests/sample.py --test-func-name-validator-module=./funky_validator.py --select=TN101

>>myproject/tests/sample.py:14:1: TN101 test function name does not match the convention (test_invalid_method_sample)

Expand All @@ -69,13 +69,17 @@ This plugin is using the following error codes:
Operation
---------

The plugin will go through all files, look for directories "tests", and validate method
The plugin will go through all files, look for directories named "tests", and validate method
starting with `test_` against your validator.


Changes
-------

0.1.2 - 2021-03-21
``````````````````
* minor refactoring and doc improvement

0.1.1 - 2021-03-19
``````````````````
* Initial release
12 changes: 6 additions & 6 deletions flake8_test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re

# metadata
__version__ = "0.1.1"
__version__ = "0.1.2"
CODE_PREFIX = "TN"

# constants
Expand Down Expand Up @@ -50,10 +50,6 @@ def regex_validator(func_name):
return regex_validator


def format_code(code):
return f"{CODE_PREFIX}{code}"


def resolve_path(dir_path):
dir_path = os.path.expanduser(dir_path)
return os.path.abspath(dir_path)
Expand Down Expand Up @@ -104,13 +100,17 @@ class MyFlake8Plugin(Flake8Argparse):

version = __version__
name = "test-name"
code_previx = CODE_PREFIX

ERRORS = {
101: "test function name does not match the convention ({func_name})",
}

def format_code(self, code):
return f"{self.code_previx}{code}"

def _generate_error(self, node, code, func_name):
msg = "{0} {1}".format(format_code(code), self.ERRORS[code])
msg = "{0} {1}".format(self.format_code(code), self.ERRORS[code])
msg = msg.format(func_name=func_name)
return node.lineno, node.col_offset, msg, type(self)

Expand Down
8 changes: 4 additions & 4 deletions test_flake8_test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from flake8_test_name import (
Flake8Argparse,
MyFlake8Plugin,
format_code,
resolve_path,
MyVisitor,
_get_validator_from_module,
Expand Down Expand Up @@ -70,9 +69,6 @@ def test__resolve_path_relative(self):
def test__resolve_path_expand(self):
assert resolve_path("~/tmp") == os.path.expanduser("~/tmp")

def test__format_code(self):
assert format_code(302) == "TN302"

#
# @pytest.mark.parametrize(
# "func_name",
Expand Down Expand Up @@ -141,6 +137,10 @@ def test_visitor_find_all_methods(self):


class TestMyFlake8Plugin:
def test__format_code(self):
checker = MyFlake8Plugin(None, SAMPLE_FILE_PATH)
assert checker.format_code(302) == "TN302"

def test__get_invalid_test_methods__no_match(self):
code_snippet = "import garbage\n\ndef test__im_a_valid_method__when_this__then_that():\n pass"
tree = get_tree_from_str(code_snippet)
Expand Down

0 comments on commit 0ad637d

Please sign in to comment.