def conn(): """Initialize a memory DB with test data and return a connexion on this DB""" conn = sql.get_sql_connection(":memory:") sql.create_project(conn, "test", "hg19") assert table_exists(conn, "projects"), "cannot create table projects" sql.create_table_fields(conn) assert table_exists(conn, "fields"), "cannot create table fields" sql.insert_many_fields(conn, FIELDS) assert table_count(conn, "fields") == len(FIELDS), "cannot insert many fields" sql.create_table_selections(conn) assert table_exists(conn, "selections"), "cannot create table selections" sql.create_table_annotations( conn, sql.get_field_by_category(conn, "annotations")) assert table_exists(conn, "annotations"), "cannot create table annotations" sql.create_table_samples(conn, sql.get_field_by_category(conn, "samples")) assert table_exists(conn, "samples"), "cannot create table samples" sql.insert_many_samples(conn, SAMPLES) sql.create_table_variants(conn, sql.get_field_by_category(conn, "variants")) assert table_exists(conn, "variants"), "cannot create table variants" sql.insert_many_variants(conn, VARIANTS) sql.create_table_wordsets(conn) assert table_exists(conn, "wordsets"), "cannot create table sets" return conn
def test_create_db(reader): conn = sqlite3.connect(":memory:") sql.create_table_fields(conn) sql.insert_many_fields(conn, reader.get_fields()) assert len(list(sql.get_fields(conn))) == len(list(reader.get_fields())) sql.create_table_samples(conn, reader.get_fields_by_category("samples")) sql.insert_many_samples(conn, reader.get_samples()) assert len(list(sql.get_samples(conn))) == len(list(reader.get_samples())) sql.create_table_annotations(conn, reader.get_fields_by_category("annotations")) sql.create_table_variants(conn, reader.get_fields_by_category("variants")) sql.create_table_selections(conn) sql.insert_many_variants(conn, reader.get_variants()) # count variant with annotation variant_count = len(list(reader.get_variants())) assert sql.get_variants_count(conn) == variant_count