Skip to content

Commit d66e5f0

Browse files
committed
Move over and simplify test for is_valid_coverage
1 parent 48c8cee commit d66e5f0

File tree

3 files changed

+45
-49
lines changed

3 files changed

+45
-49
lines changed

exasol/toolbox/nox/_artifacts.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
SECURITY_JSON = ".security.json"
2020

2121
ALL_FILES = {COVERAGE_FILE, LINT_JSON, LINT_TXT, SECURITY_JSON}
22-
22+
COVERAGE_TABLES = {"coverage_schema", "meta", "file", "line_bits"}
2323
LINT_JSON_ATTRIBUTES = {
2424
"type",
2525
"module",
@@ -114,20 +114,21 @@ def _is_valid_security_json(file: Path) -> bool:
114114
def _is_valid_coverage(path: Path) -> bool:
115115
try:
116116
conn = sqlite3.connect(path)
117+
cursor = conn.cursor()
117118
except sqlite3.Error as ex:
118119
return _handle_validation_error(
119120
path, f"database connection not possible, details: {ex}"
120121
)
121-
cursor = conn.cursor()
122122
try:
123123
actual_tables = set(
124124
cursor.execute("select name from sqlite_schema where type == 'table'")
125125
)
126126
except sqlite3.Error as ex:
127-
return _handle_validation_error(path, f"schema query not possible, details: {ex}")
128-
expected = {"coverage_schema", "meta", "file", "line_bits"}
129-
actual = {f[0] for f in actual_tables if (f[0] in expected)}
130-
missing = expected - actual
127+
return _handle_validation_error(
128+
path, f"schema query not possible, details: {ex}"
129+
)
130+
actual = {f[0] for f in actual_tables if (f[0] in COVERAGE_TABLES)}
131+
missing = COVERAGE_TABLES - actual
131132
if len(missing) > 0:
132133
return _handle_validation_error(
133134
path,

test/unit/lint_file_check_test.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

test/unit/nox/_artifacts_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import json
33
import re
4+
import sqlite3
45
from dataclasses import dataclass
56
from inspect import cleandoc
67
from pathlib import Path
@@ -15,11 +16,13 @@
1516
from exasol.toolbox.nox._artifacts import (
1617
ALL_FILES,
1718
COVERAGE_FILE,
19+
COVERAGE_TABLES,
1820
LINT_JSON,
1921
LINT_JSON_ATTRIBUTES,
2022
LINT_TXT,
2123
SECURITY_JSON,
2224
SECURITY_JSON_ATTRIBUTES,
25+
_is_valid_coverage,
2326
_is_valid_lint_json,
2427
_is_valid_lint_txt,
2528
_is_valid_security_json,
@@ -183,6 +186,41 @@ def test_missing_attributes(self, tmp_path, capsys, missing_attributes):
183186
)
184187

185188

189+
class TestIsValidCoverage:
190+
@staticmethod
191+
def _create_coverage_file(path: Path, tables: set) -> None:
192+
connection = sqlite3.connect(path)
193+
cursor = connection.cursor()
194+
for table in tables:
195+
cursor.execute(f"CREATE TABLE IF NOT EXISTS {table} (test INTEGER)")
196+
197+
def test_passes_when_as_expected(self, tmp_path):
198+
path = Path(tmp_path, COVERAGE_FILE)
199+
self._create_coverage_file(path, COVERAGE_TABLES)
200+
201+
result = _is_valid_coverage(path)
202+
203+
assert result
204+
205+
@pytest.mark.parametrize(
206+
"missing_table",
207+
[
208+
pytest.param({"coverage_schema"}, id="missing_coverage_schema"),
209+
],
210+
)
211+
def test_database_missing_tables(self, tmp_path, capsys, missing_table):
212+
tables = COVERAGE_TABLES - missing_table
213+
path = Path(tmp_path, COVERAGE_FILE)
214+
self._create_coverage_file(path, tables)
215+
216+
result = _is_valid_coverage(path)
217+
218+
assert not result
219+
assert (
220+
f"missing the following tables {missing_table}" in capsys.readouterr().out
221+
)
222+
223+
186224
class TestCopyArtifacts:
187225
@staticmethod
188226
def test_missing_files(tmp_path, capsys):

0 commit comments

Comments
 (0)