Skip to content

Commit

Permalink
Merge pull request #21 from tzussman/cov-fix
Browse files Browse the repository at this point in the history
String formatting fixes
  • Loading branch information
tzussman committed May 6, 2023
2 parents 07fbbbf + 6915c8e commit 95a7468
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
18 changes: 2 additions & 16 deletions valparse/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ def test_Parser():

filename = Path(__file__).resolve().parent / 'data/bad-test.xml'

try:
valfile = Parser(filename)
except FileNotFoundError:
print(f"File '{filename}' not found. The tested executable might have failed...", "red")
exit(1)
except Exception as e:
print(f"Exception raised: {e}. The tested executable might have failed...", "red")
exit(1)
valfile = Parser(filename)

assert valfile.args.valexe == "/usr/bin/valgrind.bin"
assert valfile.args.valargs == [
Expand Down Expand Up @@ -122,14 +115,7 @@ def test_suppression_dump():

filename = Path(__file__).resolve().parent / 'data/bad-test.xml'

try:
valfile = Parser(filename)
except FileNotFoundError:
print(f"File '{filename}' not found. The tested executable might have failed...", "red")
exit(1)
except Exception as e:
print(f"Exception raised: {e}. The tested executable might have failed...", "red")
exit(1)
valfile = Parser(filename)

assert valfile.hasErrors() is True
assert valfile.hasLeaks() is False
Expand Down
25 changes: 16 additions & 9 deletions valparse/tests/test_vgerror.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_ValgrindError_error():
fn="main",
dir="/home/valparse/examples/",
file="invalid_read.c",
line="50",
line=50,
),
],
)
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_ValgrindError_leak():
fn="main",
dir="/home/valparse/examples/",
file="fake_file.c",
line="50",
line=50,
),
],
)
Expand Down Expand Up @@ -114,13 +114,13 @@ def test_Status():
def test_SFrame():
"""Create an instance of a SFrame and check its fields."""
sframe = valparse.SFrame(
obj="0x4",
obj="test",
fun="main",
)

assert sframe.obj == "0x4"
assert sframe.obj == "test"
assert sframe.fun == "main"
assert str(sframe) == " Object: 0x4\n Function: main\n"
assert str(sframe) == " Object: test\n Function: main\n"


def test_FatalSignal():
Expand All @@ -138,9 +138,10 @@ def test_FatalSignal():
fn="main",
dir="/home/valparse/examples/",
file="invalid_read.c",
line="50",
line=50,
),
],
threadname="test_thread",
)

assert sig.tid == 5
Expand All @@ -149,6 +150,7 @@ def test_FatalSignal():
assert sig.sicode == 1
assert sig.siaddr == "0x0"
assert len(sig.stack) == 1
assert sig.threadname == "test_thread"

assert sig.get_signal() == signal.SIGSEGV
sig_str = '''Thread ID: 5
Expand All @@ -163,6 +165,7 @@ def test_FatalSignal():
Directory: /home/valparse/examples/
File: invalid_read.c
Line: 50
Thread name: test_thread
'''

assert str(sig) == sig_str
Expand All @@ -176,15 +179,15 @@ def test_Frame():
fn="main",
dir="/home/valparse/examples/",
file="invalid_read.c",
line="50",
line=50,
)

assert frame.ip == "0x108706"
assert frame.obj == "/home/valparse/examples/invalid_read"
assert frame.fn == "main"
assert frame.dir == "/home/valparse/examples/"
assert frame.file == "invalid_read.c"
assert frame.line == "50"
assert frame.line == 50

frame_str = ''' Instruction Pointer: 0x108706
Object: /home/valparse/examples/invalid_read
Expand Down Expand Up @@ -218,16 +221,20 @@ def test_Suppression():
supp = valparse.Suppression(
name="test_supp",
kind="Memcheck:Value8",
stack=[valparse.SFrame(fun="main")],
stack=[valparse.SFrame(fun="main", obj="test")],
auxkind="Test suppression",
)

assert supp.name == "test_supp"
assert supp.kind == "Memcheck:Value8"
assert len(supp.stack) == 1
assert supp.auxkind == "Test suppression"

supp_str = '''Suppression kind: Memcheck:Value8
Stack frame:
Object: test
Function: main
Aux kind: Test suppression
'''

assert str(supp) == supp_str
2 changes: 1 addition & 1 deletion valparse/valparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def value(val):
result += f"Stack frame:\n{sframe.__str__()}"

if self.auxkind is not None:
result = "Aux kind" + value(self.auxkind)
result += "Aux kind" + value(self.auxkind)

return result

Expand Down

0 comments on commit 95a7468

Please sign in to comment.