extra-syntaxes: First of test suite of extra syntaxes using HEADER macro with test_syntax_parsing

This commit is contained in:
DancingQuanta 2018-09-23 11:28:32 +01:00 committed by Tomas Babej
parent ca3f5c844c
commit 920c065d98
2 changed files with 78 additions and 0 deletions

41
tests/conftest.py Normal file
View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
import pytest
import re
markup_headers = {
'default': {
'HEADER1': "= %s =",
'HEADER2': "== %s ==",
'HEADER3': "=== %s ===",
},
'markdown': {
'HEADER1': "# %s",
'HEADER2': "## %s",
'HEADER3': "### %s",
}
}
@pytest.fixture(params=markup_headers)
def test_syntax(request):
markup = request.param
format_header_dict = markup_headers[markup]
def header_expand(string):
"""
The function perform string replacement of 'HEADER1(.+)' with a header
syntax for a markup containing the string found in '.+'. This function
is constructed with a dict of three header levels containing their regex
and actual syntax.
When a markup is selected and this function is executed, the function
will find instance of 'HEADER1' with 1 being any number between 1 and 3
inclusive.
"""
for header_level, format_header in format_header_dict.items():
regex = header_level + '\((.*?)\)'
string = re.sub(regex,
lambda match: format_header % match.group(1),
string)
return string
return (markup, header_expand)

View file

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
import pytest
from taskwiki import regexp
import re
class TestParsingSyntax(object):
def test_header(self, test_syntax):
markup, header_expand = test_syntax
header = "HEADER1(Test)"
header = header_expand(header)
print("Markup: %s,\nHeader syntax:\n%s\nRegex pattern:\n%s" % (
markup, header, regexp.HEADER[markup].pattern))
if re.match(regexp.HEADER[markup], header):
assert 1
else:
assert 0
def test_macro_viewport(self, test_syntax):
markup, header_expand = test_syntax
viewport = "HEADER1(Test | project:Home | +home #T $T)"
viewport = header_expand(viewport)
print("Viewport syntax:\n%s\nRegex pattern:\n%s" % (
viewport, regexp.VIEWPORT[markup].pattern))
match = re.search(regexp.VIEWPORT[markup], viewport)
assert match != None
assert match.group('name').strip() == "Test"
assert match.group('filter').strip() == "project:Home"
assert match.group('defaults').strip() == "+home"
assert match.group('source').strip() == "T"
assert match.group('sort').strip() == "T"