Skip to content

Commit 9f9ad95

Browse files
Fix PT006, PT007, PT018, PT030 prek violations
Remove PT006/PT007 from ignore list and fix all violations: convert list/string parametrize args to tuples, convert tuple-of-tuples values to list-of-tuples, split compound assertions, and add match= to pytest.warns calls.
1 parent c7ee246 commit 9f9ad95

7 files changed

Lines changed: 24 additions & 24 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ ignore = [
154154
"PT009", # pytest.raises(ValueError) too broad
155155
"PT011", # pytest.raises(ValueError) too broad
156156
"PT012", # pytest.raises() block should contain a single simple statement
157-
"PT006", # Wrong type passed to first argument of `pytest.mark.parametrize`
158-
"PT007", # Wrong type pytest.mark.parametrize` expected `list` of `tuple
159157
"B018", # Found useless expression. Either assign it
160-
"PT018", # Assertion should be broken down into multiple parts
161-
"PT030", # `pytest.warns(UserWarning)` is too broad, set the
162158
"B028", # No stacklevel for warnings
163159
]
164160

tests/test_algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def test_from_ts(self):
372372
assert ts.sequence_length == 100
373373

374374
@pytest.mark.parametrize(
375-
["num_founders", "num_generations", "r"],
375+
("num_founders", "num_generations", "r"),
376376
[
377377
(4, 5, 0),
378378
(4, 5, 0.1),

tests/test_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ def test_simulate_short_args(self, tmp_path):
13461346
def test_compress_warns(self, tmp_path):
13471347
cmd = "simulate"
13481348
tree_sequence_file = str(tmp_path / "out.ts")
1349-
with pytest.warns(UserWarning):
1349+
with pytest.warns(UserWarning, match="--compress option is no longer supported"):
13501350
capture_output(cli.msp_main, [cmd, "10", tree_sequence_file, "--compress"])
13511351
tree_sequence = tskit.load(tree_sequence_file)
13521352
assert tree_sequence.get_sample_size() == 10
@@ -1450,7 +1450,7 @@ def test_run_yaml(self, tmp_path):
14501450

14511451
class TestSampleParsing:
14521452
@pytest.mark.parametrize(
1453-
["param", "result"], [("1", 1), ("1000", 1000), ("1_000", 1000), ("1e3", 1000)]
1453+
("param", "result"), [("1", 1), ("1000", 1000), ("1_000", 1000), ("1e3", 1000)]
14541454
)
14551455
def test_parse_sample_size(self, param, result):
14561456
value = cli.parse_sample_size(param)
@@ -1462,7 +1462,7 @@ def test_parse_sample_size_error(self, param):
14621462
cli.parse_sample_size(param)
14631463

14641464
@pytest.mark.parametrize(
1465-
["param", "result"],
1465+
("param", "result"),
14661466
[
14671467
(["A:1"], {"A": 1}),
14681468
(["A:2", "B:1"], {"A": 2, "B": 1}),
@@ -1484,7 +1484,7 @@ def test_parse_sample_spec_malformed_token(self, param):
14841484

14851485

14861486
@pytest.mark.parametrize(
1487-
["verbosity", "log_level"],
1487+
("verbosity", "log_level"),
14881488
[("", "WARN"), ("-v", "INFO"), ("-vv", "DEBUG"), ("-vvv", "DEBUG")],
14891489
)
14901490
def test_setup_logging(verbosity, log_level):

tests/test_demes.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ def test_activate_ghost_split(self):
594594
assert "B" == dbg.epochs[0].active_populations[0].name
595595
assert len(dbg.epochs[1].active_populations) == 2
596596
active_pops = [_.name for _ in dbg.epochs[1].active_populations]
597-
assert "B" in active_pops and "C" in active_pops
597+
assert "B" in active_pops
598+
assert "C" in active_pops
598599
assert len(dbg.epochs[2].active_populations) == 1
599600
assert "A" in dbg.epochs[2].active_populations[0].name
600601

@@ -628,10 +629,12 @@ def test_activate_ghost_admixture(self):
628629
assert "D" == dbg.epochs[0].active_populations[0].name
629630
assert len(dbg.epochs[1].active_populations) == 2
630631
active_pops = [_.name for _ in dbg.epochs[1].active_populations]
631-
assert "B" in active_pops and "D" in active_pops
632+
assert "B" in active_pops
633+
assert "D" in active_pops
632634
assert len(dbg.epochs[2].active_populations) == 2
633635
active_pops = [_.name for _ in dbg.epochs[2].active_populations]
634-
assert "B" in active_pops and "C" in active_pops
636+
assert "B" in active_pops
637+
assert "C" in active_pops
635638
assert len(dbg.epochs[3].active_populations) == 1
636639
assert "A" in dbg.epochs[3].active_populations[0].name
637640

@@ -775,7 +778,7 @@ def test_admixture_via_mass_migration(self):
775778
assert epoch.end_size == 1000
776779

777780
@pytest.mark.parametrize(
778-
"time_lo,time_hi", [(0, math.inf), (0, 20), (10, math.inf), (10, 20)]
781+
("time_lo", "time_hi"), [(0, math.inf), (0, 20), (10, math.inf), (10, 20)]
779782
)
780783
def test_asymmetric_migration_via_rate_change(self, time_lo, time_hi):
781784
demog = msprime.Demography.isolated_model([1000] * 2)
@@ -928,8 +931,8 @@ def test_bad_pulse(self):
928931
demog.to_demes()
929932

930933
@pytest.mark.parametrize(
931-
"sizes,times",
932-
(([1000], [0]), ([1000, 500], [0, 20]), ([1000, 50, 1000], [0, 20, 30])),
934+
("sizes", "times"),
935+
[([1000], [0]), ([1000, 500], [0, 20]), ([1000, 50, 1000], [0, 20, 30])],
933936
)
934937
def test_piecewise_constant_sizes(self, sizes, times):
935938
assert len(sizes) == len(times)
@@ -953,13 +956,13 @@ def test_piecewise_constant_sizes(self, sizes, times):
953956
assert epochs[j].end_time == times[len(times) - j - 1]
954957

955958
@pytest.mark.parametrize(
956-
"sizes,growth_rates,times",
957-
(
959+
("sizes", "growth_rates", "times"),
960+
[
958961
([1000, 500], [0.1, 0], [0, 20]),
959962
([1000, None, 1000], [0.1, -0.1, 0], [0, 20, 30]),
960963
([1000, 5000, 1000], [0.1, None, 0], [0, 20, 30]),
961964
([1000, 5000, None], [0.1, None, 0], [0, 20, 30]),
962-
),
965+
],
963966
)
964967
def test_piecewise_exponential_sizes(self, sizes, growth_rates, times):
965968
assert growth_rates[-1] == 0 # can't convert to demes graph otherwise

tests/test_demography.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ def test_double_step_validation(self):
17311731
)
17321732
ddb = model.debug()
17331733
steps = np.linspace(0, 400, 2)
1734-
with pytest.warns(UserWarning):
1734+
with pytest.warns(UserWarning, match="Doubling the number of steps"):
17351735
ddb.coalescence_rate_trajectory(steps=steps, lineages={"A": 2})
17361736
# Test coalescence rates without double step validation
17371737
steps = np.linspace(0, 400, 401)

tests/test_mutations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def test_SMM(self):
367367
sys.platform.startswith("win"), reason="Windows BLAS issue #2349"
368368
)
369369
@pytest.mark.parametrize(
370-
"p, m, lo, hi",
370+
("p", "m", "lo", "hi"),
371371
[
372372
(0.9, 0.9, 2, 50),
373373
(0.5, 0.25, 50, 500),
@@ -428,7 +428,7 @@ def test_EL2(self):
428428
assert np.abs(exp - a_ratio) < 1e-6
429429

430430
@pytest.mark.parametrize(
431-
"m, u, v, p, s, lo, hi",
431+
("m", "u", "v", "p", "s", "lo", "hi"),
432432
[
433433
(1.0, 0.62, 0.015, 0, 0.88, 1, 10.0),
434434
(0.43, 0.68, 0.037, 1.0, 0.5, 3.0, 10),
@@ -444,7 +444,7 @@ def test_MicrosatMutationModel(self, m, u, v, p, s, lo, hi):
444444

445445
class TestMicrosatModels:
446446
@pytest.mark.parametrize(
447-
"m, u, v, p, s",
447+
("m", "u", "v", "p", "s"),
448448
[
449449
(1.0, 0.62, 0.015, 0, 0.88),
450450
(0.43, 0.68, 0.037, 0, 0.88),
@@ -468,7 +468,7 @@ def test_transition_matrix(self, m, u, v, p, s):
468468
assert ((d[0] / d[j]) - exp) < 1e-6
469469

470470
@pytest.mark.parametrize(
471-
"m, u, v, p, s, lo, hi",
471+
("m", "u", "v", "p", "s", "lo", "hi"),
472472
[
473473
(1.0, 0.62, 0.015, 0, 0.88, 1, np.inf),
474474
(0.43, 0.68, 0.037, 0, 0.88, np.inf, 10),

tests/test_python_c.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,8 @@ def test_demographic_events(self):
934934
migration_matrix[:] = rate
935935
np.fill_diagonal(migration_matrix, 0)
936936
else:
937-
assert source >= 0 and dest >= 0
937+
assert source >= 0
938+
assert dest >= 0
938939
migration_matrix[source, dest] = rate
939940
elif event_type == "mass_migration":
940941
source = event["source"]

0 commit comments

Comments
 (0)