Skip to content

Commit f62fcaf

Browse files
committed
[test] catch RecursionError on higher python versions
1 parent b1e1480 commit f62fcaf

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

coverage_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ rm -rf coverage/{c,python}
1111

1212
# Coverage should be measured with extension compiled for both Python 2 & 3 (e.g. via separate venv)
1313
export CFLAGS="-coverage"
14-
python3 setup.py build_ext -i
15-
python3 -mcoverage run --branch --omit=bjdata/compat.py -m unittest discover test/ -vf
16-
python3 -mcoverage html -d coverage/python
14+
python setup.py build_ext -i
15+
python -mcoverage run --branch --omit=bjdata/compat.py -m unittest discover test/ -vf
16+
python -mcoverage html -d coverage/python
1717
lcov --capture --directory . --output-file /tmp/bjdata-coverage.info.pre
1818
# Only consider own source files. (Unfortunately extract/remove commands seem incapable of reading from stdin)
1919
lcov --extract /tmp/bjdata-coverage.info.pre "$(pwd)/src/*" --output-file /tmp/bjdata-coverage.info.pre2

test/perf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535

3636
class LibWrapper(object):
37-
3837
__metaclass__ = ABCMeta
3938

4039
@staticmethod

test/test.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,9 @@ def test_decoder_fuzz(self):
946946
self.bjdloadb(pack(fmt, i))
947947
except DecoderException:
948948
pass
949-
except Exception as ex: # pragma: no cover pylint: disable=broad-except
949+
except (
950+
Exception
951+
) as ex: # pragma: no cover pylint: disable=broad-except
950952
self.fail("Unexpected failure: %s" % ex)
951953

952954
def assert_raises_regex(self, *args, **kwargs):
@@ -958,18 +960,25 @@ def assert_raises_regex(self, *args, **kwargs):
958960
def test_recursion(self):
959961
old_limit = getrecursionlimit()
960962
setrecursionlimit(200)
963+
if version_info >= (3, 5):
964+
# Python 3.5+ has RecursionError
965+
recursion_exceptions = (RuntimeError, RecursionError)
966+
else:
967+
# Python 2.7 and early Python 3.x only have RuntimeError
968+
recursion_exceptions = (RuntimeError,)
969+
961970
try:
962971
obj = current = []
963-
# Increase the multiplier for Python 3.12+
964-
multiplier = 4 if version_info >= (3, 12) else 2
965-
for _ in range(getrecursionlimit() * multiplier):
972+
for _ in range(getrecursionlimit() * 2):
966973
new_list = []
967974
current.append(new_list)
968975
current = new_list
969-
with self.assert_raises_regex(RuntimeError, "recursion"):
976+
977+
with self.assert_raises_regex(recursion_exceptions, "recursion"):
970978
self.bjddumpb(obj)
971-
raw = ARRAY_START * (getrecursionlimit() * multiplier)
972-
with self.assert_raises_regex(RuntimeError, "recursion"):
979+
980+
raw = ARRAY_START * (getrecursionlimit() * 2)
981+
with self.assert_raises_regex(recursion_exceptions, "recursion"):
973982
self.bjdloadb(raw)
974983
finally:
975984
setrecursionlimit(old_limit)

0 commit comments

Comments
 (0)