Esempio n. 1
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
Esempio n. 2
0
import os
import sys
import platform
this_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(this_dir, ".."))
import friendly

# Make it possible to find docs and tests source
docs_root_dir = os.path.abspath(
    os.path.join(this_dir, "..", "..", "friendly-traceback-docs"))
assert os.path.isdir(docs_root_dir), "Separate docs repo need to exist"

LANG = "en"
friendly.install()
friendly.set_lang(LANG)
friendly.set_formatter("docs")

sys.path.insert(0, this_dir)
py_version = f"{sys.version_info.major}.{sys.version_info.minor}"

import trb_syntax_common

target = os.path.normpath(
    os.path.join(docs_root_dir,
                 f"docs/source/syntax_tracebacks_{LANG}_{py_version}.rst"))

intro_text = """
Friendly SyntaxError tracebacks - in English
=============================================
Esempio n. 3
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)
# 3. Change the first line of this file so that the name of the rst file
#    is correct!

import os
import sys
import platform
import friendly

# Make it possible to find docs and tests source
this_dir = os.path.dirname(__file__)
docs_root_dir = os.path.abspath(
    os.path.join(this_dir, "..", "..", "friendly-traceback-docs"))
assert os.path.isdir(docs_root_dir), "Separate docs repo need to exist"

friendly.install()
friendly.set_lang("en")
friendly.set_formatter("markdown_docs")

sys.path.insert(0, this_dir)
py_version = f"{sys.version_info.major}.{sys.version_info.minor}"

import trb_common

target = os.path.normpath(
    os.path.join(docs_root_dir, "docs/source/tracebacks_markdown.md"))

intro_text = """
# Friendly tracebacks - markdown_docs format

<div class="admonition note">
<p class="admonition-title">Note</p>