| 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 |
|
| 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 "setupp.py" in result and "open" in result |
| 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 "setup.py" in result or "setup" in result |
| 65 |
assert "pyg" in result |
| 66 |
if chdir: |
| 67 |
os.chdir(cwd) |
| 68 |
if friendly_traceback._writing_docs: |
| 69 |
return result, message |
| 70 |
|
| 71 |
|
| 72 |
def test_Directory_not_found(): |
| 73 |
try: |
| 74 |
open("does_not_exist/file.txt") |
| 75 |
except FileNotFoundError as e: |
| 76 |
message = str(e) |
| 77 |
friendly_traceback.explain_traceback(redirect="capture") |
| 78 |
result = friendly_traceback.get_output() |
| 79 |
assert ( |
| 80 |
"FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist/file.txt'" |
| 81 |
in result |
| 82 |
) |
| 83 |
if friendly_traceback.get_lang() == "en": |
| 84 |
assert "is not a valid directory" in result |
| 85 |
if friendly_traceback._writing_docs: |
| 86 |
return result, message |
| 87 |
|
| 88 |
|
| 89 |
if __name__ == "__main__": |
| 90 |
print(test_Filename_not_found()[0]) |