Skip to content

Commit 9fcf423

Browse files
authored
Ruff: Final fix of PTH123 (#12177)
1 parent b018feb commit 9fcf423

File tree

193 files changed

+1079
-1084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+1079
-1084
lines changed

ruff.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ preview = true
114114
"S105", # hardcoded passwords in tests are fine
115115
"S108", # tmp paths mentioned in tests are fine
116116
]
117-
"unittests/tools/**" = [
118-
"PTH123", # Fix is needed in unittests/tools as well but there are too many problematic files, let's do it per partes
119-
]
120117
".github/pr-reminder.py" = [
121118
"INP001", # https://docs.astral.sh/ruff/rules/implicit-namespace-package/
122119
]

unittests/tools/test_acunetix_parser.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class TestAcunetixParser(DojoTestCase):
1010

1111
def test_parse_file_with_one_finding(self):
12-
with open(get_unit_tests_scans_path("acunetix") / "one_finding.xml", encoding="utf-8") as testfile:
12+
with (get_unit_tests_scans_path("acunetix") / "one_finding.xml").open(encoding="utf-8") as testfile:
1313
parser = AcunetixParser()
1414
findings = parser.get_findings(testfile, Test())
1515
for finding in findings:
@@ -37,7 +37,7 @@ def test_parse_file_with_one_finding(self):
3737
self.assertEqual("some/path", endpoint.path)
3838

3939
def test_parse_file_with_multiple_finding(self):
40-
with open(get_unit_tests_scans_path("acunetix") / "many_findings.xml", encoding="utf-8") as testfile:
40+
with (get_unit_tests_scans_path("acunetix") / "many_findings.xml").open(encoding="utf-8") as testfile:
4141
parser = AcunetixParser()
4242
findings = parser.get_findings(testfile, Test())
4343
for finding in findings:
@@ -132,7 +132,7 @@ def test_parse_file_with_multiple_finding(self):
132132
self.assertIsInstance(req_resp["resp"], str)
133133

134134
def test_parse_file_with_example_com(self):
135-
with open(get_unit_tests_scans_path("acunetix") / "XML_http_example_co_id_.xml", encoding="utf-8") as testfile:
135+
with (get_unit_tests_scans_path("acunetix") / "XML_http_example_co_id_.xml").open(encoding="utf-8") as testfile:
136136
parser = AcunetixParser()
137137
findings = parser.get_findings(testfile, Test())
138138
for finding in findings:
@@ -204,7 +204,7 @@ def test_parse_file_with_example_com(self):
204204
self.assertIsInstance(req_resp["resp"], str)
205205

206206
def test_parse_file_with_one_finding_acunetix360(self):
207-
with open(get_unit_tests_scans_path("acunetix") / "acunetix360_one_finding.json", encoding="utf-8") as testfile:
207+
with (get_unit_tests_scans_path("acunetix") / "acunetix360_one_finding.json").open(encoding="utf-8") as testfile:
208208
parser = AcunetixParser()
209209
findings = parser.get_findings(testfile, Test())
210210
self.assertEqual(1, len(findings))
@@ -225,7 +225,7 @@ def test_parse_file_with_one_finding_acunetix360(self):
225225
self.assertIn("https://online.acunetix360.com/issues/detail/735f4503-e9eb-4b4c-4306-ad49020a4c4b", finding.references)
226226

227227
def test_parse_file_with_one_finding_false_positive(self):
228-
with open(get_unit_tests_scans_path("acunetix") / "acunetix360_one_finding_false_positive.json", encoding="utf-8") as testfile:
228+
with (get_unit_tests_scans_path("acunetix") / "acunetix360_one_finding_false_positive.json").open(encoding="utf-8") as testfile:
229229
parser = AcunetixParser()
230230
findings = parser.get_findings(testfile, Test())
231231
self.assertEqual(1, len(findings))
@@ -245,7 +245,7 @@ def test_parse_file_with_one_finding_false_positive(self):
245245
self.assertTrue(finding.false_p)
246246

247247
def test_parse_file_with_one_finding_risk_accepted(self):
248-
with open(get_unit_tests_scans_path("acunetix") / "acunetix360_one_finding_accepted_risk.json", encoding="utf-8") as testfile:
248+
with (get_unit_tests_scans_path("acunetix") / "acunetix360_one_finding_accepted_risk.json").open(encoding="utf-8") as testfile:
249249
parser = AcunetixParser()
250250
findings = parser.get_findings(testfile, Test())
251251
self.assertEqual(1, len(findings))
@@ -265,7 +265,7 @@ def test_parse_file_with_one_finding_risk_accepted(self):
265265
self.assertTrue(finding.risk_accepted)
266266

