Debian Codegraph @

tests/runtime/test_file_not_found_error.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import os
2 import friendly_traceback
3
4
5 def test_Filename_not_found():
6 try:
7 open("does_not_exist")
8 except FileNotFoundError as e:
9 message = str(e)
10 friendly_traceback.explain_traceback(redirect="capture")
11 result = friendly_traceback.get_output()
12 assert (
13 "FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist'"
14 in result
15 )
16 if friendly_traceback.get_lang() == "en":
17 assert "that cannot be found is `does_not_exist`." in result
18 assert "I have no additional information" in result
19 if friendly_traceback._writing_docs:
20 return result, message
21
22
23 def test_Filename_not_found_2():
24 # For documentation, cwd is tests rather than the root of the repository.
25 cwd = os.getcwd()
26 chdir = cwd.endswith("tests")
27 if chdir:
28 os.chdir("..")
29
30 try:
31 open("setupp.py")
32 except FileNotFoundError as e:
33 message = str(e)
34 friendly_traceback.explain_traceback(redirect="capture")
35 result = friendly_traceback.get_output()
36 assert (
37 "FileNotFoundError: [Errno 2] No such file or directory: 'setupp.py'"
38 in result
39 )
40 if friendly_traceback.get_lang() == "en":
41 assert "The file `setup.py` has a similar name." in result, os.getcwd()
42 if chdir:
43 os.chdir(cwd)
44 if friendly_traceback._writing_docs:
45 return result, message
46
47
48 def test_Filename_not_found_3():
49 cwd = os.getcwd()
50 chdir = cwd.endswith("tests")
51 if chdir:
52 os.chdir("..")
53 try:
54 open("setup.pyg")
55 except FileNotFoundError as e:
56 message = str(e)
57 friendly_traceback.explain_traceback(redirect="capture")
58 result = friendly_traceback.get_output()
59 assert (
60 "FileNotFoundError: [Errno 2] No such file or directory: 'setup.pyg'"
61 in result
62 )
63 if friendly_traceback.get_lang() == "en":
64 assert "Perhaps you meant one of the following files with similar names:" in result
65 if chdir:
66 os.chdir(cwd)
67 if friendly_traceback._writing_docs:
68 return result, message
69
70
71 def test_Directory_not_found():
72 try:
73 open("does_not_exist/file.txt")
74 except FileNotFoundError as e:
75 message = str(e)
76 friendly_traceback.explain_traceback(redirect="capture")
77 result = friendly_traceback.get_output()
78 assert (
79 "FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist/file.txt'"
80 in result
81 )
82 if friendly_traceback.get_lang() == "en":
83 assert "is not a valid directory" in result
84 if friendly_traceback._writing_docs:
85 return result, message
86
87
88 if __name__ == "__main__":
89 print(test_Filename_not_found()[0])