test/first (#8)
Introducing first very simple tests for tools.py Reviewed-on: https://www.kuhl-mann.de/git/git/jkuhl/corrlib/pulls/8
This commit is contained in:
parent
acab85df82
commit
d70e8d32ce
9 changed files with 1650 additions and 11 deletions
35
.github/workflows/pytest.yaml
vendored
Normal file
35
.github/workflows/pytest.yaml
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
name: Pytest
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 4 1 * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pytest:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version:
|
||||||
|
- "3.12"
|
||||||
|
- "3.13"
|
||||||
|
- "3.14"
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
UV_CACHE_DIR: /tmp/.uv-cache
|
||||||
|
steps:
|
||||||
|
- name: Check out the repository
|
||||||
|
uses: https://github.com/RouxAntoine/checkout@v4.1.8
|
||||||
|
with:
|
||||||
|
show-progress: true
|
||||||
|
- name: Install uv
|
||||||
|
uses: astral-sh/setup-uv@v7
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
enable-cache: true
|
||||||
|
- name: Install corrlib
|
||||||
|
run: uv sync --locked --all-extras --dev --python ${{ matrix.python-version }}
|
||||||
|
- name: Run tests
|
||||||
|
run: uv run pytest tests
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -2,3 +2,6 @@ pyerrors_corrlib.egg-info
|
||||||
__pycache__
|
__pycache__
|
||||||
*.egg-info
|
*.egg-info
|
||||||
test.ipynb
|
test.ipynb
|
||||||
|
.vscode
|
||||||
|
.venv
|
||||||
|
.pytest_cache
|
||||||
|
|
@ -20,4 +20,3 @@ from .import input as input
|
||||||
from .initialization import *
|
from .initialization import *
|
||||||
from .meas_io import *
|
from .meas_io import *
|
||||||
from .find import *
|
from .find import *
|
||||||
from .version import __version__
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import typer
|
import typer
|
||||||
from corrlib import __app_name__, __version__
|
from corrlib import __app_name__
|
||||||
from .initialization import create
|
from .initialization import create
|
||||||
from .toml import import_tomls, update_project, reimport_project
|
from .toml import import_tomls, update_project, reimport_project
|
||||||
from .find import find_record, list_projects
|
from .find import find_record, list_projects
|
||||||
|
|
@ -8,6 +8,7 @@ from .tools import str2list
|
||||||
from .main import update_aliases
|
from .main import update_aliases
|
||||||
from .meas_io import drop_cache as mio_drop_cache
|
from .meas_io import drop_cache as mio_drop_cache
|
||||||
import os
|
import os
|
||||||
|
from importlib.metadata import version, PackageNotFoundError
|
||||||
|
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
@ -15,7 +16,7 @@ app = typer.Typer()
|
||||||
|
|
||||||
def _version_callback(value: bool) -> None:
|
def _version_callback(value: bool) -> None:
|
||||||
if value:
|
if value:
|
||||||
typer.echo(f"{__app_name__} v{__version__}")
|
print(__app_name__, version(__app_name__))
|
||||||
raise typer.Exit()
|
raise typer.Exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,24 @@ import os
|
||||||
import datalad.api as dl
|
import datalad.api as dl
|
||||||
|
|
||||||
|
|
||||||
def str2list(string):
|
def str2list(string: str):
|
||||||
return string.split(",")
|
return string.split(",")
|
||||||
|
|
||||||
def list2str(mylist):
|
def list2str(mylist):
|
||||||
s = ",".join(mylist)
|
s = ",".join(mylist)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
cached = True
|
cached: bool = True
|
||||||
|
|
||||||
def m2k(m):
|
def m2k(m: float) -> float:
|
||||||
return 1/(2*m+8)
|
return 1/(2*m+8)
|
||||||
|
|
||||||
|
|
||||||
def k2m(k):
|
def k2m(k: float) -> float:
|
||||||
return (1/(2*k))-4
|
return (1/(2*k))-4
|
||||||
|
|
||||||
|
|
||||||
def get_file(path, file):
|
def get_file(path: str, file: str):
|
||||||
if file == "backlogger.db":
|
if file == "backlogger.db":
|
||||||
print("Downloading database...")
|
print("Downloading database...")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,36 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools >= 63.0.0", "wheel"]
|
requires = ["setuptools >= 63.0.0", "wheel", "setuptools-scm"]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
requires-python = ">=3.10"
|
||||||
|
name = "corrlib"
|
||||||
|
dynamic = ["version"]
|
||||||
|
dependencies = [
|
||||||
|
"gitpython>=3.1.45",
|
||||||
|
'pyerrors>=2.11.1',
|
||||||
|
'datalad>=1.1.0',
|
||||||
|
'typer>=0.12.5'
|
||||||
|
]
|
||||||
|
description = "Python correlation library"
|
||||||
|
authors = [
|
||||||
|
{ name = 'Justus Kuhlmann', email = 'j_kuhl19@uni-muenster.de'}
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
pcl = "corrlib.cli:app"
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
include = ["corrlib", "corrlib.*"]
|
||||||
|
|
||||||
|
[tool.setuptools_scm]
|
||||||
|
write_to = "corrlib/version.py"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
ignore = ["F403"]
|
ignore = ["F403"]
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"pytest>=9.0.1",
|
||||||
|
"pytest-pretty>=1.3.0",
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,4 @@ def test_toml_check_measurement_data():
|
||||||
"names": ['list', 'of', 'names']
|
"names": ['list', 'of', 'names']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.check_measurement_data(measurements)
|
t.check_measurement_data(measurements, "sfcf")
|
||||||
|
|
|
||||||
25
tests/tools_test.py
Normal file
25
tests/tools_test.py
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def test_str2list():
|
||||||
|
assert tl.str2list("a,b,c") == ["a", "b", "c"]
|
||||||
|
assert tl.str2list("1,2,3") == ["1", "2", "3"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_list2str():
|
||||||
|
assert tl.list2str(["a", "b", "c"]) == "a,b,c"
|
||||||
|
assert tl.list2str(["1", "2", "3"]) == "1,2,3"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue