From 135575da1e0a9974b2ef31ccb2961cd0f976ad0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnter=20Milde?= Date: Thu, 23 Feb 2017 22:05:09 +0100 Subject: [PATCH] test update --- test/pylit_ui_test.py | 4 +-- test/regexps.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 test/regexps.py diff --git a/test/pylit_ui_test.py b/test/pylit_ui_test.py index 7f7b5d6..3ffa6a0 100644 --- a/test/pylit_ui_test.py +++ b/test/pylit_ui_test.py @@ -91,7 +91,7 @@ class test_PylitOptions: """parse cmd line args""" # default should appear in options values = self.options.parse_args(txt2code=False) - print values, type(values), dir(values) + # print values, type(values), dir(values) assert values.txt2code == False # "cmd line arg should appear as option overwriting default" values = self.options.parse_args(["--txt2code"], txt2code=False) @@ -367,7 +367,7 @@ class test_Main(IOTests): def test_text_to_code_twice(self): """conversion should work a second time""" main(infile=self.txtpath, outfile=self.outpath) - main(infile=self.txtpath, outfile=self.outpath) + main(infile=self.txtpath, outfile=self.outpath, overwrite=True) output = self.get_output() print repr(output) assert output == code diff --git a/test/regexps.py b/test/regexps.py new file mode 100644 index 0000000..1585011 --- /dev/null +++ b/test/regexps.py @@ -0,0 +1,80 @@ +import re + +literal = """\ +:: + :: +t :: +text:: + indented:: + indented :: +more text :: + indented text :: +. no-directive:: +a .. directive:: somewhere:: +""" + +directive = """\ +.. code-block:: python + .. code-block:: python +.. code-block:: python listings + .. code-block:: python listings +""" + +misses = """\ +.. comment string :: +.. :: +text: +""" + +def get_regexp(marker): + class self: pass # dummy to make the definitions compatible to pylit + if marker == '::': + self.marker_regexp = re.compile('^( *(?!\.\.).*)(%s)([ \n]*)$' + % marker) + else: + # assume code_block_marker is a directive like '.. code-block::' + self.marker_regexp = re.compile('^( *)(%s)(.*\n?)$' % marker) + return self.marker_regexp + +for marker in ('::', '.. code-block::'): + print 'regexp test for %r' % marker + regexp = get_regexp(marker) + for sample in (literal + directive + misses).splitlines(True): + match = regexp.search(sample) + print '%-40r'%(sample), + if match: + print '-> ', match.groups() + # print '-> ', repr(match.group()) + else: + print '-> ', match + +options = """\ + :lineno: + :lineno: 2 + :line-no: + :line+no: + :lineno+: + :x:x: +""" + +no_options = [' :lineno:2', # no space before option arg + ':lineno:', # no leading whitespace + ' ::', # empty option + ' :lin$no:', # invalid character + ] +option_regexp = re.compile(r' +:(\w|[-._+:])+:( |$)') + +print 'regexp test for option_regexp' +for sample in (options).splitlines(True) + no_options: + match = option_regexp.search(sample) + print '%-40r'%(sample), + if match: + print '-> ', match.groups() + # print '-> ', repr(match.group()) + else: + print '-> ', match + + + + + -- 2.11.4.GIT