267267
def test_parse_file_with_multiple_finding_acunetix360(self):
268-
with open(get_unit_tests_scans_path("acunetix") / "acunetix360_many_findings.json", encoding="utf-8") as testfile:
268+
with (get_unit_tests_scans_path("acunetix") / "acunetix360_many_findings.json").open(encoding="utf-8") as testfile:
269269
parser = AcunetixParser()
270270
findings = parser.get_findings(testfile, Test())
271271
self.assertEqual(16, len(findings))
@@ -306,7 +306,7 @@ def test_parse_file_with_multiple_finding_acunetix360(self):
306306
self.assertEqual(str(endpoint), "http://php.testsparker.com")
307307

308308
def test_parse_file_with_mulitple_cwe(self):
309-
with open(get_unit_tests_scans_path("acunetix") / "acunetix360_multiple_cwe.json", encoding="utf-8") as testfile:
309+
with (get_unit_tests_scans_path("acunetix") / "acunetix360_multiple_cwe.json").open(encoding="utf-8") as testfile:
310310
parser = AcunetixParser()
311311
findings = parser.get_findings(testfile, Test())
312312
self.assertEqual(1, len(findings))
@@ -325,19 +325,19 @@ def test_parse_file_with_mulitple_cwe(self):
325325
self.assertEqual(str(endpoint), "http://php.testsparker.com/auth/login.php")
326326

327327
def test_parse_file_issue_10370(self):
328-
with open(get_unit_tests_scans_path("acunetix") / "issue_10370.json", encoding="utf-8") as testfile:
328+
with (get_unit_tests_scans_path("acunetix") / "issue_10370.json").open(encoding="utf-8") as testfile:
329329
parser = AcunetixParser()
330330
findings = parser.get_findings(testfile, Test())
331331
self.assertEqual(1, len(findings))
332332

333333
def test_parse_file_issue_10435(self):
334-
with open(get_unit_tests_scans_path("acunetix") / "issue_10435.json", encoding="utf-8") as testfile:
334+
with (get_unit_tests_scans_path("acunetix") / "issue_10435.json").open(encoding="utf-8") as testfile:
335335
parser = AcunetixParser()
336336
findings = parser.get_findings(testfile, Test())
337337
self.assertEqual(1, len(findings))
338338

339339
def test_parse_file_issue_11206(self):
340-
with open(get_unit_tests_scans_path("acunetix") / "issue_11206.json", encoding="utf-8") as testfile:
340+
with (get_unit_tests_scans_path("acunetix") / "issue_11206.json").open(encoding="utf-8") as testfile:
341341
parser = AcunetixParser()
342342
findings = parser.get_findings(testfile, Test())
343343
self.assertEqual(1, len(findings))

unittests/tools/test_anchore_engine_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55

66
class TestAnchoreEngineParser(DojoTestCase):
77
def test_anchore_engine_parser_has_no_finding(self):
8-
with open(get_unit_tests_scans_path("anchore_engine") / "no_vuln.json", encoding="utf-8") as testfile:
8+
with (get_unit_tests_scans_path("anchore_engine") / "no_vuln.json").open(encoding="utf-8") as testfile:
99
parser = AnchoreEngineParser()
1010
findings = parser.get_findings(testfile, Test())
1111
self.assertEqual(0, len(findings))
1212

1313
def test_anchore_engine_parser_has_one_finding(self):
14-
with open(get_unit_tests_scans_path("anchore_engine") / "one_vuln.json", encoding="utf-8") as testfile:
14+
with (get_unit_tests_scans_path("anchore_engine") / "one_vuln.json").open(encoding="utf-8") as testfile:
1515
parser = AnchoreEngineParser()
1616
findings = parser.get_findings(testfile, Test())
1717
self.assertEqual(1, len(findings))
1818

1919
def test_anchore_engine_parser_has_many_findings(self):
20-
with open(get_unit_tests_scans_path("anchore_engine") / "many_vulns.json", encoding="utf-8") as testfile:
20+
with (get_unit_tests_scans_path("anchore_engine") / "many_vulns.json").open(encoding="utf-8") as testfile:
2121
parser = AnchoreEngineParser()
2222
findings = parser.get_findings(testfile, Test())
2323
self.assertEqual(23, len(findings))
2424

