Skip to content

Commit 10246dc

Browse files
authored
🧪 TESTS: Add Windows to test matrix (#10)
1 parent 3c18115 commit 10246dc

File tree

9 files changed

+26
-21
lines changed

9 files changed

+26
-21
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ jobs:
2626

2727
tests:
2828

29-
runs-on: ubuntu-latest
3029
strategy:
3130
matrix:
31+
os: [ubuntu-latest]
3232
python-version: [3.6, 3.7, 3.8, 3.9]
33+
include:
34+
- os: windows-latest
35+
python-version: 3.8
36+
37+
runs-on: ${{ matrix.os }}
3338

3439
steps:
3540
- uses: actions/checkout@v2

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,13 @@ Process:
228228
- Read toc ("builder-inited" event), error if toc not found
229229
- Note, in jupyter-book: if index page does not exist, works out first page from toc and creates an index page that just redirects to it)
230230
- adds toctree node to page doctree after it is parsed ("doctree-read" event)
231-
- Note, in jupyter-book this was done by physically addingto the text before parsing ("source-read" event), but this is not as robust.
231+
- Note, in jupyter-book this was done by physically adding to the text before parsing ("source-read" event), but this is not as robust.
232232

233233
Questions / TODOs:
234234

235235
- Should `titlesonly` default to `True` (as in jupyter-book)?
236236
- nested numbered toctree not allowed (logs warning), so should be handled if `numbered: true` is in defaults
237237
- Add additional top-level keys, e.g. `appendices` and `bibliography`
238-
- testing against Windows (including toc with subfolders)
239238
- Add tests for "bad" toc files
240239
- Using `external_toc_exclude_missing` to exclude a certain file suffix:
241240
currently if you had files `doc.md` and `doc.rst`, and put `doc.md` in your ToC,

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
name = sphinx_external_toc
33
version = attr: sphinx_external_toc.__version__
4-
description = A sphinx extension that allows the documentation toctree to be defined in a single file.
4+
description = A sphinx extension that allows the site-map to be defined in a single YAML file.
55
long_description = file: README.md
66
long_description_content_type = text/markdown
77
url = https://github.com/executablebooks/sphinx-external-toc

sphinx_external_toc/tools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from itertools import chain
22
from pathlib import Path, PurePosixPath
3-
from os import linesep
43
import shutil
54
from typing import Mapping, Optional, Sequence, Union
65

@@ -73,6 +72,8 @@ def create_site_from_toc(
7372
if extra_lines:
7473
content.extend(extra_lines + [""])
7574

76-
docpath.write_text(linesep.join(content), encoding=encoding)
75+
# note \n works when writing for all platforms:
76+
# https://docs.python.org/3/library/os.html#os.linesep
77+
docpath.write_text("\n".join(content), encoding=encoding)
7778

7879
return site_map

tests/_toc_files/basic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ main:
1111
- file: doc3
1212
parts:
1313
- sections:
14-
- file: doc4
14+
- file: subfolder/doc4
1515
- url: https://example.com

tests/test_api/test_file_to_sitemap_basic_.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ doc3:
1414
numbered: false
1515
reversed: false
1616
sections:
17-
- doc4
17+
- subfolder/doc4
1818
- title: null
1919
url: https://example.com
2020
titlesonly: true
2121
title: null
22-
doc4:
23-
docname: doc4
24-
parts: []
25-
title: null
2622
intro:
2723
docname: intro
2824
parts:
@@ -35,3 +31,7 @@ intro:
3531
- doc3
3632
titlesonly: true
3733
title: Introduction
34+
subfolder/doc4:
35+
docname: subfolder/doc4
36+
parts: []
37+
title: null

tests/test_cli.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
from pathlib import Path
3+
from typing import List
24

35
from click.testing import CliRunner
46

@@ -8,14 +10,11 @@
810
import pytest
911

1012

11-
# TOC_FILES = list(Path(__file__).parent.joinpath("_toc_files").glob("*.yml"))
12-
13-
1413
@pytest.fixture()
1514
def invoke_cli():
1615
"""Run CLI and do standard checks."""
1716

18-
def _func(command, args, assert_exit: bool = True):
17+
def _func(command, args: List[str], assert_exit: bool = True):
1918
runner = CliRunner()
2019
result = runner.invoke(command, args)
2120
if assert_exit:
@@ -26,11 +25,11 @@ def _func(command, args, assert_exit: bool = True):
2625

2726

2827
def test_version(invoke_cli):
29-
result = invoke_cli(main, "--version")
28+
result = invoke_cli(main, ["--version"])
3029
assert __version__ in result.output
3130

3231

3332
def test_parse_toc(invoke_cli):
34-
path = Path(__file__).parent.joinpath("_toc_files", "basic.yml").resolve()
35-
result = invoke_cli(parse_toc, str(path))
33+
path = os.path.abspath(Path(__file__).parent.joinpath("_toc_files", "basic.yml"))
34+
result = invoke_cli(parse_toc, [path])
3635
assert "intro" in result.output

tests/test_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
)
1313
def test_file_to_sitemap(path: Path, tmp_path: Path, data_regression):
1414
create_site_from_toc(path, root_path=tmp_path)
15-
file_list = [str(p.relative_to(tmp_path)) for p in tmp_path.glob("**/*")]
15+
file_list = [p.relative_to(tmp_path).as_posix() for p in tmp_path.glob("**/*")]
1616
data_regression.check(sorted(file_list))

tests/test_tools/test_file_to_sitemap_basic_.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
- doc1.rst
33
- doc2.rst
44
- doc3.rst
5-
- doc4.rst
65
- intro.rst
6+
- subfolder
7+
- subfolder/doc4.rst

0 commit comments

Comments
 (0)