Skip to content

Commit

Permalink
- added saving final coverage in checkpoint, since CoverUp already
Browse files Browse the repository at this point in the history
  measures it anyway, and it is useful for evaluation;
  • Loading branch information
jaltmayerpizzorno committed Feb 14, 2024
1 parent ef6e2ef commit b760899
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/coverup/coverup.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def __init__(self, initial_coverage: dict):
self.coverage = initial_coverage
self.usage = {'prompt_tokens': 0, 'completion_tokens': 0}
self.counters = {k:0 for k in PROGRESS_COUNTERS}
self.final_coverage = None
self.bar = None


Expand All @@ -306,6 +307,11 @@ def get_initial_coverage(self) -> dict:
return self.coverage


def set_final_coverage(self, cov: dict) -> None:
"""Adds the final coverage obtained, so it can be saved in a checkpoint."""
self.final_coverage = cov


def set_progress_bar(self, bar: Progress):
"""Specifies a progress bar to update."""
self.bar = bar
Expand Down Expand Up @@ -365,15 +371,20 @@ def load_checkpoint(ckpt_file: Path): # -> State

def save_checkpoint(self, ckpt_file: Path):
"""Saves this state to a checkpoint file."""
ckpt = {
'version': 1,
'done': {k:list(v) for k,v in self.done.items() if len(v)}, # cannot serialize 'set' as-is
'usage': self.usage,
'counters': self.counters,
'coverage': self.coverage
# FIXME save missing modules
}

if self.final_coverage:
ckpt['final_coverage'] = self.final_coverage

with ckpt_file.open("w") as f:
json.dump({
'version': 1,
'done': {k:list(v) for k,v in self.done.items() if len(v)}, # cannot serialize 'set' as-is
'usage': self.usage,
'counters': self.counters,
'coverage': self.coverage
# FIXME save missing modules
}, f)
json.dump(ckpt, f)


state = None
Expand Down Expand Up @@ -684,6 +695,10 @@ async def sem_coro(coro):
coverage = disable_interfering_tests()
print(f"End coverage: {coverage['summary']['percent_covered']:.1f}%")

if args.checkpoint:
state.set_final_coverage(coverage)
state.save_checkpoint(args.checkpoint)

# --- (4) final remarks ---

if required := get_required_modules():
Expand Down

0 comments on commit b760899

Please sign in to comment.