2525
def test_anchore_engine_parser_has_many_findings_2_4_1(self):
26-
with open(get_unit_tests_scans_path("anchore_engine") / "many_vulns_2.4.1.json", encoding="utf-8") as testfile:
26+
with (get_unit_tests_scans_path("anchore_engine") / "many_vulns_2.4.1.json").open(encoding="utf-8") as testfile:
2727
parser = AnchoreEngineParser()
2828
findings = parser.get_findings(testfile, Test())
2929
self.assertEqual(51, len(findings))
@@ -36,7 +36,7 @@ def test_anchore_engine_parser_has_many_findings_2_4_1(self):
3636
self.assertEqual("CVE-2020-13776", finding.unsaved_vulnerability_ids[0])
3737

3838
def test_anchore_engine_parser_new_fomrat_issue_11552(self):
39-
with open(get_unit_tests_scans_path("anchore_engine") / "new_format_issue_11552.json", encoding="utf-8") as testfile:
39+
with (get_unit_tests_scans_path("anchore_engine") / "new_format_issue_11552.json").open(encoding="utf-8") as testfile:
4040
parser = AnchoreEngineParser()
4141
findings = parser.get_findings(testfile, Test())
4242
self.assertEqual(84, len(findings))

unittests/tools/test_anchore_enterprise_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
class TestAnchoreEnterpriseParser(DojoTestCase):
88
def test_anchore_policy_check_parser_has_no_findings(self):
9-
with open(get_unit_tests_scans_path("anchore_enterprise") / "no_checks.json", encoding="utf-8") as testfile:
9+
with (get_unit_tests_scans_path("anchore_enterprise") / "no_checks.json").open(encoding="utf-8") as testfile:
1010
parser = AnchoreEnterpriseParser()
1111
findings = parser.get_findings(testfile, Test())
1212
self.assertEqual(0, len(findings))
1313

1414
def test_anchore_policy_check_parser_has_one_finding(self):
15-
with open(get_unit_tests_scans_path("anchore_enterprise") / "one_check.json", encoding="utf-8") as testfile:
15+
with (get_unit_tests_scans_path("anchore_enterprise") / "one_check.json").open(encoding="utf-8") as testfile:
1616
parser = AnchoreEnterpriseParser()
1717
findings = parser.get_findings(testfile, Test())
1818
self.assertEqual(1, len(findings))
1919

2020
def test_anchore_policy_check_parser_has_multiple_findings(self):
21-
with open(get_unit_tests_scans_path("anchore_enterprise") / "many_checks.json", encoding="utf-8") as testfile:
21+
with (get_unit_tests_scans_path("anchore_enterprise") / "many_checks.json").open(encoding="utf-8") as testfile:
2222
parser = AnchoreEnterpriseParser()
2323
findings = parser.get_findings(testfile, Test())
2424
self.assertEqual(57, len(findings))
@@ -27,7 +27,7 @@ def test_anchore_policy_check_parser_has_multiple_findings(self):
2727
self.assertEqual("CVE-2015-2992", finding.unsaved_vulnerability_ids[0])
2828

2929
def test_anchore_policy_check_parser_invalid_format(self):
30-
with open(get_unit_tests_scans_path("anchore_enterprise") / "invalid_checks_format.json", encoding="utf-8") as testfile, \
30+
with (get_unit_tests_scans_path("anchore_enterprise") / "invalid_checks_format.json").open(encoding="utf-8") as testfile, \
3131
self.assertRaises(ValueError):
3232
parser = AnchoreEnterpriseParser()
3333
parser.get_findings(testfile, Test())

unittests/tools/test_anchore_grype_parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
class TestAnchoreGrypeParser(DojoTestCase):
77

88
def test_parser_has_no_findings(self):
9-
with open(get_unit_tests_scans_path("anchore_grype") / "no_vuln.json", encoding="utf-8") as testfile:
9+
with (get_unit_tests_scans_path("anchore_grype") / "no_vuln.json").open(encoding="utf-8") as testfile:
1010
parser = AnchoreGrypeParser()
1111
findings = parser.get_findings(testfile, Test())
1212
self.assertEqual(0, len(findings))
1313

