def test_tabs(): path = sample_path('doctest_tabs.txt') parser = DocTestParser(optionflags=REPORT_NDIFF|ELLIPSIS) with pytest.raises(ValueError) as excinfo: Document.parse(path, parser) assert str(excinfo.value) == ( 'tabs are not supported, first one found at line 2, column 4' )
def test_windows_line_endings(tmp_path): p = tmp_path / "example.txt" p.write_bytes(b'This is my example:\r\n\r\n' b'.. code-block:: python\r\n\r\n' b' from math import cos\r\n' b' x = 123\r\n\r\n' b'That was my example.\r\n') document = Document.parse(str(p), CodeBlockParser()) example, = document example.evaluate() assert document.namespace['x'] == 123
def test_conditional_full(): document = Document.parse(sample_path('skip-conditional.txt'), DocTestParser(), skip) document.namespace['result'] = result = [] for example in document: try: example.evaluate() except SkipTest as e: result.append('skip:' + str(e)) assert result == [ 'start', 'skip:(2 > 1)', 'good 1', 'skip:foo', 'skip:foo', 'good 2', ]
def test_conditional_edge_cases(): document = Document.parse(sample_path('skip-conditional-edges.txt'), CodeBlockParser(), DocTestParser(), skip) document.namespace['sys'] = sys document.namespace['run'] = [] skipped = [] for example in document: try: example.evaluate() except SkipTest as e: skipped.append(str(e)) assert document.namespace['run'] == [1, 2] # we should always have one and only one skip from this document. if PY3: assert skipped == ['only true on python 2'] else: assert skipped == ['only true on python 3'] * 3
def test_tabs(): path = sample_path('doctest_tabs.txt') parser = DocTestParser() with pytest.raises(ValueError): Document.parse(path, parser)
def test_basic(): document = Document.parse(sample_path('skip.txt'), CodeBlockParser(), skip) for example in document: example.evaluate() assert document.namespace['run'] == [2, 5]