Commit 4a49e42d authored by Grant Paton-Simpson's avatar Grant Paton-Simpson

Minor fixes and tests

* Fix bug in CLI displayer when displaying ## >>> result comments
* Test linting regex pattern
* Bump version
parent c375ae4e
Pipeline #574 failed with stages
......@@ -9,16 +9,7 @@ from .. import conf, lint_conf
from ..utils import get_nice_str_list, get_os_platform, \
layout_comment as layout, make_open_tmp_file
## extract patterns e.g. from:
## /tmp/snippet.py:1:23: W291 trailing whitespace
## /tmp/snippet.py:4:1: E999 IndentationError: unexpected indent
prog = re.compile(
fr"""^.+?: ## starts with misc until first colon e.g. /tmp/snippet.py: (+? to be non-greedy)
(?P<{conf.LINT_LINE_NO}>\d+) ## line_no = one or more digits after snippet.py: and before the next : e.g. 4
:\d+:\s{{1}} ## one or more digits, :, and one space e.g. '1: '
(?P<{conf.LINT_MSG_TYPE}>\w{{1}}\d{{1,3}})\s{{1}} ## msg_type = (one letter, 1-3 digits) and one space e.g. E999
(?P<{conf.LINT_MSG}>.*) ## msg = everything else e.g. 'IndentationError: unexpected indent'
""", flags=re.VERBOSE) # @UndefinedVariable
prog = re.compile(lint_conf.LINT_PATTERN, flags=re.VERBOSE) # @UndefinedVariable
def _store_snippet(snippet):
tmp_fh, fpath = make_open_tmp_file(conf.SNIPPET_FNAME, mode='w')
......
......@@ -66,6 +66,7 @@ def code(text, from_fenced_block=None, **kw):
text = ('\n' + text).replace('\n ', '\n')[1:]
# funny: ":-" confuses the tokenizer. replace/backreplace:
raw_code = text.replace(':-', '\x01--')
raw_code = raw_code.replace('## &gt;&gt;&gt;', '## >>>')
text = cli_utils.style_ansi(raw_code)
# unnested level has indent of N_LEFT_INDENT, use it for fenced
indent = ' ' * kw.get('nesting_level', cli_conf.N_LEFT_INDENT)
......
from collections import namedtuple
from . import conf # @UnresolvedImport
## extract patterns e.g. from:
## /tmp/snippet.py:1:23: W291 trailing whitespace
## /tmp/snippet.py:4:1: E999 IndentationError: unexpected indent
LINT_PATTERN = fr"""^.+?: ## starts with misc until first colon e.g. /tmp/snippet.py: (+? to be non-greedy)
(?P<{conf.LINT_LINE_NO}>\d+) ## line_no = one or more digits after snippet.py: and before the next : e.g. 4
:\d+:\s{{1}} ## one or more digits, :, and one space e.g. '1: '
(?P<{conf.LINT_MSG_TYPE}>\w{{1}}\d{{1,3}})\s{{1}} ## msg_type = (one letter, 1-3 digits) and one space e.g. E999
(?P<{conf.LINT_MSG}>.*) ## msg = everything else e.g. 'IndentationError: unexpected indent'
"""
## https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
## https://flake8.pycqa.org/en/latest/user/error-codes.html
IGNORED_LINT_RULES = [
......
......@@ -95,7 +95,6 @@ def layout_comment(raw_comment, *, is_code=False):
)
indented_lines = [f"{' ' * 4}{line}" for line in lines]
comment = f'\n'.join(indented_lines) + '\n' ## new line at end needed otherwise content of next str (if any) becomes part of code highlighting
comment = f'\n'.join(indented_lines) + '\n' ## new line at end needed otherwise content of next str (if any) becomes part of code highlighting
else:
raw_paragraphs = dedent(raw_comment).split('\n\n') ## we only split paragraphs if two new lines
new_paragraphs = []
......
import re
from nose.tools import assert_equal, assert_not_equal, assert_true, assert_false # @UnusedImport @UnresolvedImport
try:
from ..superhelp import lint_conf # @UnresolvedImport @UnusedImport
except (ImportError, ValueError):
from pathlib import Path
import sys
parent = str(Path.cwd().parent.parent)
sys.path.insert(0, parent)
from superhelp import lint_conf # @Reimport
def test_linter_regex():
tests = [
(r'/tmp/snippet.py:1:23: W291 trailing whitespace',
{'line_no': '1', 'msg_type': 'W291', 'msg': 'trailing whitespace'}),
(r'/tmp/snippet.py:4:1: E999 IndentationError: unexpected indent' ,
{'line_no': '4', 'msg_type': 'E999', 'msg': 'IndentationError: unexpected indent'}),
(r'path location:2222:333333333: E000 this has lots of spaces in it and punctuation ;:!@#$%^&*()_+|{}[]<>?/' ,
{'line_no': '2222', 'msg_type': 'E000', 'msg': 'this has lots of spaces in it and punctuation ;:!@#$%^&*()_+|{}[]<>?/'}),
]
for lint_str, expected_dict in tests:
actual_dict = re.match(
lint_conf.LINT_PATTERN, lint_str, flags=re.VERBOSE).groupdict() # @UndefinedVariable
assert_equal(actual_dict, expected_dict)
# test_linter_regex()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment