Skip to content

Commit 0ad637d

Browse files
committed
0.1.2 minor refactoring and readme fix
1 parent fdc2e91 commit 0ad637d

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ When both Flake8 and ``flake8-test-name`` are installed, the plugin
2020
will show up when displaying the version of ``flake8``::
2121

2222
$ flake8 --version
23-
3.6.0 (flake8-test-name: 0.1.0, […]
23+
3.6.0 (flake8-test-name: 0.1.2, […]
2424

2525

2626
Parameters
@@ -33,7 +33,7 @@ or
3333

3434
E.g usage with the regex::
3535

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

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

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

5151
You can then configure the plugin with::
5252

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

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

@@ -69,13 +69,17 @@ This plugin is using the following error codes:
6969
Operation
7070
---------
7171

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

7575

7676
Changes
7777
-------
7878

79+
0.1.2 - 2021-03-21
80+
``````````````````
81+
* minor refactoring and doc improvement
82+
7983
0.1.1 - 2021-03-19
8084
``````````````````
8185
* Initial release

flake8_test_name.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66

77
# metadata
8-
__version__ = "0.1.1"
8+
__version__ = "0.1.2"
99
CODE_PREFIX = "TN"
1010

1111
# constants
@@ -50,10 +50,6 @@ def regex_validator(func_name):
5050
return regex_validator
5151

5252

53-
def format_code(code):
54-
return f"{CODE_PREFIX}{code}"
55-
56-
5753
def resolve_path(dir_path):
5854
dir_path = os.path.expanduser(dir_path)
5955
return os.path.abspath(dir_path)
@@ -104,13 +100,17 @@ class MyFlake8Plugin(Flake8Argparse):
104100

105101
version = __version__
106102
name = "test-name"
103+
code_previx = CODE_PREFIX
107104

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

109+
def format_code(self, code):
110+
return f"{self.code_previx}{code}"
111+
112112
def _generate_error(self, node, code, func_name):
113-
msg = "{0} {1}".format(format_code(code), self.ERRORS[code])
113+
msg = "{0} {1}".format(self.format_code(code), self.ERRORS[code])
114114
msg = msg.format(func_name=func_name)
115115
return node.lineno, node.col_offset, msg, type(self)
116116

test_flake8_test_name.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from flake8_test_name import (
99
Flake8Argparse,
1010
MyFlake8Plugin,
11-
format_code,
1211
resolve_path,
1312
MyVisitor,
1413
_get_validator_from_module,
@@ -70,9 +69,6 @@ def test__resolve_path_relative(self):
7069
def test__resolve_path_expand(self):
7170
assert resolve_path("~/tmp") == os.path.expanduser("~/tmp")
7271

73-
def test__format_code(self):
74-
assert format_code(302) == "TN302"
75-
7672
#
7773
# @pytest.mark.parametrize(
7874
# "func_name",
@@ -141,6 +137,10 @@ def test_visitor_find_all_methods(self):
141137

142138

143139
class TestMyFlake8Plugin:
140+
def test__format_code(self):
141+
checker = MyFlake8Plugin(None, SAMPLE_FILE_PATH)
142+
assert checker.format_code(302) == "TN302"
143+
144144
def test__get_invalid_test_methods__no_match(self):
145145
code_snippet = "import garbage\n\ndef test__im_a_valid_method__when_this__then_that():\n pass"
146146
tree = get_tree_from_str(code_snippet)

0 commit comments

Comments
 (0)