Ejemplo n.º 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"
Ejemplo n.º 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:")
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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