def test_csv_zipfile(pytestconfig, treedb): suffix = '-memory' if treedb.engine.file is None else '' suffix += pytestconfig.option.file_engine_tag path = treedb.csv_zipfile() assert path.name == f'treedb{suffix}.zip' assert_file_size_between(path, 1, 20)
def test_dump_sql(pytestconfig, treedb): suffix = '-memory' if treedb.engine.file is None else '' suffix += pytestconfig.option.file_engine_tag path = treedb.dump_sql() assert path.name == f'treedb{suffix}.sql.gz' assert_file_size_between(path, 1, 20)
def test_write_raw_csv(pytestconfig, treedb_raw): expected = RAW_CSV_SHA256.get(pytestconfig.option.glottolog_tag) suffix = '-memory' if treedb_raw.engine.file is None else '' suffix += pytestconfig.option.file_engine_tag path = treedb_raw.raw.write_raw_csv() assert path.name == f'treedb{suffix}.raw.csv.gz' assert_file_size_between(path, 1, 100) if expected is None: pass else: shasum = treedb_raw.sha256sum(path) assert shasum == expected
def test_write_csv(pytestconfig, treedb): expected = QUERY_HASH.get(pytestconfig.option.glottolog_tag) suffix = '-memory' if treedb.engine.file is None else '' suffix += pytestconfig.option.file_engine_tag path = treedb.write_csv() assert path.name == f'treedb{suffix}.query.csv' assert_file_size_between(path, 1, 30) if expected is None: pass else: shasum = treedb.sha256sum(path) assert shasum == expected
def test_backup(treedb): path = treedb.engine.file_with_suffix('.backup.sqlite3') engine = treedb.backup(path.name) assert engine.url.database == path.name assert_file_size_between(path, 10, 200) # SQLiteEngineProxy engine = treedb.engine.__class__(engine, future=treedb.engine.future) assert engine.file_exists() assert engine.file_mtime() assert engine.file_size() == path.stat().st_size assert 10 <= engine.file_size(as_megabytes=True) <= 200 assert len(engine.file_sha256()) == 64
def test_write_json_lines(pytestconfig, capsys, treedb, suffix, n=100): name_suffix = '-memory' if treedb.engine.file is None else '' name_suffix += pytestconfig.option.file_engine_tag args = ([f'treedb{name_suffix}.languoids{suffix}'] if suffix != 'jsonl.gz' else []) filepath, _ = treedb.write_languoids(*args) assert filepath.name == f'treedb{name_suffix}.languoids{suffix}' assert_file_size_between(filepath, 1, 200) if filepath.name.endswith('.jsonl'): with filepath.open(encoding='utf-8') as f: for line in get_assert_head(f, n=n): item = json.loads(line) assert_nonempty_dict(item) path = item['__path__'] assert isinstance(path, list) assert all(isinstance(p, str) for p in path) assert path assert all(path) languoid = item['languoid'] assert_nonempty_dict(languoid) for key in ('id', 'level', 'name'): assert_nonempty_string(languoid[key]) assert languoid['parent_id'] or languoid['parent_id'] is None assert languoid['level'] in ('family', 'language', 'dialect') out, err = capsys.readouterr() assert not out assert not err expected_checksum = CHECKSUM.get(pytestconfig.option.glottolog_tag) if expected_checksum is not None: assert treedb.sha256sum(filepath) == expected_checksum