예제 #1
0
def _test(input, output, args=''):
    with tempfile.NamedTemporaryFile('w', delete=False) as finput:
        finput.write(input)
        finput.seek(0)

        with tempfile.NamedTemporaryFile('w+', delete=False) as foutput:
            opts = '{} -o {} {}'.format(finput.name, foutput.name, args)
            main(shlex.split(opts))
            assert foutput.read() == output + '\n'
예제 #2
0
def _test(input, expected_output, args=''):
    with tempfile.NamedTemporaryFile('w', delete=False) as finput:
        finput.write(input)
        finput.seek(0)

        with tempfile.NamedTemporaryFile('w+', delete=False) as foutput:
            opts = '{} -o {} {}'.format(finput.name, foutput.name, args)
            main.main(shlex.split(opts))
            output = foutput.read()
            try:  # python2 needs additional utf8 decoding
                output = output.decode('utf8')
            except AttributeError:  # python3 is OK
                pass
            assert output == expected_output + '\n'
예제 #3
0
def _test(input, expected_output, args=''):
    with tempfile.NamedTemporaryFile('w') as finput:
        # python2 needs additional utf8 encoding
        if sys.version_info[0] == 2:
            input = input.encode('utf8')
        finput.write(input)
        finput.seek(0)

        with tempfile.NamedTemporaryFile('w+') as foutput:
            opts = '{} -o {} {}'.format(finput.name, foutput.name, args)
            sys.argv = ['foo'] + shlex.split(opts)
            main.main()

            output = foutput.read()
            if expected_output == '':
                assert output == ''
            else:
                assert output == expected_output + '\n'
예제 #4
0
def _test(input, expected_output, args=''):
    with tempfile.NamedTemporaryFile('w') as finput:
        # python2 needs additional utf8 encoding
        if sys.version_info[0] == 2:
            input = input.encode('utf8')
        finput.write(input)
        finput.seek(0)

        with tempfile.NamedTemporaryFile('w+') as foutput:
            opts = '{} -o {} {}'.format(finput.name, foutput.name, args)
            sys.argv = ['foo'] + shlex.split(opts)
            main.main()

            output = foutput.read()
            # python2 needs additional utf8 decoding
            if sys.version_info[0] == 2:
                output = output.decode('utf8')
            assert output == expected_output + '\n'
예제 #5
0
def _test(text, expected_output, args=''):
    with tempfile.TemporaryDirectory() as tmpdir:
        input_file = pathlib.Path(tmpdir) / 'input.txt'
        output_file = pathlib.Path(tmpdir) / 'output.txt'
        with open(input_file, 'wb') as finput:
            finput.write(text.encode('utf8'))

        sys.argv = ['unused', f'{input_file}', '-o', f'{output_file}']
        if args:
            sys.argv += shlex.split(args)
        main.main()

        with open(output_file, 'rb') as foutput:
            output = foutput.read().decode()

        # silly fix for windows
        assert output.replace('\r', '').strip(os.linesep) \
            == expected_output.replace('\r', '')
예제 #6
0
def test_list_languages():
    sys.argv = ['foo', '--list-languages']
    main.main()
예제 #7
0
def test_version():
    sys.argv = ['foo', '--version']
    main.main()
예제 #8
0
def test_help():
    sys.argv = ['foo', '-h']
    with pytest.raises(SystemExit):
        main.main()
예제 #9
0
def test_help():
    with pytest.raises(SystemExit):
        main.main('-h'.split())
예제 #10
0
def test_version():
    sys.argv = ['foo', '--version']
    main.main()
예제 #11
0
def test_help():
    sys.argv = ['foo', '-h']
    with pytest.raises(SystemExit):
        main.main()