Skip to content

Commit

Permalink
tests: run "ruff check --fix --unsafe-fixes tests/tools"
Browse files Browse the repository at this point in the history
Run "ruff check --fix --unsafe-fixes tests/tools" and
"ruff check --fix --unsafe-fixes tests/tools/run-tests"

Apply unsafe fixes. These are actually safe.

These are additional errors reported by ruff:

  tests/tools/compiled.py:217:9: F821 Undefined name `self`
  tests/tools/compiled.py:321:9: E722 Do not use bare `except`
  tests/tools/compiled.py:685:9: F821 Undefined name `time`
  tests/tools/compiled.py:689:9: F821 Undefined name `time`
  tests/tools/system_mode.py:61:9: E722 Do not use bare `except`
  • Loading branch information
perillo committed Mar 17, 2024
1 parent c2acdff commit 2d48999
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 59 deletions.
68 changes: 34 additions & 34 deletions tests/tools/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ def runTest(self):
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 3) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 3) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 13) == 0
assert parse_cobertura.hitsPerLine(dom, "shell-main", 26) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 26) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 30) == 5
assert parse_cobertura.hitsPerLine(dom, "shell-main", 34) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 38) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 34) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 38) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 5) == 1

assert parse_cobertura.hitsPerLine(dom, "short-test.sh", 5) == 11
assert parse_cobertura.hitsPerLine(dom, "shell-main", 128) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 132) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 132) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 135) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 136) == 1

Expand All @@ -68,7 +68,7 @@ def runTest(self):
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 3) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 3) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 4) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 22) == 1

Expand All @@ -94,11 +94,11 @@ def runTest(self):
dom = self.doTest("5")

assert parse_cobertura.hitsPerLine(dom, "shell-main", 52) == 4
assert parse_cobertura.hitsPerLine(dom, "shell-main", 53) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 55) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 53) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 55) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 59) == 1
assert parse_cobertura.hitsPerLine(dom, "shell-main", 61) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 62) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 61) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 62) is None


class bash_heredoc_special_cases_issue_44(BashBase):
Expand All @@ -122,9 +122,9 @@ def runTest(self):
class bash_coverage_tricky(BashBase):
def runTest(self):
dom = self.doTest("5")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 36) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 44) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 7) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 36) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 44) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 7) is None


class bash_honor_signal(testbase.KcovTestCase):
Expand Down Expand Up @@ -372,8 +372,8 @@ def runTest(self):
+ "/tests/bash/shell-main 5"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 163) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 169) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 163) is None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 169) is None


# Issue #154
Expand Down Expand Up @@ -456,31 +456,31 @@ def runTest(self):
+ "/tests/bash/other.sh"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/other.sh/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "other.sh", 22) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 22) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 23) == 1

assert parse_cobertura.hitsPerLine(dom, "other.sh", 26) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 27) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 28) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 26) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 27) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 28) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 29) == 1

assert parse_cobertura.hitsPerLine(dom, "other.sh", 32) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 34) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 35) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 36) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 32) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 34) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 35) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 36) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 37) == 1

assert parse_cobertura.hitsPerLine(dom, "other.sh", 40) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 42) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 40) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 42) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 43) == 1

assert parse_cobertura.hitsPerLine(dom, "other.sh", 47) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 48) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 49) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 47) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 48) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 49) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 51) == 1

# Rust stuff
assert parse_cobertura.hitsPerLine(dom, "other.sh", 54) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 54) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 55) == 1


Expand Down Expand Up @@ -538,8 +538,8 @@ def runTest(self):
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/a.sh/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "a.sh", 5) == 1
# Not included in report
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) == None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 3) == None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) is None
assert parse_cobertura.hitsPerLine(dom, "other.sh", 3) is None


class bash_can_ignore_function_with_spaces(testbase.KcovTestCase):
Expand All @@ -556,10 +556,10 @@ def runTest(self):
dom = parse_cobertura.parseFile(
testbase.outbase + "/kcov/function-with-spaces.sh/cobertura.xml"
)
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 5) == None
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 5) is None
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 6) == 1
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 9) == None
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 10) == None
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 9) is None
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 10) is None
assert parse_cobertura.hitsPerLine(dom, "function-with-spaces.sh", 11) == 1


Expand Down
2 changes: 1 addition & 1 deletion tests/tools/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def runTest(self):
dom = parse_cobertura.parseFile(
testbase.outbase + "/kcov/main-tests-debug-file/cobertura.xml"
)
assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == None
assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) is None


# Todo: Look in /usr/lib/debug as well
Expand Down
6 changes: 3 additions & 3 deletions tests/tools/compiled_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def runTest(self):
testbase.outbase + "/kcov/shared_library_test/cobertura.xml"
)
assert parse_cobertura.hitsPerLine(dom, "main.c", 9) == 1
assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) == None
assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) is None


