-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_src_config.py
76 lines (63 loc) 路 2.29 KB
/
test_src_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
__author__ = "Vini Salazar"
__license__ = "MIT"
__maintainer__ = "Vini Salazar"
__url__ = "https://github.com/vinisalazar/bioprov"
__version__ = "0.1.18a"
"""
Testing for the Config module.
"""
import bioprov as bp
from bioprov.src.config import Config, BioProvDB
from os import environ, remove
from pathlib import Path
from tinydb import TinyDB, Query
from coolname import generate_slug
from tempfile import NamedTemporaryFile
def test_Config():
"""
Testing for the Config class
:return:
"""
config = Config()
assert config.env.env_dict == dict(environ.items())
assert config.user == config.env.user
assert config.genomes.exists()
assert config.data.exists()
assert str(config) == f"BioProv Config class set in {bp.src.config.__file__}"
assert type(len(config.db_all())) == int
# ProvStore properties
# getters
if Path(config.provstore_file).is_file():
# no cover because default is the file not existing
assert config.provstore_user is not None # no cover
assert config.provstore_token is not None # no cover
else:
assert config._provstore_user is None
assert config._provstore_token is None
# setters
config.provstore_user = None
config.provstore_token = None
with NamedTemporaryFile() as f:
config.provstore_file = f.name
config.create_provstore_file(user=generate_slug(2), token=generate_slug(4))
config.read_provstore_file()
def test_BioProvDB():
# Compare to TinyDB
db_path = Path(bp.__file__).parent.joinpath("db.json")
bp_db = BioProvDB(db_path)
tinydb_ = TinyDB(db_path)
assert len(bp_db) == len(tinydb_), "BioProvDB and TinyDB behaviour differs!"
assert isinstance(
bp_db, type(tinydb_)
), f"Type {type(bp_db)} should inherit or be an instance of {type(tinydb_)}"
# Try a Query
q = Query()
slug, slug_ = generate_slug(2), generate_slug(4)
results = bp_db.search(q[slug] == slug_)
assert results == [], f"Query result should be an empty list! Results: {results}"
# Create and erase database
non_db_path = "./." + generate_slug(4) + ".json"
non_db = BioProvDB(non_db_path)
non_db.clear_db(confirm=True)
assert len(non_db) == 0, f"Did not correctly erase the database at {non_db_path}"
remove(non_db_path)