コード例 #1
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def test_input_types():
    code = _read_reprex_file('tests/reprexes/txt-outputs.py')
    out_str = reprex(code=code)

    out_infile = reprex(code_file='tests/reprexes/txt-outputs.py')

    pyperclip.copy(code)
    out_clipboard = reprex()

    assert out_str == out_infile == out_clipboard
コード例 #2
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def test_si_non_imports():
    code = _read_reprex_file('tests/reprexes/non-imports.py')
    out = reprex(code, si=True)
    non_imports = ['pickledb', 'matplotlib', 'ipython']
    for distribution in non_imports:
        distribution_regex = distribution + '=='
        assert not re.search(distribution_regex, out)
コード例 #3
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def test_si_imports():
    code = _read_reprex_file('tests/reprexes/imports.py')
    out = reprex(code, si=True)
    imports = [
        'nbconvert', 'asttokens', 'pyimgur', 'stdlib-list', 'ipython', 'pyzmq'
    ]
    for distribution in imports:
        distribution_regex = distribution + '=='
        assert re.search(distribution_regex, out)
コード例 #4
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def test_misc_params():
    raw_code = """
    var = 'some var'
    var
    """
    code = textwrap.dedent(raw_code).strip('\n')
    out = reprex(code, venue='so', comment='#<>', advertise=True)
    regex = ('    var = \'some var\''
             '.*#<>'
             '.*Created on.*by the \\[reprexpy package\\]')
    assert re.search(regex, out, flags=re.DOTALL)
コード例 #5
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def test_output_to_clipboard():
    code = 'print("hi there")'
    expected_output = '```python\nprint("hi there")\n#> hi there\n```'
    reprex(code)
    assert pyperclip.paste() == expected_output
コード例 #6
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def test_exception_handling():
    out = reprex('10 / 0')
    assert re.search('ZeroDivisionError', out)
コード例 #7
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def _count_mismatching_lines(file_name, *args, **kargs):
    src, expected_output = _read_reprex_file_pair(file_name)
    out = reprex(src, *args, **kargs)
    out_lines = out.splitlines()
    expected_lines = expected_output.splitlines()
    return sum([i != j for i, j in zip(out_lines, expected_lines)])
コード例 #8
0
ファイル: test_reprexpy.py プロジェクト: crew102/reprexpy
def _assert_reprex_exact_match(file_name, *args, **kargs):
    src, expected_output = _read_reprex_file_pair(file_name)
    out = reprex(src, *args, **kargs)
    assert out == expected_output