File: test_simple.py

package info (click to toggle)
python-friendly 0.7.21%2Bgit20230418.fe5d3a2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,268 kB
  • sloc: python: 2,291; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 978 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
28
29
30
31
32
33
import re
import friendly
import friendly_traceback
from friendly_traceback.config import session


def test_basic():
    lang = friendly.get_lang()
    friendly.set_lang("en")
    friendly.set_formatter("dark", color_system="truecolor")

    console = session.console
    with console.capture() as capture:
        try:
            a = b  # noqa
        except NameError:
            friendly_traceback.explain_traceback()
    str_output = capture.get()

    with open("tests/basic_text.out", encoding="utf8") as f:
        expected = f.read()

def normalize(text):
    text = re.sub(r'File "[^"]*test_simple\.py"', 'File "test_simple.py"', text)
    text = text.replace("╭", "┌").replace("╮", "┐")
    text = text.replace("╰", "└").replace("╯", "┘")
    text = "\n".join(line.rstrip() for line in text.splitlines())
    text = re.sub(r' +│', ' │', text)
    return text

    assert normalize(str_output) == normalize(expected)

    friendly.set_lang(lang)