Skip to content

Commit

Permalink
Merge pull request #53 from alexmojaki/ZoeDong/master
Browse files Browse the repository at this point in the history
Test fixes for pygments and typeguard
  • Loading branch information
alexmojaki authored Sep 30, 2023
2 parents df3566c + c86ff98 commit 140ba64
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 47 deletions.
11 changes: 6 additions & 5 deletions stack_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ def is_frame(frame_or_tb: Union[FrameType, TracebackType]) -> bool:


def iter_stack(frame_or_tb: Union[FrameType, TracebackType]) -> Iterator[Union[FrameType, TracebackType]]:
while frame_or_tb:
yield frame_or_tb
if is_frame(frame_or_tb):
frame_or_tb = frame_or_tb.f_back
current: Union[FrameType, TracebackType, None] = frame_or_tb
while current:
yield current
if is_frame(current):
current = current.f_back
else:
frame_or_tb = frame_or_tb.tb_next
current = current.tb_next


def frame_and_lineno(frame_or_tb: Union[FrameType, TracebackType]) -> Tuple[FrameType, int]:
Expand Down
5 changes: 4 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

import pyximport
from typeguard.importhook import install_import_hook
try:
from typeguard import install_import_hook
except ImportError:
from typeguard.importhook import install_import_hook

pyximport.install(language_level=3)

Expand Down
36 changes: 18 additions & 18 deletions tests/golden_files/pygmented.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Traceback (most recent call last):
File "formatter_example.py", line 21, in foo
9 | x = 1
10 | lst = (
9 | x = 1
10 | lst = (
11 |  [
12 |  x,
(...)
18 |  + []
18 |  + []
19 | )
20 | try:
--> 21 |  return int(str(lst))
Expand All @@ -19,7 +19,7 @@ Traceback (most recent call last):
21 |  return int(str(lst))
22 | except:
23 |  try:
--> 24 |  return 1 / 0
--> 24 |  return 1 / 0
25 |  except Exception as e:
ZeroDivisionError: division by zero

Expand All @@ -31,24 +31,24 @@ Traceback (most recent call last):
--> 30 |  exec("foo()")
File "<string>", line 1, in <module>
File "formatter_example.py", line 8, in foo
6 | def foo(n=5):
7 |  if n > 0:
--> 8 |  return foo(n - 1)
9 |  x = 1
6 | def foo(n=5):
7 |  if n > 0:
--> 8 |  return foo(n - 1)
9 |  x = 1
File "formatter_example.py", line 8, in foo
6 | def foo(n=5):
7 |  if n > 0:
--> 8 |  return foo(n - 1)
9 |  x = 1
6 | def foo(n=5):
7 |  if n > 0:
--> 8 |  return foo(n - 1)
9 |  x = 1
[... skipping similar frames: foo at line 8 (2 times)]
File "formatter_example.py", line 8, in foo
6 | def foo(n=5):
7 |  if n > 0:
--> 8 |  return foo(n - 1)
9 |  x = 1
6 | def foo(n=5):
7 |  if n > 0:
--> 8 |  return foo(n - 1)
9 |  x = 1
File "formatter_example.py", line 26, in foo
23 | try:
24 |  return 1 / 0
24 |  return 1 / 0
25 | except Exception as e:
--> 26 |  raise TypeError from e
--> 26 |  raise TypeError from e
TypeError
Loading

0 comments on commit 140ba64

Please sign in to comment.