Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load hook automatically only when env flag is equal to 1 #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion better_exceptions_hook.pth
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import os; exec("try:\n if 'BETTER_EXCEPTIONS' in os.environ:import better_exceptions;better_exceptions.hook()\nexcept:print('An error occured while automatically hooking better_exceptions.\\nIf you uninstalled better_exceptions, you should probably delete any \\'better_exceptions_hook.pth\\' file on your system or unset your \\'BETTER_EXCEPTIONS\\' environment variable.'); raise;")
import os; exec("try:\n if os.environ.get('BETTER_EXCEPTIONS') == '1':import better_exceptions;better_exceptions.hook()\nexcept:print('An error occured while automatically hooking better_exceptions.\\nIf you uninstalled better_exceptions, you should probably delete any \\'better_exceptions_hook.pth\\' file on your system or unset your \\'BETTER_EXCEPTIONS\\' environment variable.'); raise;")
49 changes: 49 additions & 0 deletions test/output/python-dumb-UTF-8-nocolor.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
python test/test_env.py


Traceback (most recent call last):
File "test/test_env.py", line 14, in <module>
shallow(bar, 15)
File "test/test_env.py", line 5, in shallow
deep(a + b)
File "test/test_env.py", line 10, in deep
assert val > 10 and foo == 60
AssertionError



python test/test_env.py


Traceback (most recent call last):
File "test/test_env.py", line 14, in <module>
shallow(bar, 15)
File "test/test_env.py", line 5, in shallow
deep(a + b)
File "test/test_env.py", line 10, in deep
assert val > 10 and foo == 60
AssertionError



python test/test_env.py


Traceback (most recent call last):
File "test/test_env.py", line 14, in <module>
shallow(bar, 15)
│ └ 2
└ <function shallow at 0xDEADBEEF>
File "test/test_env.py", line 5, in shallow
deep(a + b)
│ │ └ 15
│ └ 2
└ <function deep at 0xDEADBEEF>
File "test/test_env.py", line 10, in deep
assert val > 10 and foo == 60
│ └ 52
└ 17
AssertionError: assert val > 10 and foo == 60



15 changes: 15 additions & 0 deletions test/test_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
foo = 52


def shallow(a, b):
deep(a + b)


def deep(val):
global foo
assert val > 10 and foo == 60


bar = foo - 50
shallow(bar, 15)
shallow(bar, 2)
23 changes: 23 additions & 0 deletions test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ function test_case {
return $?
}

function test_env() {
echo -e "\x1b[35;1m${filename}\x1b[m" >&2
test_case "python" "test/test_env.py"
export BETTER_EXCEPTIONS=0
test_case "python" "test/test_env.py"
export BETTER_EXCEPTIONS=1
test_case "python" "test/test_env.py"
unset BETTER_EXCEPTIONS
}

function test_all {
test_case "$BETEXC_PYTHON" "test/test.py"
test_case "$BETEXC_PYTHON" "test/test_color.py"
Expand All @@ -50,6 +60,19 @@ function test_all {
fi
}

# Test env var loading. Package should be installed locally into default/active python
export LANG="en_US.UTF-8"
export LC_ALL="${LANG}"
export PYTHONCOERCECLOCALE=0
export PYTHONUTF8=0
export TERM="dumb"
export FORCE_COLOR=false
export BETEXC_PYTHON="python"
filename="test/output/python-dumb-UTF-8-nocolor.out"
test_env | diff "$(pwd)/${filename}" -



for encoding in ascii "UTF-8"; do
for term in xterm vt100 dumb; do
for color in 0 1; do
Expand Down