Пример #1
0
def test_lyth_ellipsis():
    """
    Start the main function, activates the console and hopes that let statement
    does not lead to an exception.
    """
    with unittest.mock.patch.object(builtins, 'input', send_let):
        with unittest.mock.patch('sys.stdout', new_callable=StringIO):
            assert main(["test.py", "-c", "cycle=2"]) == 0
Пример #2
0
def test_idle():
    """
    Testing an idle console.
    """
    from lyth.__main__ import main
    with unittest.mock.patch.object(builtins, 'input', _delayed_interrupt):
        with unittest.mock.patch('sys.stdout', new_callable=StringIO):
            assert main([]) == 0
            assert "Goodbye.\n" in sys.stdout.getvalue()
Пример #3
0
def test_main(inputs, returns):
    """
    Start the main function, activates the console and waits
    """
    with unittest.mock.patch.object(builtins, 'input', lambda x: inputs):
        with unittest.mock.patch('sys.stdout', new_callable=StringIO):
            assert main(["test.py", "-c", "cycle=2"]) == returns
            result = sys.stdout.getvalue()
            assert "Goodbye.\n" in result
            assert "3\n" in result
Пример #4
0
def test_lyth_syntax_error(inputs, returns):
    """
    Start the main function, activates the console and waits
    """
    error = f"Invalid character at '<stdin>', line 0:\n\t1 ; 2\n\t  ^"

    with unittest.mock.patch.object(builtins, 'input', lambda x: inputs):
        with unittest.mock.patch('sys.stdout', new_callable=StringIO):
            assert main(["test.py", "-c", "cycle=2"]) == returns
            result = sys.stdout.getvalue()
            assert error in result
Пример #5
0
def test__main__():
    """
    Start the main function, activates the console and waits
    """
    from lyth.__main__ import main
    with unittest.mock.patch.object(
            builtins, 'input', lambda x:
        (_ for _ in ()).throw(KeyboardInterrupt())):
        with unittest.mock.patch('sys.stdout', new_callable=StringIO):
            assert main(["test.py", "-c", "cycle=2"]) == 0
            assert "Keyboard interrupt" in sys.stdout.getvalue()
            assert "Goodbye.\n" in sys.stdout.getvalue()
Пример #6
0
def test_exception():
    """
    Start the main function, activates the console and send ctrl-c to it
    """
    from lyth.__main__ import main
    with unittest.mock.patch.object(
            builtins, 'input', lambda x:
        (_ for _ in ()).throw(Exception("exception from test"))):
        with unittest.mock.patch('sys.stdout', new_callable=StringIO):
            with unittest.mock.patch('sys.stderr', new_callable=StringIO):
                assert main(["test.py", "-c", "cycle=2"]) == 1
                assert "Exception: exception from test" in sys.stderr.getvalue(
                )
                assert "Goodbye.\n" in sys.stdout.getvalue()
Пример #7
0
"""
Entrypoint module, in case you use `python -mlyth`.


Why does this file exist, and why __main__? For more info, read:

- https://www.python.org/dev/peps/pep-0338/
- https://docs.python.org/2/using/cmdline.html#cmdoption-m
- https://docs.python.org/3/using/cmdline.html#cmdoption-m
"""
import sys

from lyth.cli import main

if __name__ == "__main__":
    # You are outside of coverage. Do not put code here.
    sys.exit(main())