Ejemplo n.º 1
0
def test_run_error_en():
    friendly.run(
        "../name_error.py",
        include="explain",  # comprehensive
        console=False,
        redirect="capture",
    )
    result = friendly.get_output()
    friendly.uninstall()
    assert "The similar name `pi` was found in the local scope." in result
Ejemplo n.º 2
0
def test_run_error_fr():
    friendly.run(
        "../name_error.py",
        lang="fr",
        include="why",  # more restricted than the English test
        console=False,
        redirect="capture",
    )
    result = friendly.get_output()
    friendly.set_lang('en')
    friendly.uninstall()
    assert "Le nom semblable `pi` a été trouvé dans la portée locale." in result
Ejemplo n.º 3
0
def test_uncleaned_traceback():
    """Assert this test filename appear in tracebacks if we don't exclude
    it.
    """
    ft.install(redirect="capture")

    try:
        from . import raise_exception
    except ValueError:
        ft.explain_traceback()

    output = ft.get_output()
    assert "test_clean_traceback" in output
    assert "André" in output

    # cleanup for other tests
    ft.uninstall()
Ejemplo n.º 4
0
def test_cleaned_traceback():
    """Assert this test filename does not appear in tracebacks if we
    exclude it.
    """
    ft.install(redirect="capture")
    ft.exclude_file_from_traceback(__file__)

    try:
        from . import raise_exception
    except ValueError:
        ft.explain_traceback()

    output = ft.get_output()
    assert "test_clean_traceback" not in output
    assert "André" in output

    # cleanup for other tests
    ft.path_info.include_file_in_traceback(__file__)
    ft.uninstall()
Ejemplo n.º 5
0
def test_uncleaned_traceback():
    """Assert this test filename appear in tracebacks if we don't exclude
    it.
    """
    friendly.install(redirect="capture")
    old_debug = friendly.debug_helper.DEBUG
    friendly.debug_helper.DEBUG = False

    try:
        from . import raise_exception
    except ValueError:
        friendly.explain_traceback()

    output = friendly.get_output()
    assert "test_clean_traceback" in output
    assert "André" in output

    # cleanup for other tests
    friendly.uninstall()
    friendly.debug_helper.DEBUG = old_debug
Ejemplo n.º 6
0
def test_exec_code():
    # set-up
    bad_code_syntax = "True = 1"
    bad_code_exec = "a = b"  # Not a syntax error, but a NameError
    good_code = "c = 1"

    ft.set_stream("capture")
    original_include = ft.get_include()
    installed = ft.is_installed()
    # ----- end of set-up

    # When a SyntaxError is raised, exec_code returns False

    assert not ft.editors_helpers.exec_code(source=bad_code_syntax)
    result = ft.get_output()  # content is flushed
    assert "SyntaxError" in result

    assert not ft.get_output()  # confirm that content was flushed

    ft.editors_helpers.exec_code(source=bad_code_exec)
    result = ft.get_output()
    assert "NameError" in result

    assert ft.editors_helpers.exec_code(source=good_code)
    assert not ft.get_output()  # no new exceptions recorded

    try:
        exec(bad_code_syntax, {})
    except Exception:
        assert not ft.get_output()

    # Ensure that a call to exec_code only install() temporarily
    # if it was not installed before.
    ft.uninstall()
    ft.editors_helpers.exec_code(source=bad_code_syntax)
    assert not ft.is_installed()
    ft.editors_helpers.exec_code(source=bad_code_syntax, include="no_tb")
    assert not ft.is_installed()

    # When friendly is "installed", a call to exec_code
    # leaves its include unchanged.
    ft.install(redirect="capture")

    ft.set_include("friendly_tb")
    ft.editors_helpers.exec_code(source=bad_code_syntax)
    assert ft.get_include() == "friendly_tb"
    ft.editors_helpers.exec_code(source=bad_code_syntax, include="no_tb")
    assert ft.get_include() == "friendly_tb"

    # A call to exec_code, with a language specified as an argument
    # should leave the previous language unchanged.

    ft.set_lang("en")
    ft.editors_helpers.exec_code(source=bad_code_exec,
                                 lang="fr",
                                 include="explain")
    result = ft.get_output()
    assert "Une exception `NameError` indique" in result
    assert ft.get_lang() == "en"

    # Clean up and restore for other tests
    ft.get_output()
    ft.set_stream(None)
    if installed:
        ft.uninstall()
    ft.set_include(original_include)