Skip to content

Commit

Permalink
chore(ci): make demo app test options
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnault Chazareix committed Jan 2, 2025
1 parent 80920c8 commit 2c2caf8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
29 changes: 29 additions & 0 deletions commands/utils.py
Original file line number Diff line number Diff line change
@@ -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")
31 changes: 13 additions & 18 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import hashlib
import string
from pathlib import Path
from typing import List

import nox
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
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_streamlit_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2c2caf8

Please sign in to comment.