1414
def test_parser_has_many_findings(self):
1515
found = False
16-
with open(get_unit_tests_scans_path("anchore_grype") / "many_vulns.json", encoding="utf-8") as testfile:
16+
with (get_unit_tests_scans_path("anchore_grype") / "many_vulns.json").open(encoding="utf-8") as testfile:
1717
parser = AnchoreGrypeParser()
1818
findings = parser.get_findings(testfile, Test())
1919
self.assertEqual(1509, len(findings))
@@ -35,7 +35,7 @@ def test_parser_has_many_findings(self):
3535

3636
def test_grype_parser_with_one_criticle_vuln_has_one_findings(self):
3737
found = False
38-
with open(get_unit_tests_scans_path("anchore_grype") / "many_vulns2.json", encoding="utf-8") as testfile:
38+
with (get_unit_tests_scans_path("anchore_grype") / "many_vulns2.json").open(encoding="utf-8") as testfile:
3939
parser = AnchoreGrypeParser()
4040
findings = parser.get_findings(testfile, Test())
4141
self.assertEqual(1567, len(findings))
@@ -56,7 +56,7 @@ def test_grype_parser_with_one_criticle_vuln_has_one_findings(self):
5656

5757
def test_grype_parser_with_many_vulns3(self):
5858
found = False
59-
with open(get_unit_tests_scans_path("anchore_grype") / "many_vulns3.json", encoding="utf-8") as testfile:
59+
with (get_unit_tests_scans_path("anchore_grype") / "many_vulns3.json").open(encoding="utf-8") as testfile:
6060
parser = AnchoreGrypeParser()
6161
findings = parser.get_findings(testfile, Test())
6262
self.assertEqual(327, len(findings))
@@ -77,7 +77,7 @@ def test_grype_parser_with_many_vulns3(self):
7777

7878
def test_grype_parser_with_new_matcher_list(self):
7979
found = False
80-
with open(get_unit_tests_scans_path("anchore_grype") / "many_vulns4.json", encoding="utf-8") as testfile:
80+
with (get_unit_tests_scans_path("anchore_grype") / "many_vulns4.json").open(encoding="utf-8") as testfile:
8181
parser = AnchoreGrypeParser()
8282
findings = parser.get_findings(testfile, Test())
8383
self.assertEqual(9, len(findings))
@@ -97,7 +97,7 @@ def test_grype_parser_with_new_matcher_list(self):
9797
self.assertTrue(found)
9898

9999
def test_check_all_fields(self):
100-
with open(get_unit_tests_scans_path("anchore_grype") / "check_all_fields.json", encoding="utf-8") as testfile:
100+
with (get_unit_tests_scans_path("anchore_grype") / "check_all_fields.json").open(encoding="utf-8") as testfile:
101101
parser = AnchoreGrypeParser()
102102
findings = parser.get_findings(testfile, Test())
103103
self.assertEqual(5, len(findings))
@@ -266,13 +266,13 @@ def test_check_all_fields(self):
266266
self.assertEqual(2, finding.nb_occurences)
267267

268268
def test_grype_issue_9618(self):
269-
with open(get_unit_tests_scans_path("anchore_grype") / "issue_9618.json", encoding="utf-8") as testfile:
269+
with (get_unit_tests_scans_path("anchore_grype") / "issue_9618.json").open(encoding="utf-8") as testfile:
270270
parser = AnchoreGrypeParser()
271271
findings = parser.get_findings(testfile, Test())
272272
self.assertEqual(35, len(findings))
273273

274274
def test_grype_issue_9942(self):
275-
with open(get_unit_tests_scans_path("anchore_grype") / "issue_9942.json", encoding="utf-8") as testfile:
275+
with (get_unit_tests_scans_path("anchore_grype") / "issue_9942.json").open(encoding="utf-8") as testfile:
276276
parser = AnchoreGrypeParser()
277277
findings = parser.get_findings(testfile, Test())
278278
self.assertEqual(1, len(findings))

unittests/tools/test_anchorectl_policies_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
class TestAnchoreCTLPoliciesParser(DojoTestCase):
77
def test_anchore_engine_parser_has_no_finding(self):
8-
with open(get_unit_tests_scans_path("anchorectl_policies") / "no_violation.json", encoding="utf-8") as testfile:
8+
with (get_unit_tests_scans_path("anchorectl_policies") / "no_violation.json").open(encoding="utf-8") as testfile:
99
parser = AnchoreCTLPoliciesParser()
1010
findings = parser.get_findings(testfile, Test())
1111
self.assertEqual(0, len(findings))
1212

