-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_command_ingest.py
91 lines (57 loc) · 2.5 KB
/
test_command_ingest.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import pytest
import pandas as pd
import click.testing
import backports.tempfile
from sqlalchemy import create_engine
import cytominer_database.command
@pytest.fixture(scope="function")
def runner():
return click.testing.CliRunner()
def test_help(runner):
result = runner.invoke(cytominer_database.command.command, ["ingest", "--help"])
assert "ingest [OPTIONS] SOURCE TARGET" in result.output
def test_run(dataset, runner):
opts = ["ingest"]
if dataset["config"]:
opts += ["--config-file", os.path.join(dataset["data_dir"], dataset["config"])]
if dataset["munge"]:
opts += ["--munge"]
else:
opts += ["--no-munge"]
opts += [dataset["data_dir"]]
with backports.tempfile.TemporaryDirectory() as temp_dir:
sqlite_file = os.path.join(temp_dir, "test.db")
opts += ["sqlite:///{}".format(sqlite_file)]
result = runner.invoke(cytominer_database.command.command, opts)
assert result.exit_code == 0, result.output
for blob in dataset["ingest"]:
table_name = blob["table"].capitalize()
target = "sqlite:///{}::{}".format(str(sqlite_file), table_name)
engine = create_engine(target)
df = pd.read_sql(target, con=engine, index_col=0)
assert df.shape[0] == blob["nrows"]
assert df.shape[1] == blob["ncols"] + 1
if table_name.lower() != "image":
assert df.groupby(["TableNumber", "ImageNumber"]).size().sum() == blob["nrows"]
def test_run_defaults(cellpainting, runner):
opts = ["ingest"]
if cellpainting["munge"]:
opts += ["--munge"]
else:
opts += ["--no-munge"]
opts += [cellpainting["data_dir"]]
with backports.tempfile.TemporaryDirectory() as temp_dir:
sqlite_file = os.path.join(temp_dir, "test.db")
opts += ["sqlite:///{}".format(sqlite_file)]
result = runner.invoke(cytominer_database.command.command, opts)
assert result.exit_code == 0
for blob in cellpainting["ingest"]:
table_name = blob["table"].capitalize()
target = "sqlite:///{}::{}".format(str(sqlite_file), table_name)
engine = create_engine(target)
df = pd.read_sql(target, con=engine, index_col=0)
assert df.shape[0] == blob["nrows"]
assert df.shape[1] == blob["ncols"] + 1
if table_name.lower() != "image":
assert df.groupby(["TableNumber", "ImageNumber"]).size().sum() == blob["nrows"]