コード例 #1
0
ファイル: conftest.py プロジェクト: shalevy1/DataFS
def validator():

    tester = Runner()
    tester.call_engines['echo'] = SubprocessValidator()
    tester.call_engines['cat'] = SubprocessValidator()
    tester.call_engines['python'] = SubprocessValidator()

    yield tester
コード例 #2
0
def test_parser_1():

    tester = Runner()

    test = r'''
    .. code-block:: bash

        $ echo "my string"
        ['echo', 'my string']

    '''

    next(tester._parse_cli_statement(test))
    (['echo', 'my string'], "['echo', 'my string']", {})
コード例 #3
0
def test_validator():

    teststr = r'''

    .. code-block:: bash

        $ hello Polly
        Hello Polly!

        $ echo 'Pining for the fjords' # doctest: +NORMALIZE_WHITESPACE
        Pining for the fjords

    Pipes don't work, so we can't redirect this value into a file. But we can
    write a file with python:

    .. code-block:: bash

        $ python -c \
        >     "with open('tmp.txt', 'w+') as f: f.write('Pushing up daisies')"

        $ cat tmp.txt
        Pushing up daisies

    '''

    tester = Runner()
    tester.call_engines['hello'] = ClickValidator(hello)
    tester.call_engines['echo'] = SubprocessValidator()
    tester.call_engines['python'] = SubprocessValidator()
    tester.call_engines['cat'] = SubprocessValidator()

    tester.teststring(teststr)

    badstr = '''

    The following block of code should cause an error:

    .. code-block:: bash

        $ rm tmp.txt

    '''

    with pytest.raises(ValueError):
        tester.teststring(badstr)

    os.remove('tmp.txt')
コード例 #4
0
def test_bad_command():

    badstr = '''

    .. code-block:: bash

        $ badcmd Polly # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        ValueError: This command doesn't work!

    '''

    tester = Runner()
    tester.call_engines['badcmd'] = ClickValidator(badcmd)

    tester.teststring(badstr)
コード例 #5
0
def test_skip():

    teststr = r'''

    Of course, you can always skip them!

    .. code-block:: bash

        $ echo "There, it moved!" # doctest: +SKIP
        "No it didn't!"

    '''

    tester = Runner()
    tester.call_engines['echo'] = SubprocessValidator()

    tester.teststring(teststr)
コード例 #6
0
def test_skipper():

    skipstr = '''

    The following command will be skipped:

    .. code-block:: bash

        $ aws storage buckets list

    '''

    tester = Runner()
    tester.call_engines['aws'] = SkipValidator()

    tester.teststring(skipstr)

    noskip = '''

    Unrecognized commands will raise an error, even if +SKIP is specified

    .. code-block:: bash

        $ nmake all # doctest: +SKIP
        $ echo 'I made it!'
        I made it!

    '''

    tester.teststring(noskip)
コード例 #7
0
def test_string_failure():

    teststr = r'''

    Lines failing to match the command's output will raise an error

    .. code-block:: bash

        $ echo "There, it moved!"
        "No it didn't!"

    '''

    tester = Runner()
    tester.call_engines['echo'] = SubprocessValidator()

    with pytest.raises(ValueError):
        tester.teststring(teststr)
コード例 #8
0
def testfile():

    tester = Runner()
    tester.call_engines['echo'] = SubprocessValidator()
    tester.call_engines['python'] = SubprocessValidator()
    tester.call_engines['cat'] = SubprocessValidator()

    tester.testfile('tests/resources/sample_doc.txt')
コード例 #9
0
def test_parser_2():

    tester = Runner()

    test = r'''

    This is the first block. It has an error.

    .. code-block:: bash

        $ pytest test_nonexistant.py --cov=mymodule \
        >     --cov=docs --doctest-modules \
        >     --cov-report term-missing \
        >     # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        ERROR: file not found: test_nonexistant.py

        $ pytest test_real.py --cov=mymodule \
        >     --cov=docs --doctest-modules \
        >     --cov-report term-missing # doctest: +SKIP

    '''

    parser = tester._parse_cli_statement(test)

    expected = ([
        'pytest', 'test_nonexistant.py', '--cov=mymodule', '--cov=docs',
        '--doctest-modules', '--cov-report', 'term-missing'
    ], ('Traceback (most recent call last):'
        '\n...\n'
        'ERROR: file not found: test_nonexistant.py\n'), 8)

    assert next(parser) == expected

    assert next(parser) == ([
        'pytest', 'test_real.py', '--cov=mymodule', '--cov=docs',
        '--doctest-modules', '--cov-report', 'term-missing'
    ], '', 16)
コード例 #10
0
def test_string_command():

    teststr = '''

    .. code-block:: bash

        $ hello Polly
        Hello Polly!

        $ hello Polly Parrot
        Usage: hello [OPTIONS] NAME
        <BLANKLINE>
        Error: Got unexpected extra argument (Parrot)

        $ hello 'Polly Parrot'
        Hello Polly Parrot!

    '''

    tester = Runner()
    tester.call_engines['hello'] = ClickValidator(hello)

    tester.teststring(teststr)