1313
def test_anchore_engine_parser_has_one_finding_and_it_is_correctly_parsed(self):
14-
with open(get_unit_tests_scans_path("anchorectl_policies") / "one_violation.json", encoding="utf-8") as testfile:
14+
with (get_unit_tests_scans_path("anchorectl_policies") / "one_violation.json").open(encoding="utf-8") as testfile:
1515
parser = AnchoreCTLPoliciesParser()
1616
findings = parser.get_findings(testfile, Test())
1717
self.assertEqual(1, len(findings))
@@ -21,13 +21,13 @@ def test_anchore_engine_parser_has_one_finding_and_it_is_correctly_parsed(self):
2121
self.assertEqual(singleFinding.description, "User root found as effective user, which is not on the allowed list")
2222

2323
def test_anchore_engine_parser_has_many_findings(self):
24-
with open(get_unit_tests_scans_path("anchorectl_policies") / "many_violations.json", encoding="utf-8") as testfile:
24+
with (get_unit_tests_scans_path("anchorectl_policies") / "many_violations.json").open(encoding="utf-8") as testfile:
2525
parser = AnchoreCTLPoliciesParser()
2626
findings = parser.get_findings(testfile, Test())
2727
self.assertEqual(3, len(findings))
2828

2929
def test_anchore_engine_parser_has_one_finding_and_description_has_severity(self):
30-
with open(get_unit_tests_scans_path("anchorectl_policies") / "one_violation_description_severity.json", encoding="utf-8") as testfile:
30+
with (get_unit_tests_scans_path("anchorectl_policies") / "one_violation_description_severity.json").open(encoding="utf-8") as testfile:
3131
parser = AnchoreCTLPoliciesParser()
3232
findings = parser.get_findings(testfile, Test())
3333
self.assertEqual(1, len(findings))

unittests/tools/test_anchorectl_vulns_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
class TestAnchoreCTLVulnsParser(DojoTestCase):
77
def test_anchore_engine_parser_has_no_finding(self):
8-
with open(get_unit_tests_scans_path("anchorectl_vulns") / "no_vuln.json", encoding="utf-8") as testfile:
8+
with (get_unit_tests_scans_path("anchorectl_vulns") / "no_vuln.json").open(encoding="utf-8") as testfile:
99
parser = AnchoreCTLVulnsParser()
1010
findings = parser.get_findings(testfile, Test())
1111
self.assertEqual(0, len(findings))
1212

1313
def test_anchore_engine_parser_has_one_finding_and_it_is_correctly_parsed(self):
14-
with open(get_unit_tests_scans_path("anchorectl_vulns") / "one_vuln.json", encoding="utf-8") as testfile:
14+
with (get_unit_tests_scans_path("anchorectl_vulns") / "one_vuln.json").open(encoding="utf-8") as testfile:
1515
parser = AnchoreCTLVulnsParser()
1616
findings = parser.get_findings(testfile, Test())
1717
self.assertEqual(1, len(findings))
@@ -21,7 +21,7 @@ def test_anchore_engine_parser_has_one_finding_and_it_is_correctly_parsed(self):
2121
self.assertEqual(singleFinding.description, "**Image hash**: None\n\n**Package**: libgnutls30-3.5.8-5+deb9u4\n\n**Package path**: None\n\n**Package type**: dpkg\n\n**Feed**: vulnerabilities/debian:9\n\n**CPE**: None\n\n**Description**: That test description\n\n")
2222

2323
def test_anchore_engine_parser_has_many_findings(self):
24-
with open(get_unit_tests_scans_path("anchorectl_vulns") / "many_vulns.json", encoding="utf-8") as testfile:
24+
with (get_unit_tests_scans_path("anchorectl_vulns") / "many_vulns.json").open(encoding="utf-8") as testfile:
2525
parser = AnchoreCTLVulnsParser()
2626
findings = parser.get_findings(testfile, Test())
2727
self.assertEqual(23, len(findings))

unittests/tools/test_api_blackduck_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class TestApiBlackduckParser(DojoTestCase):
88

99
def test_bandit_parser_has_many_findings(self):
10-
with open(get_unit_tests_scans_path("api_blackduck") / "many_vulns.json", encoding="utf-8") as testfile:
10+
with (get_unit_tests_scans_path("api_blackduck") / "many_vulns.json").open(encoding="utf-8") as testfile:
1111
parser = ApiBlackduckParser()
1212
findings = parser.get_findings(testfile, Test())
1313
for finding in findings:

0 commit comments

Comments
 (0)