class shared_library_filter_out(testbase.KcovTestCase):
Expand All @@ -74,7 +74,7 @@ def runTest(self):
testbase.outbase + "/kcov/shared_library_test/cobertura.xml"
)
assert parse_cobertura.hitsPerLine(dom, "main.c", 9) == 1
assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) == None
assert parse_cobertura.hitsPerLine(dom, "solib.c", 5) is None


class shared_library_accumulate(testbase.KcovTestCase):
Expand Down Expand Up @@ -120,7 +120,7 @@ def doTest(self, verify):

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main-tests/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1
assert parse_cobertura.hitsPerLine(dom, "main.cc", 14) == None
assert parse_cobertura.hitsPerLine(dom, "main.cc", 14) is None
assert parse_cobertura.hitsPerLine(dom, "main.cc", 18) >= 1
assert parse_cobertura.hitsPerLine(dom, "main.cc", 25) == 1
assert parse_cobertura.hitsPerLine(dom, "file.c", 6) >= 1
Expand Down
14 changes: 7 additions & 7 deletions tests/tools/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def runTest(self):

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) >= 1
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) == None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) is None

rv, o = self.do(
testbase.kcov
Expand All @@ -28,7 +28,7 @@ def runTest(self):
+ "/tests/bash/shell-main"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) >= 1

rv, o = self.do(
Expand All @@ -40,8 +40,8 @@ def runTest(self):
+ "/tests/bash/shell-main"
)
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) == None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) is None
assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) >= 1


Expand All @@ -60,7 +60,7 @@ def runTest(self):
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) >= 1
assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) >= 1

Expand All @@ -80,6 +80,6 @@ def runTest(self):
)

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/shell-main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) == None
assert parse_cobertura.hitsPerLine(dom, "shell-main", 29) is None
assert parse_cobertura.hitsPerLine(dom, "c.sh", 3) >= 1
assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) == None
assert parse_cobertura.hitsPerLine(dom, "b.sh", 3) is None
8 changes: 4 additions & 4 deletions tests/tools/parse_cobertura.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def hitsPerLine(dom, fileName, lineNr):
fileName = fileName.replace(".", "_").replace("-", "_")
fileTag = lookupClassName(dom, fileName)

if fileTag != None:
if fileTag is not None:
hits = lookupHitsByLine(fileTag, lineNr)
if hits != None:
if hits is not None:
return hits

return None
Expand All @@ -76,9 +76,9 @@ def hitsPerLine(dom, fileName, lineNr):
dom = parse(data)
fileTag = lookupClassName(dom, fileName)

if fileTag != None:
if fileTag is not None:
hits = lookupHitsByLine(fileTag, line)
if hits != None:
if hits is not None:
print(hits)
sys.exit(0)

Expand Down
16 changes: 8 additions & 8 deletions tests/tools/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ def doTest(self, extra):
dom = parse_cobertura.parseFile(testbase.outbase + "/kcov/main/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main", 10) == 2
assert parse_cobertura.hitsPerLine(dom, "main", 17) == 0
assert parse_cobertura.hitsPerLine(dom, "main", 22) == None
assert parse_cobertura.hitsPerLine(dom, "main", 22) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 2) == 1
assert parse_cobertura.hitsPerLine(dom, "second.py", 4) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 11) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 4) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 11) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 31) == 0
assert parse_cobertura.hitsPerLine(dom, "second.py", 38) == 1
assert parse_cobertura.hitsPerLine(dom, "second.py", 39) == 0
assert parse_cobertura.hitsPerLine(dom, "second.py", 40) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 40) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 41) == 1
assert parse_cobertura.hitsPerLine(dom, "second.py", 56) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 60) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 65) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 77) == None
assert parse_cobertura.hitsPerLine(dom, "second.py", 56) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 60) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 65) is None
assert parse_cobertura.hitsPerLine(dom, "second.py", 77) is None


class python_coverage(PythonBase):
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/system_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def runTest(self):

time.sleep(2)

assert os.path.isfile(pf) == False
assert os.path.isfile(pf) is False


class system_mode_can_instrument_binary(SystemModeBase):
Expand Down Expand Up @@ -87,5 +87,5 @@ def runTest(self):

dom = parse_cobertura.parseFile(testbase.outbase + "/kcov-report/main-tests/cobertura.xml")
assert parse_cobertura.hitsPerLine(dom, "main.cc", 9) == 1
assert parse_cobertura.hitsPerLine(dom, "main.cc", 14) == None
assert parse_cobertura.hitsPerLine(dom, "main.cc", 14) is None
assert parse_cobertura.hitsPerLine(dom, "main.cc", 18) >= 1

0 comments on commit 2d48999

Please sign in to comment.