Debian Codegraph @

tests/unit/test_run.py

raw symbols ◀ ▶ SCIP
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 "semblable `pi`" in result or "similar name `pi`" in result
32 # assert "Le nom semblable `pi` a été trouvé dans la portée locale." in result
33
34
35 def test_run_get_mod_dict():
36 """Ensure that we capture the dict of the module that was executed
37 with no exception raised.
38 """
39 file_capture = StringIO()
40 with redirect_stdout(file_capture):
41 mod_dict = friendly_traceback.run(
42 "tests/adder.py", # run from where pytest is run
43 console=False,
44 args=("1", "2.5", "3")
45 )
46 assert "total" in mod_dict
47 assert mod_dict["total"] == 6.5
48 assert "The sum is 6.5." in file_capture.getvalue()
49