Skip to content

Commit df16e4b

Browse files
author
Alex Lee
committed
Adding test coverage to the codespell utility
1 parent 4d26e6d commit df16e4b

File tree

7 files changed

+81
-5
lines changed

7 files changed

+81
-5
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
run: pip install -e .[test]
2626
- name: Run doctests
2727
run: pytest --doctest-modules --ignore=causalpy/tests/ causalpy/
28+
- name: Run extra tests
29+
run: pytest docs/source/.codespell/test_notebook_to_markdown.py
2830
- name: Run tests
2931
run: pytest --cov-report=xml --no-cov-on-fail
3032
- name: Upload coverage to Codecov

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
hooks:
4646
- id: convert-notebooks
4747
name: Convert Notebooks to Markdown
48-
entry: python ./.codespell/notebook_to_markdown.py
48+
entry: python ./docs/source/.codespell/notebook_to_markdown.py
4949
language: python
5050
pass_filenames: false
5151
always_run: false
@@ -64,7 +64,7 @@ repos:
6464
"*.svg",
6565
"-S",
6666
"*.ipynb",
67-
"--ignore-words=./.codespell/codespell-whitelist.txt",
67+
"--ignore-words=./docs/source/.codespell/codespell-whitelist.txt",
6868
]
6969
additional_dependencies:
7070
# Support pyproject.toml configuration
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import os"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"print(f\"{os.__file}__\")\n",
19+
"\n",
20+
"# Speling mistake."
21+
]
22+
}
23+
],
24+
"metadata": {
25+
"language_info": {
26+
"name": "python"
27+
}
28+
},
29+
"nbformat": 4,
30+
"nbformat_minor": 2
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2024 The PyMC Labs Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Notebook to markdown tests."""
15+
16+
import os
17+
from tempfile import TemporaryDirectory
18+
19+
import pytest
20+
from notebook_to_markdown import notebook_to_markdown
21+
22+
23+
@pytest.fixture
24+
def data_dir() -> str:
25+
"""Get current directory."""
26+
return os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_data")
27+
28+
29+
def test_notebook_to_markdown_empty_pattern(data_dir: str) -> None:
30+
"""Test basic functionality of notebook_to_markdown with empty pattern."""
31+
with TemporaryDirectory() as tmp_dir:
32+
pattern = "*.missing"
33+
notebook_to_markdown(f"{data_dir}/{pattern}", tmp_dir)
34+
assert len(os.listdir(tmp_dir)) == 0
35+
36+
37+
def test_notebook_to_markdown(data_dir: str) -> None:
38+
"""Test basic functionality of notebook_to_markdown with a correct pattern."""
39+
with TemporaryDirectory() as tmp_dir:
40+
pattern = "*.ipynb"
41+
notebook_to_markdown(f"{data_dir}/{pattern}", tmp_dir)
42+
assert len(os.listdir(tmp_dir)) == 1
43+
assert "test_notebook.md" in os.listdir(tmp_dir)

docs/source/_static/interrogate_badge.svg

Lines changed: 3 additions & 3 deletions
Loading

0 commit comments

Comments
 (0)