File: test_source_missing.py

package info (click to toggle)
python-friendly-traceback 0.7.62%2Bgit20240811.d7dbff6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,264 kB
  • sloc: python: 21,500; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import friendly_traceback

def test_With_exec():
    try:
        exec("1/0")
    except ZeroDivisionError:
        friendly_traceback.explain_traceback(redirect="capture")
    result = friendly_traceback.get_output()

    if friendly_traceback.get_lang() == "en":
        assert "<string> is not a regular Python file" in result
    else:
        assert "<string>" in result


def test_With_fake_file():
    code = compile("1/0", "<fake>", "exec")
    try:
        exec(code)
    except ZeroDivisionError:
        friendly_traceback.explain_traceback(redirect="capture")
    result = friendly_traceback.get_output()

    assert "<fake>" in result
    if friendly_traceback.get_lang() == "en":
        assert "<fake> is not a regular Python file" in result
        assert "Internal error" not in result