add typing for tests
This commit is contained in:
parent
15bf399a89
commit
14d19ce9dd
5 changed files with 19 additions and 17 deletions
|
|
@ -2,18 +2,19 @@ from typer.testing import CliRunner
|
||||||
from corrlib.cli import app
|
from corrlib.cli import app
|
||||||
import os
|
import os
|
||||||
import sqlite3 as sql
|
import sqlite3 as sql
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
|
|
||||||
|
|
||||||
def test_version():
|
def test_version() -> None:
|
||||||
result = runner.invoke(app, ["--version"])
|
result = runner.invoke(app, ["--version"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "corrlib" in result.output
|
assert "corrlib" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_init_folders(tmp_path):
|
def test_init_folders(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
@ -21,7 +22,7 @@ def test_init_folders(tmp_path):
|
||||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||||
|
|
||||||
|
|
||||||
def test_init_db(tmp_path):
|
def test_init_db(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
@ -37,7 +38,7 @@ def test_init_db(tmp_path):
|
||||||
table_names = [table[0] for table in tables]
|
table_names = [table[0] for table in tables]
|
||||||
for expected_table in expected_tables:
|
for expected_table in expected_tables:
|
||||||
assert expected_table in table_names
|
assert expected_table in table_names
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM projects;")
|
cursor.execute("SELECT * FROM projects;")
|
||||||
projects = cursor.fetchall()
|
projects = cursor.fetchall()
|
||||||
assert len(projects) == 0
|
assert len(projects) == 0
|
||||||
|
|
@ -60,7 +61,7 @@ def test_init_db(tmp_path):
|
||||||
project_column_names = [col[1] for col in project_columns]
|
project_column_names = [col[1] for col in project_columns]
|
||||||
for expected_col in expected_project_columns:
|
for expected_col in expected_project_columns:
|
||||||
assert expected_col in project_column_names
|
assert expected_col in project_column_names
|
||||||
|
|
||||||
cursor.execute("PRAGMA table_info('backlogs');")
|
cursor.execute("PRAGMA table_info('backlogs');")
|
||||||
backlog_columns = cursor.fetchall()
|
backlog_columns = cursor.fetchall()
|
||||||
expected_backlog_columns = [
|
expected_backlog_columns = [
|
||||||
|
|
@ -81,7 +82,7 @@ def test_init_db(tmp_path):
|
||||||
assert expected_col in backlog_column_names
|
assert expected_col in backlog_column_names
|
||||||
|
|
||||||
|
|
||||||
def test_list(tmp_path):
|
def test_list(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import corrlib.toml as t
|
import corrlib.toml as t
|
||||||
|
|
||||||
|
|
||||||
def test_toml_check_measurement_data():
|
def test_toml_check_measurement_data() -> None:
|
||||||
measurements = {
|
measurements = {
|
||||||
"a":
|
"a":
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import corrlib.input.sfcf as input
|
import corrlib.input.sfcf as input
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def test_get_specs():
|
def test_get_specs() -> None:
|
||||||
parameters = {
|
parameters = {
|
||||||
'crr': [
|
'crr': [
|
||||||
'f_P', 'f_A'
|
'f_P', 'f_A'
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,23 @@
|
||||||
import corrlib.initialization as init
|
import corrlib.initialization as init
|
||||||
import os
|
import os
|
||||||
import sqlite3 as sql
|
import sqlite3 as sql
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
def test_init_folders(tmp_path):
|
def test_init_folders(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
init.create(str(dataset_path))
|
init.create(str(dataset_path))
|
||||||
assert os.path.exists(str(dataset_path))
|
assert os.path.exists(str(dataset_path))
|
||||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||||
|
|
||||||
|
|
||||||
def test_init_folders_no_tracker(tmp_path):
|
def test_init_folders_no_tracker(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
init.create(str(dataset_path), tracker="None")
|
init.create(str(dataset_path), tracker="None")
|
||||||
assert os.path.exists(str(dataset_path))
|
assert os.path.exists(str(dataset_path))
|
||||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||||
|
|
||||||
|
|
||||||
def test_init_config(tmp_path):
|
def test_init_config(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
init.create(str(dataset_path), tracker="None")
|
init.create(str(dataset_path), tracker="None")
|
||||||
config_path = dataset_path / ".corrlib"
|
config_path = dataset_path / ".corrlib"
|
||||||
|
|
@ -34,7 +35,7 @@ def test_init_config(tmp_path):
|
||||||
assert config.get("paths", "import_scripts_path") == "import_scripts"
|
assert config.get("paths", "import_scripts_path") == "import_scripts"
|
||||||
|
|
||||||
|
|
||||||
def test_init_db(tmp_path):
|
def test_init_db(tmp_path: Path) -> None:
|
||||||
dataset_path = tmp_path / "test_dataset"
|
dataset_path = tmp_path / "test_dataset"
|
||||||
init.create(str(dataset_path))
|
init.create(str(dataset_path))
|
||||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,29 @@
|
||||||
from corrlib import tools as tl
|
from corrlib import tools as tl
|
||||||
|
|
||||||
|
|
||||||
def test_m2k():
|
def test_m2k() -> None:
|
||||||
for m in [0.1, 0.5, 1.0]:
|
for m in [0.1, 0.5, 1.0]:
|
||||||
expected_k = 1 / (2 * m + 8)
|
expected_k = 1 / (2 * m + 8)
|
||||||
assert tl.m2k(m) == expected_k
|
assert tl.m2k(m) == expected_k
|
||||||
|
|
||||||
|
|
||||||
def test_k2m():
|
def test_k2m() -> None:
|
||||||
for m in [0.1, 0.5, 1.0]:
|
for m in [0.1, 0.5, 1.0]:
|
||||||
assert tl.k2m(m) == (1/(2*m))-4
|
assert tl.k2m(m) == (1/(2*m))-4
|
||||||
|
|
||||||
|
|
||||||
def test_k2m_m2k():
|
def test_k2m_m2k() -> None:
|
||||||
for m in [0.1, 0.5, 1.0]:
|
for m in [0.1, 0.5, 1.0]:
|
||||||
k = tl.m2k(m)
|
k = tl.m2k(m)
|
||||||
m_converted = tl.k2m(k)
|
m_converted = tl.k2m(k)
|
||||||
assert abs(m - m_converted) < 1e-9
|
assert abs(m - m_converted) < 1e-9
|
||||||
|
|
||||||
|
|
||||||
def test_str2list():
|
def test_str2list() -> None:
|
||||||
assert tl.str2list("a,b,c") == ["a", "b", "c"]
|
assert tl.str2list("a,b,c") == ["a", "b", "c"]
|
||||||
assert tl.str2list("1,2,3") == ["1", "2", "3"]
|
assert tl.str2list("1,2,3") == ["1", "2", "3"]
|
||||||
|
|
||||||
|
|
||||||
def test_list2str():
|
def test_list2str() -> None:
|
||||||
assert tl.list2str(["a", "b", "c"]) == "a,b,c"
|
assert tl.list2str(["a", "b", "c"]) == "a,b,c"
|
||||||
assert tl.list2str(["1", "2", "3"]) == "1,2,3"
|
assert tl.list2str(["1", "2", "3"]) == "1,2,3"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue