-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Landy
committed
Nov 19, 2024
1 parent
559b943
commit 5e3a561
Showing
26 changed files
with
290 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
from traceback_with_variables import a | ||
|
||
# or just | ||
# import tb.a | ||
# if you created the tb alias | ||
|
||
# or | ||
# from traceback_with_variables import activate_by_import | ||
# if you prefer better names | ||
|
||
n = 0 | ||
1/0 | ||
|
||
|
||
|
||
|
||
|
||
"""How to install in Colab etc.""" | ||
|
||
!pip install traceback-with-variables | ||
from traceback_with_variables import activate_in_ipython_by_import | ||
# add this to use "tb" alias for the package | ||
from tracaback_with_variables import create_tb_alias | ||
create_tb_alias() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/dumps/test_tb_alias.create_and_rm_tb_alias.run_1_without_tb.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Traceback (most recent call last): | ||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in <module> | ||
import tb.a | ||
ModuleNotFoundError: No module named 'tb' |
4 changes: 4 additions & 0 deletions
4
tests/dumps/test_tb_alias.create_and_rm_tb_alias.run_2_without_tb.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Traceback (most recent call last): | ||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in <module> | ||
import tb.a | ||
ModuleNotFoundError: No module named 'tb' |
29 changes: 29 additions & 0 deletions
29
tests/dumps/test_tb_alias.create_and_rm_tb_alias.run_with_tb.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Traceback with variables (most recent call last): | ||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in <module> | ||
f() | ||
...skipped... 13 vars | ||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in f | ||
return f( | ||
n = 10001 | ||
s1 = 'short string with n: 10001' | ||
l1 = 'long string with 0..n: 0, 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, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 1...9951, 9952, 9953, 9954, 9955, 9956, 9957, 9958, 9959, 9960, 9961, 9962, 9963, 9964, 9965, 9966, 9967, 9968, 9969, 9970, 9971, 9972, 9973, 9974, 9975, 9976, 9977, 9978, 9979, 9980, 9981, 9982, 9983, 9984, 9985, 9986, 9987, 9988, 9989, 9990, 9991, 9992, 9993, 9994, 9995, 9996, 9997, 9998, 9999, 10000' | ||
us = <exception while printing> Traceback (most recent call last): | ||
File "...omitted for tests only.../core.py", line...omitted for tests only..., in _to_cropped_str | ||
raw = print_(obj) | ||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in __repr__ | ||
raise ValueError("please don't print me") | ||
ValueError: please don't print me | ||
|
||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in f | ||
return 1 // (n * 0) | ||
n = 10000 | ||
s1 = 'short string with n: 10000' | ||
l1 = 'long string with 0..n: 0, 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, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 1... 9950, 9951, 9952, 9953, 9954, 9955, 9956, 9957, 9958, 9959, 9960, 9961, 9962, 9963, 9964, 9965, 9966, 9967, 9968, 9969, 9970, 9971, 9972, 9973, 9974, 9975, 9976, 9977, 9978, 9979, 9980, 9981, 9982, 9983, 9984, 9985, 9986, 9987, 9988, 9989, 9990, 9991, 9992, 9993, 9994, 9995, 9996, 9997, 9998, 9999' | ||
us = <exception while printing> Traceback (most recent call last): | ||
File "...omitted for tests only.../core.py", line...omitted for tests only..., in _to_cropped_str | ||
raw = print_(obj) | ||
File "...omitted for tests only.../code.py", line...omitted for tests only..., in __repr__ | ||
raise ValueError("please don't print me") | ||
ValueError: please don't print me | ||
|
||
builtins.ZeroDivisionError: integer division or modulo by zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
import traceback_with_variables as twv | ||
from traceback_with_variables.module_alias import create_alias, rm_alias, module_name_to_path, Path | ||
|
||
|
||
ROOT_PATH = Path(twv.__file__).parent.parent | ||
TWV = 'traceback_with_variables' | ||
OS = 'os' | ||
ALIAS = 'alias' | ||
|
||
|
||
def test_module_name_to_path(): | ||
assert module_name_to_path(OS) == Path(os.__file__) | ||
assert module_name_to_path(TWV) == ROOT_PATH / TWV | ||
with pytest.raises(ModuleNotFoundError): | ||
module_name_to_path('nonexistant_module') | ||
|
||
|
||
def test_create_and_rm_alias(): | ||
# problems before we have the alias | ||
|
||
with pytest.raises(ValueError) as e: | ||
create_alias('', TWV) | ||
assert str(e.value) == 'the alias must be non-empty' | ||
|
||
with pytest.raises(ValueError) as e: | ||
create_alias('bad name', TWV) | ||
assert str(e.value) == 'the alias must have only ascii lowecases, digits and underscores' | ||
|
||
with pytest.raises(ModuleNotFoundError): | ||
create_alias(ALIAS, 'nonexistant_module') | ||
|
||
with pytest.raises(ValueError) as e: | ||
create_alias(OS, TWV) | ||
assert str(e.value) == 'a module with the alias name already exists' | ||
|
||
with pytest.raises(ModuleNotFoundError): | ||
rm_alias(ALIAS) | ||
|
||
with pytest.raises(ValueError) as e: | ||
rm_alias(TWV) | ||
|
||
assert str(e.value) == 'the module is not an alias' | ||
|
||
create_alias(ALIAS, TWV) | ||
|
||
# problems once we have the alias | ||
|
||
with pytest.raises(ValueError) as e: | ||
create_alias(ALIAS, TWV) | ||
assert str(e.value) == 'a module with the alias name already exists' | ||
|
||
with pytest.raises(ValueError) as e: | ||
create_alias(ALIAS, OS) | ||
assert str(e.value) == 'a module with the alias name already exists' | ||
|
||
rm_alias(ALIAS) | ||
|
||
# problems after we rm the alias | ||
|
||
with pytest.raises(ModuleNotFoundError): | ||
rm_alias(ALIAS) | ||
|
||
# rare case of garbage in the lib dir | ||
|
||
os.symlink(str(ROOT_PATH / 'nonexistant'), str(ROOT_PATH / ALIAS)) | ||
with pytest.raises(ValueError) as e: | ||
create_alias(ALIAS, TWV) | ||
assert str(e.value) == 'the needed file system location already occupied' | ||
os.remove(str(ROOT_PATH / ALIAS)) |
Oops, something went wrong.