diff --git a/commands/utils.py b/commands/utils.py new file mode 100644 index 0000000..75f6e0f --- /dev/null +++ b/commands/utils.py @@ -0,0 +1,29 @@ +import string + +from packaging.version import Version + +LATEST = "@latest" + + +def is_version_below(target: tuple[int, int], version: str) -> bool: + if version == LATEST: + return False + # We suppose version format to be ~=version, ==version, >version, ... + if version[0] in string.digits: + pass + elif version[1] in string.digits: + version = version[1:] + else: + version = version[2:] + + version = Version(version) + return version < Version(f"{target[0]}.{target[1]}") + + +if __name__ == "__main__": + assert not is_version_below((1, 22), LATEST) + assert not is_version_below((1, 22), "1.22.1") + assert is_version_below((1, 22), "1.19.1") + assert not is_version_below((1, 22), "~=1.24") + assert not is_version_below((1, 22), ">=1.24") + assert is_version_below((1, 22), "~=1.20") diff --git a/noxfile.py b/noxfile.py index 5a46450..8818d42 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,5 +1,4 @@ import hashlib -import string from pathlib import Path from typing import List @@ -7,26 +6,13 @@ import nox_poetry from nox_poetry.poetry import CommandSkippedError -LATEST = "@latest" +from commands.utils import LATEST, is_version_below def with_python_versions(python_versions: List[str], st_version: str, tqdm_version: str): return [(python_version, st_version, tqdm_version) for python_version in python_versions] -def is_version_below(target: tuple[int, int], version: str) -> bool: - if version == LATEST: - return True - # We suppose version format to be ~=version, ==version, >version, ... - if version[1] in string.digits: - version = version[1:] - else: - version = version[2:] - - st_major, st_minor = version.split(".", maxsplit=2)[:2] - return (int(st_major), int(st_minor)) < target - - def fix_deps_issues(streamlit_version: str) -> List[str]: """ Fix issues with streamlit and stqdm deps to ease ci @@ -120,7 +106,15 @@ def install_deps(session: nox.Session, constraint_groups: List[str], dependencie def tests(session: nox.Session, streamlit_version: str, tqdm_version: str) -> None: dependencies_to_install = build_dependencies_to_install_list(streamlit_version, tqdm_version, [".", "pytest", "freezegun"]) install_deps(session, constraint_groups=["dev"], dependencies_to_install=dependencies_to_install) - session.run("pytest") + session.run("pytest", "-m", "not demo_app") + + +@nox.session(python=None) +@nox.parametrize(["python", "streamlit_version", "tqdm_version"], [PYTHON_ST_TQDM_VERSIONS[-1]]) +def test_demo_app(session: nox.Session, streamlit_version: str, tqdm_version: str) -> None: + dependencies_to_install = build_dependencies_to_install_list(streamlit_version, tqdm_version, [".", "pytest", "freezegun"]) + install_deps(session, constraint_groups=["dev"], dependencies_to_install=dependencies_to_install) + session.run("pytest", "-m", "demo_app") @nox.session(python=None) @@ -130,10 +124,11 @@ def coverage(session: nox.Session, streamlit_version: str, tqdm_version: str) -> streamlit_version, tqdm_version, [".", "pytest", "pytest-cov", "freezegun"] ) install_deps(session, constraint_groups=["dev"], dependencies_to_install=dependencies_to_install) - session.run("pytest", "--cov-fail-under=15", "--cov=stqdm", "--cov-report=xml:codecov.xml") + session.run("pytest", "--cov-fail-under=15", "--cov=stqdm", "--cov-report=xml:codecov.xml", "-m", "not demo_app") -@nox_poetry.session(python=None) +@nox.session(python=None) +@nox.parametrize(["python", "streamlit_version", "tqdm_version"], [PYTHON_ST_TQDM_VERSIONS[0]] + [PYTHON_ST_TQDM_VERSIONS[-1]]) def isort(session: nox_poetry.Session): session.install("isort") session.run("isort", ".", "--check") diff --git a/pyproject.toml b/pyproject.toml index f40be5c..82eff95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,9 @@ skip_gitignore = true [tool.pytest.ini_options] addopts = "-ra" testpaths = ["tests"] +markers = [ + "app_test:Test a streamlit app directly with AppTest" +] [tool.coverage.run] omit = [".nox/*"] diff --git a/tests/test_streamlit_apps.py b/tests/test_streamlit_apps.py index 25e3c68..04856bc 100644 --- a/tests/test_streamlit_apps.py +++ b/tests/test_streamlit_apps.py @@ -11,6 +11,8 @@ import demo.src.utils from demo.src.demo_apps import simple_stqdm_in_main +pytestmark = pytest.mark.demo_app + def collect_block_elements(block: Block, should_take: Callable[[Element], bool]) -> list[Element]: children = block.children.values()