[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,8 +1,6 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""SQLite coverage data."""
from __future__ import annotations
import collections
@ -19,19 +17,29 @@ import sys
import textwrap
import threading
import zlib
from typing import Any
from typing import cast
from typing import Collection
from typing import Mapping
from typing import Sequence
from typing import (
cast, Any, Collection, Mapping,
Sequence,
)
from coverage.debug import NoDebugging, auto_repr
from coverage.exceptions import CoverageException, DataError
from coverage.debug import auto_repr
from coverage.debug import NoDebugging
from coverage.exceptions import CoverageException
from coverage.exceptions import DataError
from coverage.files import PathAliases
from coverage.misc import file_be_gone, isolate_module
from coverage.numbits import numbits_to_nums, numbits_union, nums_to_numbits
from coverage.misc import file_be_gone
from coverage.misc import isolate_module
from coverage.numbits import numbits_to_nums
from coverage.numbits import numbits_union
from coverage.numbits import nums_to_numbits
from coverage.sqlitedb import SqliteDb
from coverage.types import AnyCallable, FilePath, TArc, TDebugCtl, TLineNo, TWarnFn
from coverage.types import AnyCallable
from coverage.types import FilePath
from coverage.types import TArc
from coverage.types import TDebugCtl
from coverage.types import TLineNo
from coverage.types import TWarnFn
from coverage.version import __version__
os = isolate_module(os)
@ -112,15 +120,16 @@ CREATE TABLE tracer (
);
"""
def _locked(method: AnyCallable) -> AnyCallable:
"""A decorator for methods that should hold self._lock."""
@functools.wraps(method)
def _wrapped(self: CoverageData, *args: Any, **kwargs: Any) -> Any:
if self._debug.should("lock"):
self._debug.write(f"Locking {self._lock!r} for {method.__name__}")
if self._debug.should('lock'):
self._debug.write(f'Locking {self._lock!r} for {method.__name__}')
with self._lock:
if self._debug.should("lock"):
self._debug.write(f"Locked {self._lock!r} for {method.__name__}")
if self._debug.should('lock'):
self._debug.write(f'Locked {self._lock!r} for {method.__name__}')
return method(self, *args, **kwargs)
return _wrapped
@ -233,7 +242,7 @@ class CoverageData:
"""
self._no_disk = no_disk
self._basename = os.path.abspath(basename or ".coverage")
self._basename = os.path.abspath(basename or '.coverage')
self._suffix = suffix
self._warn = warn
self._debug = debug or NoDebugging()
@ -262,12 +271,12 @@ class CoverageData:
def _choose_filename(self) -> None:
"""Set self._filename based on inited attributes."""
if self._no_disk:
self._filename = ":memory:"
self._filename = ':memory:'
else:
self._filename = self._basename
suffix = filename_suffix(self._suffix)
if suffix:
self._filename += "." + suffix
self._filename += '.' + suffix
def _reset(self) -> None:
"""Reset our attributes."""
@ -281,8 +290,8 @@ class CoverageData:
def _open_db(self) -> None:
"""Open an existing db file, and read its metadata."""
if self._debug.should("dataio"):
self._debug.write(f"Opening data file {self._filename!r}")
if self._debug.should('dataio'):
self._debug.write(f'Opening data file {self._filename!r}')
self._dbs[threading.get_ident()] = SqliteDb(self._filename, self._debug)
self._read_db()
@ -290,10 +299,10 @@ class CoverageData:
"""Read the metadata from a database so that we are ready to use it."""
with self._dbs[threading.get_ident()] as db:
try:
row = db.execute_one("select version from coverage_schema")
row = db.execute_one('select version from coverage_schema')
assert row is not None
except Exception as exc:
if "no such table: coverage_schema" in str(exc):
if 'no such table: coverage_schema' in str(exc):
self._init_db(db)
else:
raise DataError(
@ -315,28 +324,28 @@ class CoverageData:
self._has_arcs = bool(int(row[0]))
self._has_lines = not self._has_arcs
with db.execute("select id, path from file") as cur:
with db.execute('select id, path from file') as cur:
for file_id, path in cur:
self._file_map[path] = file_id
def _init_db(self, db: SqliteDb) -> None:
"""Write the initial contents of the database."""
if self._debug.should("dataio"):
self._debug.write(f"Initing data file {self._filename!r}")
if self._debug.should('dataio'):
self._debug.write(f'Initing data file {self._filename!r}')
db.executescript(SCHEMA)
db.execute_void("insert into coverage_schema (version) values (?)", (SCHEMA_VERSION,))
db.execute_void('insert into coverage_schema (version) values (?)', (SCHEMA_VERSION,))
# When writing metadata, avoid information that will needlessly change
# the hash of the data file, unless we're debugging processes.
meta_data = [
("version", __version__),
('version', __version__),
]
if self._debug.should("process"):
if self._debug.should('process'):
meta_data.extend([
("sys_argv", str(getattr(sys, "argv", None))),
("when", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
('sys_argv', str(getattr(sys, 'argv', None))),
('when', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')),
])
db.executemany_void("insert or ignore into meta (key, value) values (?, ?)", meta_data)
db.executemany_void('insert or ignore into meta (key, value) values (?, ?)', meta_data)
def _connect(self) -> SqliteDb:
"""Get the SqliteDb object to use."""
@ -349,7 +358,7 @@ class CoverageData:
return False
try:
with self._connect() as con:
with con.execute("select * from file limit 1") as cur:
with con.execute('select * from file limit 1') as cur:
return bool(list(cur))
except CoverageException:
return False
@ -371,11 +380,11 @@ class CoverageData:
.. versionadded:: 5.0
"""
if self._debug.should("dataio"):
self._debug.write(f"Dumping data from data file {self._filename!r}")
if self._debug.should('dataio'):
self._debug.write(f'Dumping data from data file {self._filename!r}')
with self._connect() as con:
script = con.dump()
return b"z" + zlib.compress(script.encode("utf-8"))
return b'z' + zlib.compress(script.encode('utf-8'))
def loads(self, data: bytes) -> None:
"""Deserialize data from :meth:`dumps`.
@ -392,13 +401,13 @@ class CoverageData:
.. versionadded:: 5.0
"""
if self._debug.should("dataio"):
self._debug.write(f"Loading data into data file {self._filename!r}")
if data[:1] != b"z":
if self._debug.should('dataio'):
self._debug.write(f'Loading data into data file {self._filename!r}')
if data[:1] != b'z':
raise DataError(
f"Unrecognized serialization: {data[:40]!r} (head of {len(data)} bytes)",
f'Unrecognized serialization: {data[:40]!r} (head of {len(data)} bytes)',
)
script = zlib.decompress(data[1:]).decode("utf-8")
script = zlib.decompress(data[1:]).decode('utf-8')
self._dbs[threading.get_ident()] = db = SqliteDb(self._filename, self._debug)
with db:
db.executescript(script)
@ -415,7 +424,7 @@ class CoverageData:
if add:
with self._connect() as con:
self._file_map[filename] = con.execute_for_rowid(
"insert or replace into file (path) values (?)",
'insert or replace into file (path) values (?)',
(filename,),
)
return self._file_map.get(filename)
@ -425,7 +434,7 @@ class CoverageData:
assert context is not None
self._start_using()
with self._connect() as con:
row = con.execute_one("select id from context where context = ?", (context,))
row = con.execute_one('select id from context where context = ?', (context,))
if row is not None:
return cast(int, row[0])
else:
@ -441,21 +450,21 @@ class CoverageData:
.. versionadded:: 5.0
"""
if self._debug.should("dataop"):
self._debug.write(f"Setting coverage context: {context!r}")
if self._debug.should('dataop'):
self._debug.write(f'Setting coverage context: {context!r}')
self._current_context = context
self._current_context_id = None
def _set_context_id(self) -> None:
"""Use the _current_context to set _current_context_id."""
context = self._current_context or ""
context = self._current_context or ''
context_id = self._context_id(context)
if context_id is not None:
self._current_context_id = context_id
else:
with self._connect() as con:
self._current_context_id = con.execute_for_rowid(
"insert into context (context) values (?)",
'insert into context (context) values (?)',
(context,),
)
@ -484,13 +493,15 @@ class CoverageData:
{ filename: { line1, line2, ... }, ...}
"""
if self._debug.should("dataop"):
self._debug.write("Adding lines: %d files, %d lines total" % (
len(line_data), sum(len(lines) for lines in line_data.values()),
))
if self._debug.should("dataop2"):
if self._debug.should('dataop'):
self._debug.write(
'Adding lines: %d files, %d lines total' % (
len(line_data), sum(len(lines) for lines in line_data.values()),
),
)
if self._debug.should('dataop2'):
for filename, linenos in sorted(line_data.items()):
self._debug.write(f" {filename}: {linenos}")
self._debug.write(f' {filename}: {linenos}')
self._start_using()
self._choose_lines_or_arcs(lines=True)
if not line_data:
@ -500,15 +511,15 @@ class CoverageData:
for filename, linenos in line_data.items():
linemap = nums_to_numbits(linenos)
file_id = self._file_id(filename, add=True)
query = "select numbits from line_bits where file_id = ? and context_id = ?"
query = 'select numbits from line_bits where file_id = ? and context_id = ?'
with con.execute(query, (file_id, self._current_context_id)) as cur:
existing = list(cur)
if existing:
linemap = numbits_union(linemap, existing[0][0])
con.execute_void(
"insert or replace into line_bits " +
" (file_id, context_id, numbits) values (?, ?, ?)",
'insert or replace into line_bits ' +
' (file_id, context_id, numbits) values (?, ?, ?)',
(file_id, self._current_context_id, linemap),
)
@ -522,13 +533,15 @@ class CoverageData:
{ filename: { (l1,l2), (l1,l2), ... }, ...}
"""
if self._debug.should("dataop"):
self._debug.write("Adding arcs: %d files, %d arcs total" % (
len(arc_data), sum(len(arcs) for arcs in arc_data.values()),
))
if self._debug.should("dataop2"):
if self._debug.should('dataop'):
self._debug.write(
'Adding arcs: %d files, %d arcs total' % (
len(arc_data), sum(len(arcs) for arcs in arc_data.values()),
),
)
if self._debug.should('dataop2'):
for filename, arcs in sorted(arc_data.items()):
self._debug.write(f" {filename}: {arcs}")
self._debug.write(f' {filename}: {arcs}')
self._start_using()
self._choose_lines_or_arcs(arcs=True)
if not arc_data:
@ -541,8 +554,8 @@ class CoverageData:
file_id = self._file_id(filename, add=True)
data = [(file_id, self._current_context_id, fromno, tono) for fromno, tono in arcs]
con.executemany_void(
"insert or ignore into arc " +
"(file_id, context_id, fromno, tono) values (?, ?, ?, ?)",
'insert or ignore into arc ' +
'(file_id, context_id, fromno, tono) values (?, ?, ?, ?)',
data,
)
@ -551,11 +564,11 @@ class CoverageData:
assert lines or arcs
assert not (lines and arcs)
if lines and self._has_arcs:
if self._debug.should("dataop"):
if self._debug.should('dataop'):
self._debug.write("Error: Can't add line measurements to existing branch data")
raise DataError("Can't add line measurements to existing branch data")
if arcs and self._has_lines:
if self._debug.should("dataop"):
if self._debug.should('dataop'):
self._debug.write("Error: Can't add branch measurements to existing line data")
raise DataError("Can't add branch measurements to existing line data")
if not self._has_arcs and not self._has_lines:
@ -563,8 +576,8 @@ class CoverageData:
self._has_arcs = arcs
with self._connect() as con:
con.execute_void(
"insert or ignore into meta (key, value) values (?, ?)",
("has_arcs", str(int(arcs))),
'insert or ignore into meta (key, value) values (?, ?)',
('has_arcs', str(int(arcs))),
)
@_locked
@ -574,8 +587,8 @@ class CoverageData:
`file_tracers` is { filename: plugin_name, ... }
"""
if self._debug.should("dataop"):
self._debug.write("Adding file tracers: %d files" % (len(file_tracers),))
if self._debug.should('dataop'):
self._debug.write('Adding file tracers: %d files' % (len(file_tracers),))
if not file_tracers:
return
self._start_using()
@ -592,11 +605,11 @@ class CoverageData:
)
elif plugin_name:
con.execute_void(
"insert into tracer (file_id, tracer) values (?, ?)",
'insert into tracer (file_id, tracer) values (?, ?)',
(file_id, plugin_name),
)
def touch_file(self, filename: str, plugin_name: str = "") -> None:
def touch_file(self, filename: str, plugin_name: str = '') -> None:
"""Ensure that `filename` appears in the data, empty if needed.
`plugin_name` is the name of the plugin responsible for this file.
@ -610,10 +623,10 @@ class CoverageData:
`plugin_name` is the name of the plugin responsible for these files.
It is used to associate the right filereporter, etc.
"""
if self._debug.should("dataop"):
self._debug.write(f"Touching {filenames!r}")
if self._debug.should('dataop'):
self._debug.write(f'Touching {filenames!r}')
self._start_using()
with self._connect(): # Use this to get one transaction.
with self._connect(): # Use this to get one transaction.
if not self._has_arcs and not self._has_lines:
raise DataError("Can't touch files in an empty CoverageData")
@ -629,15 +642,15 @@ class CoverageData:
.. versionadded:: 7.2
"""
if self._debug.should("dataop"):
self._debug.write(f"Purging data for {filenames!r}")
if self._debug.should('dataop'):
self._debug.write(f'Purging data for {filenames!r}')
self._start_using()
with self._connect() as con:
if self._has_lines:
sql = "delete from line_bits where file_id=?"
sql = 'delete from line_bits where file_id=?'
elif self._has_arcs:
sql = "delete from arc where file_id=?"
sql = 'delete from arc where file_id=?'
else:
raise DataError("Can't purge files in an empty CoverageData")
@ -655,10 +668,12 @@ class CoverageData:
only when called directly from the test suite.
"""
if self._debug.should("dataop"):
self._debug.write("Updating with data from {!r}".format(
getattr(other_data, "_filename", "???"),
))
if self._debug.should('dataop'):
self._debug.write(
'Updating with data from {!r}'.format(
getattr(other_data, '_filename', '???'),
),
)
if self._has_lines and other_data._has_arcs:
raise DataError("Can't combine arc data with line data")
if self._has_arcs and other_data._has_lines:
@ -673,19 +688,19 @@ class CoverageData:
other_data.read()
with other_data._connect() as con:
# Get files data.
with con.execute("select path from file") as cur:
with con.execute('select path from file') as cur:
files = {path: aliases.map(path) for (path,) in cur}
# Get contexts data.
with con.execute("select context from context") as cur:
with con.execute('select context from context') as cur:
contexts = [context for (context,) in cur]
# Get arc data.
with con.execute(
"select file.path, context.context, arc.fromno, arc.tono " +
"from arc " +
"inner join file on file.id = arc.file_id " +
"inner join context on context.id = arc.context_id",
'select file.path, context.context, arc.fromno, arc.tono ' +
'from arc ' +
'inner join file on file.id = arc.file_id ' +
'inner join context on context.id = arc.context_id',
) as cur:
arcs = [
(files[path], context, fromno, tono)
@ -694,10 +709,10 @@ class CoverageData:
# Get line data.
with con.execute(
"select file.path, context.context, line_bits.numbits " +
"from line_bits " +
"inner join file on file.id = line_bits.file_id " +
"inner join context on context.id = line_bits.context_id",
'select file.path, context.context, line_bits.numbits ' +
'from line_bits ' +
'inner join file on file.id = line_bits.file_id ' +
'inner join context on context.id = line_bits.context_id',
) as cur:
lines: dict[tuple[str, str], bytes] = {}
for path, context, numbits in cur:
@ -708,25 +723,25 @@ class CoverageData:
# Get tracer data.
with con.execute(
"select file.path, tracer " +
"from tracer " +
"inner join file on file.id = tracer.file_id",
'select file.path, tracer ' +
'from tracer ' +
'inner join file on file.id = tracer.file_id',
) as cur:
tracers = {files[path]: tracer for (path, tracer) in cur}
with self._connect() as con:
assert con.con is not None
con.con.isolation_level = "IMMEDIATE"
con.con.isolation_level = 'IMMEDIATE'
# Get all tracers in the DB. Files not in the tracers are assumed
# to have an empty string tracer. Since Sqlite does not support
# full outer joins, we have to make two queries to fill the
# dictionary.
with con.execute("select path from file") as cur:
this_tracers = {path: "" for path, in cur}
with con.execute('select path from file') as cur:
this_tracers = {path: '' for path, in cur}
with con.execute(
"select file.path, tracer from tracer " +
"inner join file on file.id = tracer.file_id",
'select file.path, tracer from tracer ' +
'inner join file on file.id = tracer.file_id',
) as cur:
this_tracers.update({
aliases.map(path): tracer
@ -735,17 +750,17 @@ class CoverageData:
# Create all file and context rows in the DB.
con.executemany_void(
"insert or ignore into file (path) values (?)",
'insert or ignore into file (path) values (?)',
((file,) for file in files.values()),
)
with con.execute("select id, path from file") as cur:
with con.execute('select id, path from file') as cur:
file_ids = {path: id for id, path in cur}
self._file_map.update(file_ids)
con.executemany_void(
"insert or ignore into context (context) values (?)",
'insert or ignore into context (context) values (?)',
((context,) for context in contexts),
)
with con.execute("select id, context from context") as cur:
with con.execute('select id, context from context') as cur:
context_ids = {context: id for id, context in cur}
# Prepare tracers and fail, if a conflict is found.
@ -754,7 +769,7 @@ class CoverageData:
tracer_map = {}
for path in files.values():
this_tracer = this_tracers.get(path)
other_tracer = tracers.get(path, "")
other_tracer = tracers.get(path, '')
# If there is no tracer, there is always the None tracer.
if this_tracer is not None and this_tracer != other_tracer:
raise DataError(
@ -774,10 +789,10 @@ class CoverageData:
# Get line data.
with con.execute(
"select file.path, context.context, line_bits.numbits " +
"from line_bits " +
"inner join file on file.id = line_bits.file_id " +
"inner join context on context.id = line_bits.context_id",
'select file.path, context.context, line_bits.numbits ' +
'from line_bits ' +
'inner join file on file.id = line_bits.file_id ' +
'inner join context on context.id = line_bits.context_id',
) as cur:
for path, context, numbits in cur:
key = (aliases.map(path), context)
@ -790,24 +805,24 @@ class CoverageData:
# Write the combined data.
con.executemany_void(
"insert or ignore into arc " +
"(file_id, context_id, fromno, tono) values (?, ?, ?, ?)",
'insert or ignore into arc ' +
'(file_id, context_id, fromno, tono) values (?, ?, ?, ?)',
arc_rows,
)
if lines:
self._choose_lines_or_arcs(lines=True)
con.execute_void("delete from line_bits")
con.execute_void('delete from line_bits')
con.executemany_void(
"insert into line_bits " +
"(file_id, context_id, numbits) values (?, ?, ?)",
'insert into line_bits ' +
'(file_id, context_id, numbits) values (?, ?, ?)',
[
(file_ids[file], context_ids[context], numbits)
for (file, context), numbits in lines.items()
],
)
con.executemany_void(
"insert or ignore into tracer (file_id, tracer) values (?, ?)",
'insert or ignore into tracer (file_id, tracer) values (?, ?)',
((file_ids[filename], tracer) for filename, tracer in tracer_map.items()),
)
@ -826,16 +841,16 @@ class CoverageData:
self._reset()
if self._no_disk:
return
if self._debug.should("dataio"):
self._debug.write(f"Erasing data file {self._filename!r}")
if self._debug.should('dataio'):
self._debug.write(f'Erasing data file {self._filename!r}')
file_be_gone(self._filename)
if parallel:
data_dir, local = os.path.split(self._filename)
local_abs_path = os.path.join(os.path.abspath(data_dir), local)
pattern = glob.escape(local_abs_path) + ".*"
pattern = glob.escape(local_abs_path) + '.*'
for filename in glob.glob(pattern):
if self._debug.should("dataio"):
self._debug.write(f"Erasing parallel data file {filename!r}")
if self._debug.should('dataio'):
self._debug.write(f'Erasing parallel data file {filename!r}')
file_be_gone(filename)
def read(self) -> None:
@ -880,7 +895,7 @@ class CoverageData:
"""
self._start_using()
with self._connect() as con:
with con.execute("select distinct(context) from context") as cur:
with con.execute('select distinct(context) from context') as cur:
contexts = {row[0] for row in cur}
return contexts
@ -897,10 +912,10 @@ class CoverageData:
file_id = self._file_id(filename)
if file_id is None:
return None
row = con.execute_one("select tracer from tracer where file_id = ?", (file_id,))
row = con.execute_one('select tracer from tracer where file_id = ?', (file_id,))
if row is not None:
return row[0] or ""
return "" # File was measured, but no tracer associated.
return row[0] or ''
return '' # File was measured, but no tracer associated.
def set_query_context(self, context: str) -> None:
"""Set a context for subsequent querying.
@ -915,7 +930,7 @@ class CoverageData:
"""
self._start_using()
with self._connect() as con:
with con.execute("select id from context where context = ?", (context,)) as cur:
with con.execute('select id from context where context = ?', (context,)) as cur:
self._query_context_ids = [row[0] for row in cur.fetchall()]
def set_query_contexts(self, contexts: Sequence[str] | None) -> None:
@ -933,8 +948,8 @@ class CoverageData:
self._start_using()
if contexts:
with self._connect() as con:
context_clause = " or ".join(["context regexp ?"] * len(contexts))
with con.execute("select id from context where " + context_clause, contexts) as cur:
context_clause = ' or '.join(['context regexp ?'] * len(contexts))
with con.execute('select id from context where ' + context_clause, contexts) as cur:
self._query_context_ids = [row[0] for row in cur.fetchall()]
else:
self._query_context_ids = None
@ -961,11 +976,11 @@ class CoverageData:
if file_id is None:
return None
else:
query = "select numbits from line_bits where file_id = ?"
query = 'select numbits from line_bits where file_id = ?'
data = [file_id]
if self._query_context_ids is not None:
ids_array = ", ".join("?" * len(self._query_context_ids))
query += " and context_id in (" + ids_array + ")"
ids_array = ', '.join('?' * len(self._query_context_ids))
query += ' and context_id in (' + ids_array + ')'
data += self._query_context_ids
with con.execute(query, data) as cur:
bitmaps = list(cur)
@ -997,11 +1012,11 @@ class CoverageData:
if file_id is None:
return None
else:
query = "select distinct fromno, tono from arc where file_id = ?"
query = 'select distinct fromno, tono from arc where file_id = ?'
data = [file_id]
if self._query_context_ids is not None:
ids_array = ", ".join("?" * len(self._query_context_ids))
query += " and context_id in (" + ids_array + ")"
ids_array = ', '.join('?' * len(self._query_context_ids))
query += ' and context_id in (' + ids_array + ')'
data += self._query_context_ids
with con.execute(query, data) as cur:
return list(cur)
@ -1024,14 +1039,14 @@ class CoverageData:
lineno_contexts_map = collections.defaultdict(set)
if self.has_arcs():
query = (
"select arc.fromno, arc.tono, context.context " +
"from arc, context " +
"where arc.file_id = ? and arc.context_id = context.id"
'select arc.fromno, arc.tono, context.context ' +
'from arc, context ' +
'where arc.file_id = ? and arc.context_id = context.id'
)
data = [file_id]
if self._query_context_ids is not None:
ids_array = ", ".join("?" * len(self._query_context_ids))
query += " and arc.context_id in (" + ids_array + ")"
ids_array = ', '.join('?' * len(self._query_context_ids))
query += ' and arc.context_id in (' + ids_array + ')'
data += self._query_context_ids
with con.execute(query, data) as cur:
for fromno, tono, context in cur:
@ -1041,14 +1056,14 @@ class CoverageData:
lineno_contexts_map[tono].add(context)
else:
query = (
"select l.numbits, c.context from line_bits l, context c " +
"where l.context_id = c.id " +
"and file_id = ?"
'select l.numbits, c.context from line_bits l, context c ' +
'where l.context_id = c.id ' +
'and file_id = ?'
)
data = [file_id]
if self._query_context_ids is not None:
ids_array = ", ".join("?" * len(self._query_context_ids))
query += " and l.context_id in (" + ids_array + ")"
ids_array = ', '.join('?' * len(self._query_context_ids))
query += ' and l.context_id in (' + ids_array + ')'
data += self._query_context_ids
with con.execute(query, data) as cur:
for numbits, context in cur:
@ -1064,17 +1079,17 @@ class CoverageData:
Returns a list of (key, value) pairs.
"""
with SqliteDb(":memory:", debug=NoDebugging()) as db:
with db.execute("pragma temp_store") as cur:
with SqliteDb(':memory:', debug=NoDebugging()) as db:
with db.execute('pragma temp_store') as cur:
temp_store = [row[0] for row in cur]
with db.execute("pragma compile_options") as cur:
with db.execute('pragma compile_options') as cur:
copts = [row[0] for row in cur]
copts = textwrap.wrap(", ".join(copts), width=75)
copts = textwrap.wrap(', '.join(copts), width=75)
return [
("sqlite3_sqlite_version", sqlite3.sqlite_version),
("sqlite3_temp_store", temp_store),
("sqlite3_compile_options", copts),
('sqlite3_sqlite_version', sqlite3.sqlite_version),
('sqlite3_temp_store', temp_store),
('sqlite3_compile_options', copts),
]
@ -1095,8 +1110,8 @@ def filename_suffix(suffix: str | bool | None) -> str | None:
# if the process forks.
die = random.Random(os.urandom(8))
letters = string.ascii_uppercase + string.ascii_lowercase
rolls = "".join(die.choice(letters) for _ in range(6))
suffix = f"{socket.gethostname()}.{os.getpid()}.X{rolls}x"
rolls = ''.join(die.choice(letters) for _ in range(6))
suffix = f'{socket.gethostname()}.{os.getpid()}.X{rolls}x'
elif suffix is False:
suffix = None
return suffix