summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-07-19 21:41:58 -0400
committerNed Batchelder <ned@nedbatchelder.com>2019-07-19 21:41:58 -0400
commit0a93630dc92de59194794f5f0b9ae1987157f327 (patch)
tree0b4e37ac38aba2f8a3a46a0bfcecaed2d7209a34 /tests
parente4054498c6eb2f0b97de80bcf9835f416a91207c (diff)
downloadpython-coveragepy-git-0a93630dc92de59194794f5f0b9ae1987157f327.tar.gz
z-compressed dumps and loads
Diffstat (limited to 'tests')
-rw-r--r--tests/test_data.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_data.py b/tests/test_data.py
index 5ac08bb6..ad752d65 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -7,6 +7,7 @@ import glob
import os
import os.path
import random
+import re
import sqlite3
import threading
@@ -809,6 +810,33 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
covdata2.add_lines(LINES_1)
+class DumpsLoadsTest(DataTestHelpers, CoverageTest):
+ """Tests of CoverageData.dumps and loads."""
+
+ run_in_temp_dir = False
+
+ def test_serialization(self):
+ covdata1 = CoverageData(no_disk=True)
+ covdata1.add_lines(LINES_1)
+ covdata1.add_lines(LINES_2)
+ serial = covdata1.dumps()
+
+ covdata2 = CoverageData(no_disk=True)
+ covdata2.loads(serial)
+ self.assert_line_counts(covdata2, SUMMARY_1_2)
+ self.assert_measured_files(covdata2, MEASURED_FILES_1_2)
+
+ def test_misfed_serialization(self):
+ covdata = CoverageData(no_disk=True)
+ bad_data = b'Hello, world!\x07 ' + b'z' * 100
+ msg = r"Unrecognized serialization: {} \(head of {} bytes\)".format(
+ re.escape(repr(bad_data[:40])),
+ len(bad_data),
+ )
+ with self.assertRaisesRegex(CoverageException, msg):
+ covdata.loads(bad_data)
+
+
class BitmapOpTest(CoverageTest):
"""Tests of the bitmap operations in sqldata.py."""