File: test_formatter.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 (46 lines) | stat: -rw-r--r-- 1,186 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
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Tests of custom formatter.
"""

# test_example.py

import os
import subprocess
import sys

import pytest

def run(lang):
    proc = subprocess.run(
        [
            sys.executable,
            "-m",
            "friendly_traceback",
            "--formatter",
            "tests.fake_formatter.get_cause",
            "tests/name_error.py",
            "--lang",
            lang,
        ],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=True,
        check=False,
    )
    return proc.stderr


def test_formatter_en():
    result = run('en')
    assert "The similar name `pi` was found in the local scope." in result

# The following does not work on Github when running with windows.
# import os
# IN_GITHUB_ACTIONS = bool(os.getenv("GITHUB_ACTIONS"))
# @pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work reliably in Github Actions.")
#
# I am thus the only one to run this test.

@pytest.mark.skipif("Andre" not in __file__, reason="Test does not work reliably in Github Actions.")
def test_formatter_fr():
    result = run('fr')
    assert "Le nom semblable `pi` a été trouvé dans la portée locale." in result