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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import os
import friendly_traceback
def test_Filename_not_found():
try:
open("does_not_exist")
except FileNotFoundError as e:
message = str(e)
friendly_traceback.explain_traceback(redirect="capture")
result = friendly_traceback.get_output()
assert (
"FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist'"
in result
)
if friendly_traceback.get_lang() == "en":
assert "that cannot be found is `does_not_exist`." in result
assert "I have no additional information" in result
if friendly_traceback._writing_docs:
return result, message
def test_Filename_not_found_2():
# For documentation, cwd is tests rather than the root of the repository.
cwd = os.getcwd()
chdir = cwd.endswith("tests")
if chdir:
os.chdir("..")
try:
open("setupp.py")
except FileNotFoundError as e:
message = str(e)
friendly_traceback.explain_traceback(redirect="capture")
result = friendly_traceback.get_output()
assert (
"FileNotFoundError: [Errno 2] No such file or directory: 'setupp.py'"
in result
)
if friendly_traceback.get_lang() == "en":
assert "setupp.py" in result and "open" in result
if chdir:
os.chdir(cwd)
if friendly_traceback._writing_docs:
return result, message
def test_Filename_not_found_3():
cwd = os.getcwd()
chdir = cwd.endswith("tests")
if chdir:
os.chdir("..")
try:
open("setup.pyg")
except FileNotFoundError as e:
message = str(e)
friendly_traceback.explain_traceback(redirect="capture")
result = friendly_traceback.get_output()
assert (
"FileNotFoundError: [Errno 2] No such file or directory: 'setup.pyg'"
in result
)
if friendly_traceback.get_lang() == "en":
assert "setup.py" in result or "setup" in result
assert "pyg" in result
if chdir:
os.chdir(cwd)
if friendly_traceback._writing_docs:
return result, message
def test_Directory_not_found():
try:
open("does_not_exist/file.txt")
except FileNotFoundError as e:
message = str(e)
friendly_traceback.explain_traceback(redirect="capture")
result = friendly_traceback.get_output()
assert (
"FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist/file.txt'"
in result
)
if friendly_traceback.get_lang() == "en":
assert "is not a valid directory" in result
if friendly_traceback._writing_docs:
return result, message
if __name__ == "__main__":
print(test_Filename_not_found()[0])
|