summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-08-26 09:44:22 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-08-26 09:48:28 -0400
commit3ab1c50f23c47721bd2ccb025c0f0a8b3d2b16c9 (patch)
treeaeca089b8c1716cbce2a80a653f9c31bc6b16c9c /tests
parent86508459edcf8f85a394413aec4cf909e709981f (diff)
downloadpython-coveragepy-git-3ab1c50f23c47721bd2ccb025c0f0a8b3d2b16c9.tar.gz
Tests of the schema checking
Diffstat (limited to 'tests')
-rw-r--r--tests/coveragetest.py6
-rw-r--r--tests/test_data.py42
-rw-r--r--tests/test_process.py4
3 files changed, 37 insertions, 15 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 6e308718..15c61ece 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -97,9 +97,9 @@ class CoverageTest(
self.last_command_output = None
self.last_module_name = None
- def skip_unless_data_storage_is_json(self):
- if STORAGE != "json":
- self.skipTest("Not using JSON for data storage")
+ def skip_unless_data_storage_is(self, storage):
+ if STORAGE != storage:
+ self.skipTest("Not using {} for data storage".format(storage))
def clean_local_file_imports(self):
"""Clean up the results of calls to `import_local_file`.
diff --git a/tests/test_data.py b/tests/test_data.py
index 1e6ce027..15da32e5 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -8,6 +8,7 @@ import json
import os
import os.path
import re
+import sqlite3
import mock
@@ -190,7 +191,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
self.assertIsNone(covdata.lines('no_such_file.py'))
def test_run_info(self):
- self.skip_unless_data_storage_is_json()
+ self.skip_unless_data_storage_is("json")
covdata = CoverageData()
self.assertEqual(covdata.run_infos(), [])
covdata.add_run_info(hello="there")
@@ -269,7 +270,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
self.assertEqual(covdata3.run_infos(), [])
def test_update_run_info(self):
- self.skip_unless_data_storage_is_json()
+ self.skip_unless_data_storage_is("json")
covdata1 = CoverageData()
covdata1.add_arcs(ARCS_3)
covdata1.add_run_info(hello="there", count=17)
@@ -475,15 +476,36 @@ class CoverageDataTestInTempDir(DataTestHelpers, CoverageTest):
covdata.read()
self.assertFalse(covdata)
- if STORAGE == "json":
- self.make_file("misleading.dat", CoverageData._GO_AWAY + " this isn't JSON")
- with self.assertRaisesRegex(CoverageException, msg.format("misleading.dat")):
- covdata = CoverageData("misleading.dat")
- covdata.read()
- self.assertFalse(covdata)
+ def test_read_json_errors(self):
+ self.skip_unless_data_storage_is("json")
+ self.make_file("misleading.dat", CoverageData._GO_AWAY + " this isn't JSON")
+ msg = r"Couldn't .* '.*[/\\]{0}': \S+"
+ with self.assertRaisesRegex(CoverageException, msg.format("misleading.dat")):
+ covdata = CoverageData("misleading.dat")
+ covdata.read()
+ self.assertFalse(covdata)
+
+ def test_read_sql_errors(self):
+ self.skip_unless_data_storage_is("sql")
+ with sqlite3.connect("wrong_schema.db") as con:
+ con.execute("create table coverage_schema (version integer)")
+ con.execute("insert into coverage_schema (version) values (99)")
+ msg = r"Couldn't .* '.*[/\\]{0}': wrong schema: 99 instead of \d+".format("wrong_schema.db")
+ with self.assertRaisesRegex(CoverageException, msg):
+ covdata = CoverageData("wrong_schema.db")
+ covdata.read()
+ self.assertFalse(covdata)
+
+ with sqlite3.connect("no_schema.db") as con:
+ con.execute("create table foobar (baz text)")
+ msg = r"Couldn't .* '.*[/\\]{0}': \S+".format("no_schema.db")
+ with self.assertRaisesRegex(CoverageException, msg):
+ covdata = CoverageData("no_schema.db")
+ covdata.read()
+ self.assertFalse(covdata)
def test_debug_main(self):
- self.skip_unless_data_storage_is_json()
+ self.skip_unless_data_storage_is("json")
covdata1 = CoverageData(".coverage")
covdata1.add_lines(LINES_1)
covdata1.write()
@@ -660,7 +682,7 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
def read_json_data_file(self, fname):
"""Read a JSON data file for testing the JSON directly."""
- self.skip_unless_data_storage_is_json()
+ self.skip_unless_data_storage_is("json")
with open(fname, 'r') as fdata:
go_away = fdata.read(len(CoverageData._GO_AWAY))
self.assertEqual(go_away, CoverageData._GO_AWAY)
diff --git a/tests/test_process.py b/tests/test_process.py
index 49919b0f..1ac18ffe 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -516,7 +516,7 @@ class ProcessTest(CoverageTest):
if not hasattr(os, 'fork'):
self.skipTest("Can't test os.fork since it doesn't exist.")
# See https://nedbatchelder.com/blog/201808/sqlite_data_storage_for_coveragepy.html
- self.skip_unless_data_storage_is_json()
+ self.skip_unless_data_storage_is("json")
self.make_file("fork.py", """\
import os
@@ -655,7 +655,7 @@ class ProcessTest(CoverageTest):
if env.PYPY and env.PY3 and env.PYPYVERSION[:3] == (5, 10, 0): # pragma: obscure
# https://bitbucket.org/pypy/pypy/issues/2729/pypy3-510-incorrectly-decodes-astral-plane
self.skipTest("Avoid incorrect decoding astral plane JSON chars")
- self.skip_unless_data_storage_is_json()
+ self.skip_unless_data_storage_is("json")
self.make_file(".coveragerc", """\
[run]