Skip to content

Commit

Permalink
Adding test coverage to the codespell utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lee committed Sep 9, 2024
1 parent 4d26e6d commit df16e4b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: pip install -e .[test]
- name: Run doctests
run: pytest --doctest-modules --ignore=causalpy/tests/ causalpy/
- name: Run extra tests
run: pytest docs/source/.codespell/test_notebook_to_markdown.py
- name: Run tests
run: pytest --cov-report=xml --no-cov-on-fail
- name: Upload coverage to Codecov
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repos:
hooks:
- id: convert-notebooks
name: Convert Notebooks to Markdown
entry: python ./.codespell/notebook_to_markdown.py
entry: python ./docs/source/.codespell/notebook_to_markdown.py
language: python
pass_filenames: false
always_run: false
Expand All @@ -64,7 +64,7 @@ repos:
"*.svg",
"-S",
"*.ipynb",
"--ignore-words=./.codespell/codespell-whitelist.txt",
"--ignore-words=./docs/source/.codespell/codespell-whitelist.txt",
]
additional_dependencies:
# Support pyproject.toml configuration
Expand Down
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions docs/source/.codespell/test_data/test_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"{os.__file}__\")\n",
"\n",
"# Speling mistake."
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
43 changes: 43 additions & 0 deletions docs/source/.codespell/test_notebook_to_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 The PyMC Labs Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Notebook to markdown tests."""

import os
from tempfile import TemporaryDirectory

import pytest
from notebook_to_markdown import notebook_to_markdown


@pytest.fixture
def data_dir() -> str:
"""Get current directory."""
return os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_data")


def test_notebook_to_markdown_empty_pattern(data_dir: str) -> None:
"""Test basic functionality of notebook_to_markdown with empty pattern."""
with TemporaryDirectory() as tmp_dir:
pattern = "*.missing"
notebook_to_markdown(f"{data_dir}/{pattern}", tmp_dir)
assert len(os.listdir(tmp_dir)) == 0


def test_notebook_to_markdown(data_dir: str) -> None:
"""Test basic functionality of notebook_to_markdown with a correct pattern."""
with TemporaryDirectory() as tmp_dir:
pattern = "*.ipynb"
notebook_to_markdown(f"{data_dir}/{pattern}", tmp_dir)
assert len(os.listdir(tmp_dir)) == 1
assert "test_notebook.md" in os.listdir(tmp_dir)
6 changes: 3 additions & 3 deletions docs/source/_static/interrogate_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit df16e4b

Please sign in to comment.