Debian Codegraph @

tests/unit/test_run.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 """Tests for run(), used as a program launcher from an editor
2 """
3
4 from io import StringIO
5 import friendly_traceback
6 from contextlib import redirect_stdout
7
8 def test_run_error_en():
9 friendly_traceback.run(
10 "../name_error.py",
11 include="explain", # comprehensive
12 console=False,
13 redirect="capture",
14 )
15 result = friendly_traceback.get_output()
16 friendly_traceback.uninstall()
17 assert "The similar name `pi` was found in the local scope." in result
18
19
20 def test_run_error_fr():
21 friendly_traceback.run(
22 "../name_error.py",
23 lang="fr",
24 include="why", # more restricted than the English test
25 console=False,
26 redirect="capture",
27 )
28 result = friendly_traceback.get_output()
29 friendly_traceback.set_lang('en')
30 friendly_traceback.uninstall()
31 assert "Le nom semblable `pi` a été trouvé dans la portée locale." in result
32
33
34 def test_run_get_mod_dict():
35 """Ensure that we capture the dict of the module that was executed
36 with no exception raised.
37 """
38 file_capture = StringIO()
39 with redirect_stdout(file_capture):
40 mod_dict = friendly_traceback.run(
41 "tests/adder.py", # run from where pytest is run
42 console=False,
43 args=("1", "2.5", "3")
44 )
45 assert "total" in mod_dict
46 assert mod_dict["total"] == 6.5
47 assert "The sum is 6.5." in file_capture.getvalue()
48