Merge pull request 'test/more' (#9) from test/more into develop
Reviewed-on: https://www.kuhl-mann.de/git/git/jkuhl/corrlib/pulls/9
This commit is contained in:
commit
04559cc95f
15 changed files with 1201 additions and 42 deletions
6
.github/workflows/pytest.yaml
vendored
6
.github/workflows/pytest.yaml
vendored
|
|
@ -20,6 +20,10 @@ jobs:
|
|||
env:
|
||||
UV_CACHE_DIR: /tmp/.uv-cache
|
||||
steps:
|
||||
- name: Install git-annex
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git-annex
|
||||
- name: Check out the repository
|
||||
uses: https://github.com/RouxAntoine/checkout@v4.1.8
|
||||
with:
|
||||
|
|
@ -32,4 +36,4 @@ jobs:
|
|||
- name: Install corrlib
|
||||
run: uv sync --locked --all-extras --dev --python ${{ matrix.python-version }}
|
||||
- name: Run tests
|
||||
run: uv run pytest tests
|
||||
run: uv run pytest --cov=corrlib tests
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ test.ipynb
|
|||
.vscode
|
||||
.venv
|
||||
.pytest_cache
|
||||
.coverage
|
||||
|
|
@ -15,8 +15,10 @@ For now, we are interested in collecting primary IObservables only, as these are
|
|||
|
||||
__app_name__ = "corrlib"
|
||||
|
||||
from .main import *
|
||||
from .import input as input
|
||||
from .initialization import *
|
||||
from .meas_io import *
|
||||
from .find import *
|
||||
from .initialization import create as create
|
||||
from .meas_io import load_record as load_record
|
||||
from .meas_io import load_records as load_records
|
||||
from .find import find_project as find_project
|
||||
from .find import find_record as find_record
|
||||
from .find import list_projects as list_projects
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from .tools import str2list
|
|||
from .main import update_aliases
|
||||
from .meas_io import drop_cache as mio_drop_cache
|
||||
import os
|
||||
from importlib.metadata import version, PackageNotFoundError
|
||||
from importlib.metadata import version
|
||||
|
||||
|
||||
app = typer.Typer()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import sqlite3
|
||||
import datalad.api as dl
|
||||
import os
|
||||
import json
|
||||
import pandas as pd
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
Import functions for different codes.
|
||||
"""
|
||||
|
||||
from . import sfcf
|
||||
from . import openQCD
|
||||
from . import implementations
|
||||
from . import sfcf as sfcf
|
||||
from . import openQCD as openQCD
|
||||
from . import implementations as implementations
|
||||
|
|
|
|||
|
|
@ -26,4 +26,3 @@ def get_file(path: str, file: str):
|
|||
print("Downloading data...")
|
||||
dl.get(os.path.join(path, file), dataset=path)
|
||||
print("> downloaded file")
|
||||
|
||||
|
|
@ -1 +1,34 @@
|
|||
__version__ = "0.2.3"
|
||||
# file generated by setuptools-scm
|
||||
# don't change, don't track in version control
|
||||
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"__version_tuple__",
|
||||
"version",
|
||||
"version_tuple",
|
||||
"__commit_id__",
|
||||
"commit_id",
|
||||
]
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
|
||||
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
||||
COMMIT_ID = Union[str, None]
|
||||
else:
|
||||
VERSION_TUPLE = object
|
||||
COMMIT_ID = object
|
||||
|
||||
version: str
|
||||
__version__: str
|
||||
__version_tuple__: VERSION_TUPLE
|
||||
version_tuple: VERSION_TUPLE
|
||||
commit_id: COMMIT_ID
|
||||
__commit_id__: COMMIT_ID
|
||||
|
||||
__version__ = version = '0.2.4.dev14+g602324f84.d20251202'
|
||||
__version_tuple__ = version_tuple = (0, 2, 4, 'dev14', 'g602324f84.d20251202')
|
||||
|
||||
__commit_id__ = commit_id = 'g602324f84'
|
||||
|
|
|
|||
|
|
@ -27,10 +27,19 @@ include = ["corrlib", "corrlib.*"]
|
|||
write_to = "corrlib/version.py"
|
||||
|
||||
[tool.ruff.lint]
|
||||
ignore = ["F403"]
|
||||
ignore = ["E501"]
|
||||
extend-select = [
|
||||
"YTT",
|
||||
"E",
|
||||
"W",
|
||||
"F",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"mypy>=1.19.0",
|
||||
"pytest>=9.0.1",
|
||||
"pytest-cov>=7.0.0",
|
||||
"pytest-pretty>=1.3.0",
|
||||
"ruff>=0.14.7",
|
||||
]
|
||||
|
|
|
|||
91
tests/cli_test.py
Normal file
91
tests/cli_test.py
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
from typer.testing import CliRunner
|
||||
from corrlib.cli import app
|
||||
import os
|
||||
import sqlite3 as sql
|
||||
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_version():
|
||||
result = runner.invoke(app, ["--version"])
|
||||
assert result.exit_code == 0
|
||||
assert "corrlib" in result.output
|
||||
|
||||
|
||||
def test_init_folders(tmp_path):
|
||||
dataset_path = tmp_path / "test_dataset"
|
||||
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(str(dataset_path))
|
||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||
|
||||
|
||||
def test_init_db(tmp_path):
|
||||
dataset_path = tmp_path / "test_dataset"
|
||||
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||
conn = sql.connect(str(dataset_path / "backlogger.db"))
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
||||
tables = cursor.fetchall()
|
||||
expected_tables = [
|
||||
'projects',
|
||||
'backlogs',
|
||||
]
|
||||
table_names = [table[0] for table in tables]
|
||||
for expected_table in expected_tables:
|
||||
assert expected_table in table_names
|
||||
|
||||
cursor.execute("SELECT * FROM projects;")
|
||||
projects = cursor.fetchall()
|
||||
assert len(projects) == 0
|
||||
|
||||
cursor.execute("SELECT * FROM backlogs;")
|
||||
backlogs = cursor.fetchall()
|
||||
assert len(backlogs) == 0
|
||||
|
||||
cursor.execute("PRAGMA table_info('projects');")
|
||||
project_columns = cursor.fetchall()
|
||||
expected_project_columns = [
|
||||
"id",
|
||||
"aliases",
|
||||
"customTags",
|
||||
"owner",
|
||||
"code",
|
||||
"created_at",
|
||||
"updated_at"
|
||||
]
|
||||
project_column_names = [col[1] for col in project_columns]
|
||||
for expected_col in expected_project_columns:
|
||||
assert expected_col in project_column_names
|
||||
|
||||
cursor.execute("PRAGMA table_info('backlogs');")
|
||||
backlog_columns = cursor.fetchall()
|
||||
expected_backlog_columns = [
|
||||
"id",
|
||||
"name",
|
||||
"ensemble",
|
||||
"code",
|
||||
"path",
|
||||
"project",
|
||||
"customTags",
|
||||
"parameters",
|
||||
"parameter_file",
|
||||
"created_at",
|
||||
"updated_at"
|
||||
]
|
||||
backlog_column_names = [col[1] for col in backlog_columns]
|
||||
for expected_col in expected_backlog_columns:
|
||||
assert expected_col in backlog_column_names
|
||||
|
||||
|
||||
def test_list(tmp_path):
|
||||
dataset_path = tmp_path / "test_dataset"
|
||||
result = runner.invoke(app, ["init", "--dataset", str(dataset_path)])
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(app, ["list", "--dataset", str(dataset_path), "ensembles"])
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(app, ["list", "--dataset", str(dataset_path), "projects"])
|
||||
assert result.exit_code == 0
|
||||
68
tests/test_initialization.py
Normal file
68
tests/test_initialization.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import corrlib.initialization as init
|
||||
import os
|
||||
import sqlite3 as sql
|
||||
|
||||
def test_init_folders(tmp_path):
|
||||
dataset_path = tmp_path / "test_dataset"
|
||||
init.create(str(dataset_path))
|
||||
assert os.path.exists(str(dataset_path))
|
||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||
|
||||
|
||||
def test_init_db(tmp_path):
|
||||
dataset_path = tmp_path / "test_dataset"
|
||||
init.create(str(dataset_path))
|
||||
assert os.path.exists(str(dataset_path / "backlogger.db"))
|
||||
conn = sql.connect(str(dataset_path / "backlogger.db"))
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
||||
tables = cursor.fetchall()
|
||||
expected_tables = [
|
||||
'projects',
|
||||
'backlogs',
|
||||
]
|
||||
table_names = [table[0] for table in tables]
|
||||
for expected_table in expected_tables:
|
||||
assert expected_table in table_names
|
||||
|
||||
cursor.execute("SELECT * FROM projects;")
|
||||
projects = cursor.fetchall()
|
||||
assert len(projects) == 0
|
||||
|
||||
cursor.execute("SELECT * FROM backlogs;")
|
||||
backlogs = cursor.fetchall()
|
||||
assert len(backlogs) == 0
|
||||
|
||||
cursor.execute("PRAGMA table_info('projects');")
|
||||
project_columns = cursor.fetchall()
|
||||
expected_project_columns = [
|
||||
"id",
|
||||
"aliases",
|
||||
"customTags",
|
||||
"owner",
|
||||
"code",
|
||||
"created_at",
|
||||
"updated_at"
|
||||
]
|
||||
project_column_names = [col[1] for col in project_columns]
|
||||
for expected_col in expected_project_columns:
|
||||
assert expected_col in project_column_names
|
||||
|
||||
cursor.execute("PRAGMA table_info('backlogs');")
|
||||
backlog_columns = cursor.fetchall()
|
||||
expected_backlog_columns = [
|
||||
"id",
|
||||
"name",
|
||||
"ensemble",
|
||||
"code",
|
||||
"path",
|
||||
"project",
|
||||
"customTags",
|
||||
"parameters",
|
||||
"parameter_file",
|
||||
"created_at",
|
||||
"updated_at"
|
||||
]
|
||||
backlog_column_names = [col[1] for col in backlog_columns]
|
||||
for expected_col in expected_backlog_columns:
|
||||
assert expected_col in backlog_column_names
|
||||
|
|
@ -4,15 +4,21 @@ from corrlib import tools as tl
|
|||
|
||||
|
||||
def test_m2k():
|
||||
assert tl.m2k(0.1) == 1/(2*0.1+8)
|
||||
assert tl.m2k(0.5) == 1/(2*0.5+8)
|
||||
assert tl.m2k(1.0) == 1/(2*1.0+8)
|
||||
for m in [0.1, 0.5, 1.0]:
|
||||
expected_k = 1 / (2 * m + 8)
|
||||
assert tl.m2k(m) == expected_k
|
||||
|
||||
|
||||
def test_k2m():
|
||||
assert tl.k2m(0.1) == (1/(2*0.1))-4
|
||||
assert tl.k2m(0.5) == (1/(2*0.5))-4
|
||||
assert tl.k2m(1.0) == (1/(2*1.0))-4
|
||||
for m in [0.1, 0.5, 1.0]:
|
||||
assert tl.k2m(m) == (1/(2*m))-4
|
||||
|
||||
|
||||
def test_k2m_m2k():
|
||||
for m in [0.1, 0.5, 1.0]:
|
||||
k = tl.m2k(m)
|
||||
m_converted = tl.k2m(k)
|
||||
assert abs(m - m_converted) < 1e-9
|
||||
|
||||
|
||||
def test_str2list():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue