示例#1
0
def test_main_without_file(capfd):
    with mock.patch("sys.argv", ["nudatus"]):
        with pytest.raises(SystemExit) as ex:
            nudatus.main()
            assert ex.value.code == 1
            out, err = capfd.readouterr()
            assert len(out) == 0
            assert err == "No file specified"
示例#2
0
def test_main_with_bad_script(capfd):
    with pytest.raises(SystemExit) as ex:
        with mock.patch("sys.argv", ["nudatus", "tests/bigscript_bad.py"]):
            nudatus.main()
        assert ex.value.code == 1
    out, err = capfd.readouterr()
    assert len(out) == 0
    assert len(err) > 0
    assert err.startswith("Error mangling tests/bigscript_bad.py:")
示例#3
0
def test_main_with_file_without_output_file(capfd):
    script = ""
    with open("tests/bigscript_mangled.py") as f:
        script = f.read()
    assert len(script) > 0
    with mock.patch("sys.argv", ["nudatus", "tests/bigscript.py"]):
        nudatus.main()
        out, err = capfd.readouterr()
        assert len(err) == 0
        assert out == script
示例#4
0
def test_main_with_file_without_output_file(capfd):
    script = ''
    with open('tests/bigscript_mangled.py') as f:
        script = f.read()
    assert len(script) > 0
    with mock.patch('sys.argv', ['nudatus', 'tests/bigscript.py']):
        nudatus.main()
        out, err = capfd.readouterr()
        assert len(err) == 0
        assert out == script
示例#5
0
def test_main_with_file_with_output_file(capfd):
    expected = ""
    with open("tests/bigscript_mangled.py") as f:
        expected = f.read()
    assert len(expected) > 0
    script = ""
    with open("tests/bigscript.py") as f:
        script = f.read()
    assert len(script) > 0
    with mock.patch("sys.argv",
                    ["nudatus", "tests/bigscript.py", "testout.py"]):
        m = mock.mock_open(read_data=script)
        with mock.patch.object(builtins, "open", m):
            nudatus.main()
        m.assert_called_with("testout.py", "w")
        handle = m()
        handle.write.assert_called_with(expected)
        out, err = capfd.readouterr()
        assert len(err) == 0
        assert len(out) == 0
示例#6
0
def test_main_with_file_with_output_file(capfd):
    expected = ''
    with open('tests/bigscript_mangled.py') as f:
        expected = f.read()
    assert len(expected) > 0
    script = ''
    with open('tests/bigscript.py') as f:
        script = f.read()
    assert len(script) > 0
    with mock.patch('sys.argv',
                    ['nudatus', 'tests/bigscript.py', 'testout.py']):
        m = mock.mock_open(read_data=script)
        with mock.patch.object(builtins, 'open', m):
            nudatus.main()
        m.assert_called_with('testout.py', 'w')
        handle = m()
        handle.write.assert_called_with(expected)
        out, err = capfd.readouterr()
        assert len(err) == 0
        assert len(out) == 0