Skip to content

Instantly share code, notes, and snippets.

@nedbat
Created January 13, 2020 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nedbat/0f64978393d50b1d0b89c4412b597d12 to your computer and use it in GitHub Desktop.
Save nedbat/0f64978393d50b1d0b89c4412b597d12 to your computer and use it in GitHub Desktop.
from coverage.debug import NoDebugging
from coverage.sqldata import SqliteDb
db = SqliteDb("cov.db", NoDebugging())
with db:
db.executescript("CREATE TABLE coverage_schema (\n -- One row, to record the version of the schema in this db.\n version integer\n);\n\nCREATE TABLE meta (\n -- Key-value pairs, to record metadata about the data\n key text,\n value text,\n unique (key)\n -- Keys:\n -- 'has_arcs' boolean -- Is this data recording branches?\n -- 'sys_argv' text -- The coverage command line that recorded the data.\n -- 'version' text -- The version of coverage.py that made the file.\n -- 'when' text -- Datetime when the file was created.\n);\n\nCREATE TABLE file (\n -- A row per file measured.\n id integer primary key,\n path text,\n unique (path)\n);\n\nCREATE TABLE context (\n -- A row per context measured.\n id integer primary key,\n context text,\n unique (context)\n);\n\nCREATE TABLE line_bits (\n -- If recording lines, a row per context per file executed.\n -- All of the line numbers for that file/context are in one numbits.\n file_id integer, -- foreign key to `file`.\n context_id integer, -- foreign key to `context`.\n numbits blob, -- see the numbits functions in coverage.numbits\n foreign key (file_id) references file (id),\n foreign key (context_id) references context (id),\n unique (file_id, context_id)\n);\n\nCREATE TABLE arc (\n -- If recording branches, a row per context per from/to line transition executed.\n file_id integer, -- foreign key to `file`.\n context_id integer, -- foreign key to `context`.\n fromno integer, -- line number jumped from.\n tono integer, -- line number jumped to.\n foreign key (file_id) references file (id),\n foreign key (context_id) references context (id),\n unique (file_id, context_id, fromno, tono)\n);\n\nCREATE TABLE tracer (\n -- A row per file indicating the tracer used for that file.\n file_id integer primary key,\n tracer text,\n foreign key (file_id) references file (id)\n);\n")
db.execute('insert into coverage_schema (version) values (?)', (7,))
db.executemany('insert into meta (key, value) values (?, ?)', [('sys_argv', "['/home/travis/nedbat/apprise-api/.tox/py36/lib/python3.6/site-packages/pytest/__main__.py', 'apprise_api']"), ('version', '17.0.3a0'), ('when', '2020-01-11 17:53:31')])
with db:
db.execute('insert into meta (key, value) values (?, ?)', ('has_arcs', '0'))
with db:
with db:
db.execute('select id from context where context = ?', ('',))
with db:
db.execute('insert into context (context) values (?)', ('',))
with db:
db.execute('insert or replace into file (path) values (?)', ('/home/travis/nedbat/apprise-api/.tox/py36/lib/python3.6/site-packages/pytest_cov/engine.py',))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment