Format code with black

This commit is contained in:
James Campbell
2026-08-01 12:19:46 -04:00
parent b0ad9610be
commit f29d8c953c
16 changed files with 459 additions and 311 deletions

View File

@@ -20,12 +20,12 @@ def test_stationary_is_solid():
def test_deadly_is_hazard_not_solid():
b = block(at=[3, 3], deadly=True)
assert b.solid_rects() == []
assert b.hazard_rects() # non-empty
assert b.hazard_rects() # non-empty
def test_fake_is_drawn_but_not_solid():
b = block(at=[3, 3], fake=True)
assert b.solid_rects() == [] # you fall through
assert b.solid_rects() == [] # you fall through
assert b.sprite == "fake_block" # looks like a real block
@@ -53,8 +53,8 @@ traps:
if g.deaths > d0:
killed = True
break
assert "gone" in states # it crumbled away
assert killed # re-formed onto the standing player
assert "gone" in states # it crumbled away
assert killed # re-formed onto the standing player
def test_moving_block_that_crumbles(make_game):
@@ -78,7 +78,7 @@ traps:
respawn: 1.0
""")
b = g.level.traps[0]
place(g, 2, 1) # ride the platform
place(g, 2, 1) # ride the platform
moved = crumbled = False
start = b.x
for _ in range(200):
@@ -103,18 +103,23 @@ def test_patrol_loop_visits_all_waypoints():
def test_slider_once_no_jitter_and_retracts():
# sense=home (default): a slider moving away can't toggle its own trigger.
b = block(at=[16, 6], move=[-3, 0], speed=260, trigger={"within": 3})
g = FakeGame(pygame.Rect(17 * 32, 6 * 32, 23, 29)) # player parked to the right
g = FakeGame(pygame.Rect(17 * 32, 6 * 32, 23, 29)) # player parked to the right
xs = [(b.update(1 / 60, g), b.x)[1] for _ in range(120)]
assert reversals(xs) == 0 and abs(xs[-1] - 13 * 32) < 2 # committed to displaced
g.player.rect.x = 30 * 32 # leave
assert reversals(xs) == 0 and abs(xs[-1] - 13 * 32) < 2 # committed to displaced
g.player.rect.x = 30 * 32 # leave
xs = [(b.update(1 / 60, g), b.x)[1] for _ in range(120)]
assert reversals(xs) == 0 and abs(xs[-1] - 16 * 32) < 2 # retracted to base
assert reversals(xs) == 0 and abs(xs[-1] - 16 * 32) < 2 # retracted to base
def test_sense_current_rides_down():
# A dropper (sense=current) commits to the bottom and holds while ridden.
b = block(at=[21, 9], move=[0, 4], speed=220, sense="current",
trigger={"all": [{"within": 5}, {"dir": "above", "aligned": True}]})
b = block(
at=[21, 9],
move=[0, 4],
speed=220,
sense="current",
trigger={"all": [{"within": 5}, {"dir": "above", "aligned": True}]},
)
# player standing on top of it
p = pygame.Rect(21 * 32 + 4, 9 * 32 - 29, 23, 29)
g = FakeGame(p)
@@ -124,15 +129,15 @@ def test_sense_current_rides_down():
# keep the player riding the block top
p.bottom = b._rect().top
ys.append(b.y)
assert reversals(ys) == 0 and abs(ys[-1] - 13 * 32) < 2 # dropped fully, no bob
assert reversals(ys) == 0 and abs(ys[-1] - 13 * 32) < 2 # dropped fully, no bob
def test_carriers_reports_motion():
b = block(at=[0, 5], path=[[0, 5], [5, 5]], mode="pingpong", speed=120)
g = FakeGame(pygame.Rect(0, 0, 4, 4))
b.update(1 / 60, g)
(rect, dx, dy), = b.carriers()
assert dx != 0 and dy == 0 # moving horizontally
((rect, dx, dy),) = b.carriers()
assert dx != 0 and dy == 0 # moving horizontally
# --- array expansion (count / spacing) --------------------------------------
@@ -147,8 +152,12 @@ def test_expand_line():
def test_expand_grid_with_spacing():
ats = [s["at"] for s in expand_spec(
{"type": "block", "at": [0, 0], "count": [3, 2], "spacing": [2, 3]})]
ats = [
s["at"]
for s in expand_spec(
{"type": "block", "at": [0, 0], "count": [3, 2], "spacing": [2, 3]}
)
]
assert ats == [[0, 0], [2, 0], [4, 0], [0, 3], [2, 3], [4, 3]]
# count/spacing are stripped from each expanded spec
for s in expand_spec({"type": "block", "at": [0, 0], "count": [2, 1]}):
@@ -173,4 +182,9 @@ traps:
blocks = [t for t in lvl.traps if isinstance(t, Block)]
assert len(blocks) == 4
assert all(b.deadly for b in blocks)
assert sorted(b.current_rect().x for b in blocks) == [2 * 32, 3 * 32, 4 * 32, 5 * 32]
assert sorted(b.current_rect().x for b in blocks) == [
2 * 32,
3 * 32,
4 * 32,
5 * 32,
]