From 0a93630dc92de59194794f5f0b9ae1987157f327 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 19 Jul 2019 21:41:58 -0400 Subject: z-compressed dumps and loads --- tests/test_data.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') 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.""" -- cgit v1.2.1