Hi,
Background:
better-exceptions is a Python module that displays errors in a more detailed
and readable way.
It controls the length of the extra information it adds to tracebacks via the
`better_exceptions.MAX_LENGTH` variable.
By "output" I mean ***(MAYBE)*** only the parts that better-exceptions adds to
the Python interpreter's output, displayed with │ and └ characters (i.e., the
inline variable hints). Lines like file paths and the error message itself are
not considered part of better-exceptions' output and are never truncated.
For example, suppose we have a file named
`this_is_a_file_that_has_a_long_name.py`
and `better_exceptions.MAX_LENGTH` is set to 10.
Python’s standard output:
```
Traceback (most recent call last):
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 18, in <module>
shallow(bar, 15)
~~~~~~~^^^^^^^^^
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 9, in shallow
deep(a + b)
~~~~^^^^^^^
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 14, in deep
assert val > 10 and foo == 60
^^^^^^^^^^^^^^^^^^^^^^
AssertionError
```
Output with better-exceptions:
```
Traceback (most recent call last):
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 18, in <module>
shallow(bar, 15)
│ └ 2
└ <function ...
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 9, in shallow
deep(a + b)
│ │ └ 15
│ └ 2
└ <function ...
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 14, in deep
assert val > 10 and foo == 60
│ └ 52
└ 17
AssertionError: assert val > 10 and foo == 60
```
Lines such as
`File "/tmp/this_is_a_file_that_has_a_long_name.py", line 14, in deep`
which were not added by better-exceptions remain unchanged; consequently, they
are not considered part of the better-exceptions output, and their length is
not reduced.
--
The problem:
To test better-exceptions, it runs several Python programs containing errors
and uses `diff` to compare the output generated on the system where
better-exceptions is being built with the output that better-exceptions is
expected to produce.
The problem is that on some systems, the build path is very long, causing
better-exceptions to truncate it. Since the upstream developer did not account
for this in their comparison script, better-exceptions encounters an error
during the test process.
Of course, better-exceptions works correctly; the issue lies with the
comparison script.
The comparison script uses `sed` to change the build path to the default value,
ensuring a consistent path format across all systems for comparison purposes.
However, because shortening the build path appends "..." to the end, the build
script can no longer revert it to the default value.
We can fix it with fix_path_in_tests.patchimport better_exceptions
better_exceptions.MAX_LENGTH = 10
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)
diff --git a/test_all.sh b/test_all.sh
index 4ce6cb8..582b625 100755
--- a/test_all.sh
+++ b/test_all.sh
@@ -23,7 +23,7 @@ function normalize {
# since the addresses change from run to run and break diff testing
#
# we also filter a number of other version-specific, spurious output lines
- cat | sed 's|0x[a-fA-F0-9]\{1,\}|0xDEADBEEF|g' | sed 's|<module '"'[^']*' from '[^']*'>|<module 'test_module' from '/removed/for/test/purposes.py'>"'|g' | sed 's|File "/[^"]*"|File "/removed/for/test/purposes.ext"|g' | grep -v "bash: warning:" | grep -v 'now exiting BetterExceptionsConsole'
+ cat | sed 's|0x[a-fA-F0-9]\{1,\}|0xDEADBEEF|g' | sed 's|<module '"'[^']*' from '[^']*'>|<module 'test_module' from '/removed/for/test/purposes.py'>"'|g' | sed 's|<module '"'[^']*' from '[^']*\.\.\.|<module 'test_module' from '/removed/for/test/purposes.py'>"'|g' | sed 's|File "/[^"]*"|File "/removed/for/test/purposes.ext"|g' | grep -v "bash: warning:" | grep -v 'now exiting BetterExceptionsConsole'
}
function test_case {
Traceback (most recent call last):
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 16, in <module>
shallow(bar, 15)
â â 2
â <function shallow at 0x7f3c63433e20>
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 7, in shallow
deep(a + b)
â â â 15
â â 2
â <function deep at 0x7f3c63433ec0>
File "/tmp/this_is_a_file_that_has_a_long_name.py", line 12, in deep
assert val > 10 and foo == 60
â â 52
â 17
AssertionError: assert val > 10 and foo == 60