Skip to content

Commit

Permalink
Merge pull request #9 from besfahbod/patch-1
Browse files Browse the repository at this point in the history
pydbg.py: Use repr for actual exp value
  • Loading branch information
tylerwince authored Jan 29, 2019
2 parents c2f2495 + a7e8c45 commit f69c809
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pydbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def square(x: int) -> int:
ctx = i.code_context[0]
if "dbg" in ctx:
print(
f"[{i.filename}:{i.lineno}] {ctx[ctx.find('(') + 1 : ctx.rfind(')')]} = {exp}"
f"[{i.filename}:{i.lineno}] {ctx[ctx.find('(') + 1 : ctx.rfind(')')]} = {exp!r}"
)
break
return exp
35 changes: 24 additions & 11 deletions tests/test_pydbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,40 @@
cwd = os.getcwd()

def test_variables():
NoneType = None
boolType = True
intType = 2
floatType = 2.1
floatType = 3.4
strType = "mystring"
boolType = True
NoneType = None
strType1 = "None"
strType2 = "True"
strType3 = "2"
strType4 = "3.4"

out = io.StringIO()
with redirect_stdout(out):
dbg(NoneType)
dbg(boolType)
dbg(intType)
dbg(floatType)
dbg(strType)
dbg(boolType)
dbg(NoneType)
dbg(add(1, 2))
dbg(strType1)
dbg(strType2)
dbg(strType3)
dbg(strType4)
dbg(add(5, 6))

want = f"""[{cwd}/tests/test_pydbg.py:18] intType = 2
[{cwd}/tests/test_pydbg.py:19] floatType = 2.1
[{cwd}/tests/test_pydbg.py:20] strType = mystring
[{cwd}/tests/test_pydbg.py:21] boolType = True
want = f"""\
[{cwd}/tests/test_pydbg.py:22] NoneType = None
[{cwd}/tests/test_pydbg.py:23] add(1, 2) = 3
[{cwd}/tests/test_pydbg.py:23] boolType = True
[{cwd}/tests/test_pydbg.py:24] intType = 2
[{cwd}/tests/test_pydbg.py:25] floatType = 3.4
[{cwd}/tests/test_pydbg.py:26] strType = 'mystring'
[{cwd}/tests/test_pydbg.py:27] strType1 = 'None'
[{cwd}/tests/test_pydbg.py:28] strType2 = 'True'
[{cwd}/tests/test_pydbg.py:29] strType3 = '2'
[{cwd}/tests/test_pydbg.py:30] strType4 = '3.4'
[{cwd}/tests/test_pydbg.py:31] add(5, 6) = 11
"""

assert out.getvalue() == want
Expand Down

0 comments on commit f69c809

Please sign in to comment.