diff options
-rw-r--r-- | coverage/numbits.py | 2 | ||||
-rw-r--r-- | tests/test_numbits.py | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/coverage/numbits.py b/coverage/numbits.py index 367ec6a1..c4f0ad02 100644 --- a/coverage/numbits.py +++ b/coverage/numbits.py @@ -13,6 +13,7 @@ in the blobs should be considered an implementation detail that might change in the future. Use these functions to work with those binary blobs of data. """ +import json from coverage import env from coverage.backward import byte_to_int, bytes_to_ints, binary_bytes, zip_longest @@ -154,3 +155,4 @@ def register_sqlite_functions(connection): connection.create_function("numbits_intersection", 2, numbits_intersection) connection.create_function("numbits_any_intersection", 2, numbits_any_intersection) connection.create_function("num_in_numbits", 2, num_in_numbits) + connection.create_function("numbits_to_nums", 1, lambda b: json.dumps(numbits_to_nums(b))) diff --git a/tests/test_numbits.py b/tests/test_numbits.py index eb094d2a..232d48d3 100644 --- a/tests/test_numbits.py +++ b/tests/test_numbits.py @@ -3,6 +3,7 @@ """Tests for coverage.numbits""" +import json import sqlite3 from hypothesis import example, given, settings @@ -156,3 +157,7 @@ class NumbitsSqliteFunctionTest(CoverageTest): res = self.cursor.execute("select id, num_in_numbits(12, numbits) from data order by id") answer = [is_in for (id, is_in) in res] self.assertEqual([1, 1, 1, 1, 0, 1, 0, 0, 0, 0], answer) + + def test_numbits_to_nums(self): + res = self.cursor.execute("select numbits_to_nums(?)", [nums_to_numbits([1, 2, 3])]) + self.assertEqual([1, 2, 3], json.loads(res.fetchone()[0])) |