From b834945cc1f1f3c1464ab26e7e78fa805585b700 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 31 Aug 2025 23:16:46 +0200 Subject: [PATCH] Increase coverage --- .github/codecov.yml | 3 ++ .github/workflows/continuous-integration.yml | 7 +--- packages/dt_for_itables/add_host_to_root.py | 36 +++++++------------ .../dt_for_itables/test_add_host_to_root.py | 14 +++++++- tests/test_documentation_notebooks_run.py | 19 +++++++--- 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.github/codecov.yml b/.github/codecov.yml index 1cd354b5..c82d180b 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -19,3 +19,6 @@ coverage: patch: default: target: 80% + +ignore: + - "apps/" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 77a16998..41955c15 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -71,7 +71,6 @@ jobs: numpy-version: '<2.0' - python-version: "3.13" pandas-version: pre - polars: true - python-version: "3.13" uninstall_non_essential_dependencies: true - python-version: "3.10" @@ -110,16 +109,12 @@ jobs: if: matrix.typeguard-version != 'latest' run: pip install 'typeguard${{ matrix.typeguard-version }}' - - name: Install polars - if: matrix.polars - run: pip install -e .[polars] - - name: Install shiny run: pip install "shiny>=1.0" shinywidgets - name: Uninstall non-essential dependencies if: matrix.uninstall_non_essential_dependencies - run: pip uninstall jinja2 dash anywidget streamlit shiny shinywidgets -y + run: pip uninstall polars jinja2 dash anywidget streamlit shiny shinywidgets -y - name: Install a Jupyter Kernel run: python -m ipykernel install --name itables --user diff --git a/packages/dt_for_itables/add_host_to_root.py b/packages/dt_for_itables/add_host_to_root.py index 4a5a9859..a85fce1c 100644 --- a/packages/dt_for_itables/add_host_to_root.py +++ b/packages/dt_for_itables/add_host_to_root.py @@ -61,31 +61,21 @@ def process_rule(match): return re.sub(pattern, process_rule, css_content) -if __name__ == "__main__": - - def main(): - parser = argparse.ArgumentParser( - description="Add :host to each :root selector in a CSS file." - ) - parser.add_argument("css_file", help="Path to the CSS file to modify") - args = parser.parse_args() +def main(argv): + parser = argparse.ArgumentParser( + description="Add :host to each :root selector in a CSS file." + ) + parser.add_argument("css_file", help="Path to the CSS file to modify") + args = parser.parse_args(argv[1:]) - try: - with open(args.css_file, "r") as file: - css_content = file.read() + with open(args.css_file, "r") as file: + css_content = file.read() - modified_content = add_host_to_root(css_content) + modified_content = add_host_to_root(css_content) - with open(args.css_file, "w") as file: - file.write(modified_content) + with open(args.css_file, "w") as file: + file.write(modified_content) - print(f"Successfully updated {args.css_file}") - return 0 - except FileNotFoundError: - print(f"Error: File {args.css_file} not found.") - return 1 - except Exception as e: - print(f"Error processing file: {e}") - return 1 - sys.exit(main()) +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/packages/dt_for_itables/test_add_host_to_root.py b/packages/dt_for_itables/test_add_host_to_root.py index 4473beb2..9dae0ad0 100644 --- a/packages/dt_for_itables/test_add_host_to_root.py +++ b/packages/dt_for_itables/test_add_host_to_root.py @@ -1,5 +1,5 @@ import pytest -from add_host_to_root import add_host_to_root +from add_host_to_root import add_host_to_root, main def test_add_host_to_root_example(): @@ -66,3 +66,15 @@ def test_add_host_to_root_complex_selectors(): :root[data-theme="light"] .element, :host[data-theme="light"] .element { background-color: white; } """ assert add_host_to_root(original_css) == expected_css + + +def test_main_function(tmp_path): + """Test the main function modifies the file as expected.""" + css_content = ":root { color: red; }" + expected_content = ":root, :host { color: red; }" + css_file = tmp_path / "test.css" + css_file.write_text(css_content) + + main(["add_host_to_root.py", str(css_file)]) + result = css_file.read_text() + assert result == expected_content diff --git a/tests/test_documentation_notebooks_run.py b/tests/test_documentation_notebooks_run.py index db2e3165..dcefe447 100644 --- a/tests/test_documentation_notebooks_run.py +++ b/tests/test_documentation_notebooks_run.py @@ -1,3 +1,5 @@ +import subprocess +import sys from pathlib import Path import jupytext @@ -34,15 +36,24 @@ def test_run_documentation_notebooks(notebook): pytest.skip("Polars is not available") if "pandas_style" in notebook.stem and pd_style is None: pytest.skip("Pandas Style is not available") - if "shiny" in notebook.stem: - pytest.skip("shinywidgets makes the widget.md notebook fail") if "marimo" in notebook.stem or "widget" in notebook.stem: pytest.importorskip("anywidget") - org_options = dir(opt) - nb = jupytext.read(notebook) py_notebook = jupytext.writes(nb, "py:percent") + if "shiny" in notebook.stem: + # we can't use exec as shinywidgets makes the widget.md notebook fail + result = subprocess.run( + [sys.executable, "-c", py_notebook], capture_output=True, text=True + ) + if result.returncode != 0: + if "ModuleNotFoundError: No module named 'shinywidgets'" in result.stderr: + pytest.skip("shinywidgets is not available") + assert result.returncode == 0, result.stderr + return + + org_options = dir(opt) + exec(py_notebook, {}) new_options = set(dir(opt)).difference(org_options)