Give user a sense of the severity, add basic tests
This commit is contained in:
parent
46b97acf95
commit
3640f163fc
2 changed files with 59 additions and 1 deletions
|
|
@ -60,7 +60,10 @@ def are_keys_unique(db: Path, table: str, col: str) -> bool:
|
|||
c.execute(f"SELECT COUNT( DISTINCT CAST({col} AS nvarchar(4000))), COUNT({col}) FROM {table};")
|
||||
results = c.fetchall()[0]
|
||||
conn.close()
|
||||
return bool(results[0] == results[1])
|
||||
res = bool(results[0] == results[1])
|
||||
if not res:
|
||||
print("Unique:", results[0], "All:", results[1])
|
||||
return res
|
||||
|
||||
|
||||
def _list_projects(path: Path) -> list[tuple[str, str]]:
|
||||
|
|
|
|||
55
tests/integrity_test.py
Normal file
55
tests/integrity_test.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import corrlib.integrity as integ
|
||||
import corrlib.find as find
|
||||
import datalad.api as dl
|
||||
import corrlib.initialization as cinit
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
def test_list_ensembles(tmp_path: Path) -> None:
|
||||
"""
|
||||
Check against the implementation in find to check if they are the same.
|
||||
"""
|
||||
os.mkdir(tmp_path / 'archive')
|
||||
os.mkdir(tmp_path / 'archive' / 'A')
|
||||
os.mkdir(tmp_path / 'archive' / 'B')
|
||||
os.mkdir(tmp_path / 'archive' / 'C')
|
||||
integ_results = integ._list_ensembles(tmp_path)
|
||||
assert len(integ_results) == 3
|
||||
find_results = find.list_ensembles(tmp_path)
|
||||
assert len(find_results) == 3
|
||||
for f,i in zip(find_results, integ_results):
|
||||
assert f == i
|
||||
|
||||
|
||||
def test_list_projects(tmp_path: Path) -> None:
|
||||
cinit.create(tmp_path)
|
||||
db = tmp_path / "backlogger.db"
|
||||
dl.unlock(str(db), dataset=str(tmp_path))
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
|
||||
customTags = ""
|
||||
owner = "owner"
|
||||
code = "sfcf"
|
||||
created_at = "today"
|
||||
updated_at = "today"
|
||||
|
||||
id = "asdf1"
|
||||
aliases = "a1,s1,d1,f1"
|
||||
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?,?,?,?,?,?,?)", (id, aliases, customTags, owner, code , created_at, updated_at))
|
||||
id = "asdf2"
|
||||
aliases = "a2,s2,d2,f2"
|
||||
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?,?,?,?,?,?,?)", (id, aliases, customTags, owner, code , created_at, updated_at))
|
||||
id = "asdf3"
|
||||
aliases = "a3,s3,d3,f3"
|
||||
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?,?,?,?,?,?,?)", (id, aliases, customTags, owner, code , created_at, updated_at))
|
||||
conn.commit()
|
||||
conn.close
|
||||
integ_results = integ._list_projects(tmp_path)
|
||||
assert len(integ_results) == 3
|
||||
find_results = find.list_projects(tmp_path)
|
||||
assert len(find_results) == 3
|
||||
for f,i in zip(find_results, integ_results):
|
||||
assert f == i
|
||||
Loading…
Add table
Add a link
Reference in a new issue