mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-22 09:32:25 +01:00
Enable B023, PT017: fix loop variable binding and use pytest.raises
This commit is contained in:
parent
d06cf95566
commit
24d15e831f
@ -283,8 +283,8 @@ def append_cases_to_unified_test(
|
|||||||
if re.search(pattern_no_best, content):
|
if re.search(pattern_no_best, content):
|
||||||
content = re.sub(
|
content = re.sub(
|
||||||
pattern_no_best,
|
pattern_no_best,
|
||||||
lambda m: m.group(0).replace(
|
lambda m, lbl=base_label, bst=best_uci: m.group(0).replace(
|
||||||
m.group(1), f"{base_label}_best_{best_uci}"
|
m.group(1), f"{lbl}_best_{bst}"
|
||||||
),
|
),
|
||||||
content,
|
content,
|
||||||
count=1,
|
count=1,
|
||||||
@ -293,8 +293,8 @@ def append_cases_to_unified_test(
|
|||||||
elif re.search(pattern_with_best, content):
|
elif re.search(pattern_with_best, content):
|
||||||
content = re.sub(
|
content = re.sub(
|
||||||
pattern_with_best,
|
pattern_with_best,
|
||||||
lambda m: m.group(0).replace(
|
lambda m, lbl=base_label, bst=best_uci: m.group(0).replace(
|
||||||
m.group(1), f"{base_label}_best_{best_uci}"
|
m.group(1), f"{lbl}_best_{bst}"
|
||||||
),
|
),
|
||||||
content,
|
content,
|
||||||
count=1,
|
count=1,
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import time
|
|||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def _req(url, method="GET", data=None):
|
def _req(url, method="GET", data=None):
|
||||||
"""Send an HTTP request and return status code and body."""
|
"""Send an HTTP request and return status code and body."""
|
||||||
@ -92,12 +94,9 @@ def test_crud_roundtrip(tmp_path):
|
|||||||
assert code == HTTPStatus.NO_CONTENT
|
assert code == HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
# Ensure gone
|
# Ensure gone
|
||||||
try:
|
with pytest.raises(urllib.error.HTTPError) as exc_info:
|
||||||
_req(base + f"/api/articles/{art_id}")
|
_req(base + f"/api/articles/{art_id}")
|
||||||
msg = "Expected 404"
|
assert exc_info.value.code == HTTPStatus.NOT_FOUND
|
||||||
raise AssertionError(msg)
|
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
assert e.code == HTTPStatus.NOT_FOUND
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
srv.terminate()
|
srv.terminate()
|
||||||
|
|||||||
@ -65,12 +65,10 @@ ignore = [
|
|||||||
"S310", # suspicious-url-open - acceptable for scripts
|
"S310", # suspicious-url-open - acceptable for scripts
|
||||||
"S110", # try-except-pass - common pattern in scripts
|
"S110", # try-except-pass - common pattern in scripts
|
||||||
"S112", # try-except-continue - acceptable pattern
|
"S112", # try-except-continue - acceptable pattern
|
||||||
"B023", # function-uses-loop-variable - common pattern with closures
|
|
||||||
"DTZ005", # datetime.now without tz - acceptable for local scripts
|
"DTZ005", # datetime.now without tz - acceptable for local scripts
|
||||||
"E741", # ambiguous-variable-name - sometimes intentional (e.g. l for list)
|
"E741", # ambiguous-variable-name - sometimes intentional (e.g. l for list)
|
||||||
"DTZ004", # datetime.utcfromtimestamp - acceptable
|
"DTZ004", # datetime.utcfromtimestamp - acceptable
|
||||||
"E722", # bare-except - will be fixed where critical
|
"E722", # bare-except - will be fixed where critical
|
||||||
"PT017", # pytest-assert-in-except - acceptable pattern
|
|
||||||
"PERF401", # manual-list-comprehension - style preference
|
"PERF401", # manual-list-comprehension - style preference
|
||||||
"RUF005", # collection-literal-concatenation - style preference
|
"RUF005", # collection-literal-concatenation - style preference
|
||||||
"SIM102", # collapsible-if - style preference
|
"SIM102", # collapsible-if - style preference
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user