Skip to content

Commit 35b58d3

Browse files
committed
fix: CoverageData.update() can be called twice on an in-memory database. #2279
1 parent 92e1ce9 commit 35b58d3

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎CHANGES.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ Unreleased
2828
``else:`` body removes the ``else:`` line. Previously the ``case`` line was
2929
left behind and reported as missing. Closes `issue 1563`_ with `pull 2269`_.
3030

31+
- Fix: using :meth:`.CoverageData.update` twice on an in-memory database would
32+
fail, as described in `issue 2279`_. This is now fixed.
33+
3134
.. _issue 1563: https://github.com/coveragepy/coveragepy/issues/1563
3235
.. _pull 2269: https://github.com/coveragepy/coveragepy/pull/2269
36+
.. _issue 2279: https://github.com/coveragepy/coveragepy/issues/2279
3337

3438
.. start-releases
3539

‎coverage/sqldata.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ def map_with_fixed_slashes(p: str) -> str:
880880
INNER JOIN main.file AS main_file ON other_file_mapped.mapped_path = main_file.path
881881
""")
882882

883+
# Clean up in case we'll use update() again.
884+
con.execute_void("DROP TABLE other_file_mapped")
885+
if has_arcs:
886+
con.execute_void("DROP TABLE context_mapping")
887+
con.con.commit()
888+
con.execute_void("DETACH DATABASE other_db")
889+
883890
if not self._no_disk:
884891
# Update all internal cache data.
885892
self._reset()

‎tests/test_data.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,24 @@ def test_update_arcs_empty(self) -> None:
526526
covdata1.update(covdata2)
527527
assert_line_counts(covdata1, SUMMARY_3)
528528

529+
def test_update_lines_in_memory_twice(self) -> None:
530+
combined = DebugCoverageData(no_disk=True)
531+
for index in range(2):
532+
source = DebugCoverageData(no_disk=True)
533+
source.add_lines({"example.py": {index + 1}})
534+
source.write()
535+
combined.update(source)
536+
assert combined.lines("example.py") == [1, 2]
537+
538+
def test_update_arcs_in_memory_twice(self) -> None:
539+
combined = DebugCoverageData(no_disk=True)
540+
for index in range(2):
541+
source = DebugCoverageData(no_disk=True)
542+
source.add_arcs({"example.py": {(index + 1, 10)}})
543+
source.write()
544+
combined.update(source)
545+
assert combined.arcs("example.py") == [(1, 10), (2, 10)]
546+
529547
def test_asking_isnt_measuring(self) -> None:
530548
# Asking about an unmeasured file shouldn't make it seem measured.
531549
covdata = DebugCoverageData()

0 commit comments

Comments
 (0)