Skip to content

Commit cce22ba

Browse files
EliahKaganclaude
andcommitted
Convert remaining rorepo-mutating tests to @with_rw_repo
Two further `TestRepo` tests in `test/test_repo.py` mutate `self.rorepo` on disk: - `test_daemon_export` toggles `self.rorepo.daemon_export`, which creates and removes `.git/git-daemon-export-ok` via `touch` and `os.unlink`. - `test_alternates` assigns to `self.rorepo.alternates`, which writes and removes `<common_dir>/objects/info/alternates` via `open(..., "wb")` and `os.remove`. Both bracket their writes with a save-and-restore pattern, so on the happy path the on-disk state ends up unchanged; on a mid-test abort the rorepo is left with stray state. Neither test produces git lock files, which is why an earlier scope based on lock- leaking tests did not pick them up. The contract violation is the same in shape (transient mutation of a fixture documented as read-only and shared across tests), and the same conversion applies: `@with_rw_repo("HEAD")` confines the writes to a per-test temp clone destined for cleanup. Note that `@with_rw_repo` clones with `shared=True`, which sets the clone's `objects/info/alternates` to point back at the source repository's `objects/`. In `test_alternates` this means `cur_alternates` reads back as one entry rather than the empty list typical on the rorepo. The test's save/empty/set/restore sequence still exercises the same setter contract; the asserts verify what the setter wrote at each step. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f64e36a commit cce22ba

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

‎test/test_repo.py‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,24 @@ def test_init(self):
300300
def test_bare_property(self):
301301
self.rorepo.bare
302302

303-
def test_daemon_export(self):
304-
orig_val = self.rorepo.daemon_export
305-
self.rorepo.daemon_export = not orig_val
306-
self.assertEqual(self.rorepo.daemon_export, (not orig_val))
307-
self.rorepo.daemon_export = orig_val
308-
self.assertEqual(self.rorepo.daemon_export, orig_val)
309-
310-
def test_alternates(self):
311-
cur_alternates = self.rorepo.alternates
303+
@with_rw_repo("HEAD")
304+
def test_daemon_export(self, rwrepo):
305+
orig_val = rwrepo.daemon_export
306+
rwrepo.daemon_export = not orig_val
307+
self.assertEqual(rwrepo.daemon_export, (not orig_val))
308+
rwrepo.daemon_export = orig_val
309+
self.assertEqual(rwrepo.daemon_export, orig_val)
310+
311+
@with_rw_repo("HEAD")
312+
def test_alternates(self, rwrepo):
313+
cur_alternates = rwrepo.alternates
312314
# empty alternates
313-
self.rorepo.alternates = []
314-
self.assertEqual(self.rorepo.alternates, [])
315+
rwrepo.alternates = []
316+
self.assertEqual(rwrepo.alternates, [])
315317
alts = ["other/location", "this/location"]
316-
self.rorepo.alternates = alts
317-
self.assertEqual(alts, self.rorepo.alternates)
318-
self.rorepo.alternates = cur_alternates
318+
rwrepo.alternates = alts
319+
self.assertEqual(alts, rwrepo.alternates)
320+
rwrepo.alternates = cur_alternates
319321

320322
def test_repr(self):
321323
assert repr(self.rorepo).startswith("<git.repo.base.Repo ")

0 commit comments

Comments
 (0)