Skip to content

Commit 384fdf7

Browse files
🧪 TESTS: Move from unittest to pytest (executablebooks#88)
Co-authored-by: Chris Sewell <[email protected]>
1 parent 546f52f commit 384fdf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2668
-819
lines changed

‎.pre-commit-config.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ repos:
77
- id: check-yaml
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
10+
exclude:
11+
".xml"
1012

1113
- repo: https://github.com/mgedmin/check-manifest
1214
rev: "0.39"
@@ -31,6 +33,6 @@ repos:
3133
exclude: >
3234
(?x)^(
3335
setup.py|
34-
test/.*|
36+
tests/.*|
3537
docs/.*
3638
)$

‎MANIFEST.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude docs
22
recursive-exclude docs *
3-
exclude test
4-
recursive-exclude test *
3+
exclude tests
4+
recursive-exclude tests *
55
exclude images
66
recursive-exclude images *
77

‎codecov.yml

+5
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ coverage:
22
status:
33
project:
44
default:
5+
target: 85%
6+
threshold: 0.5%
7+
patch:
8+
default:
9+
target: 80%
510
threshold: 0.5%

‎setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ def get_version():
3131
"coverage",
3232
"pytest>=3.6,<4",
3333
"pytest-cov",
34+
"pytest-regressions",
3435
"pygments",
35-
"lxml",
3636
"sphinx_testing",
37+
"bs4",
3738
],
3839
"code_style": ["pre-commit==2.6"],
3940
},

‎sphinx_tabs/tabs.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import base64
44
import json
5-
import os
6-
import posixpath
5+
from pathlib import Path
76

87
from docutils import nodes
98
from docutils.parsers.rst import Directive, directives
@@ -249,8 +248,8 @@ def run(self):
249248

250249

251250
class _FindTabsDirectiveVisitor(nodes.NodeVisitor):
252-
""" Visitor pattern than looks for a sphinx tabs
253-
directive in a document """
251+
"""Visitor pattern than looks for a sphinx tabs
252+
directive in a document"""
254253

255254
def __init__(self, document):
256255
nodes.NodeVisitor.__init__(self, document)
@@ -279,17 +278,17 @@ def update_context(app, pagename, templatename, context, doctree):
279278
visitor = _FindTabsDirectiveVisitor(doctree)
280279
doctree.walk(visitor)
281280
if not visitor.found_tabs_directive:
282-
paths = [posixpath.join("_static", "sphinx_tabs/" + f) for f in FILES]
281+
paths = [Path("_static") / "sphinx_tabs" / f for f in FILES]
283282
if "css_files" in context:
284283
context["css_files"] = context["css_files"][:]
285284
for path in paths:
286-
if path.endswith(".css") and path in context["css_files"]:
287-
context["css_files"].remove(path)
285+
if path.suffix == ".css" and path in context["css_files"]:
286+
context["css_files"].remove(path.as_posix())
288287
if "script_files" in context:
289288
context["script_files"] = context["script_files"][:]
290289
for path in paths:
291-
if path.endswith(".js") and path in context["script_files"]:
292-
context["script_files"].remove(path)
290+
if path.suffix == ".js" and path.as_posix() in context["script_files"]:
291+
context["script_files"].remove(path.as_posix())
293292

294293

295294
# pylint: enable=unused-argument
@@ -316,15 +315,15 @@ def copy_assets(app, exception):
316315

317316
log("Copying tabs assets")
318317

319-
installdir = os.path.join(app.builder.outdir, "_static", "sphinx_tabs")
318+
installdir = Path(app.builder.outdir) / "_static" / "sphinx_tabs"
320319

321320
for path in FILES:
322321
source = resource_filename("sphinx_tabs", path)
323-
dest = os.path.join(installdir, path)
322+
dest = installdir / path
324323

325-
destdir = os.path.dirname(dest)
326-
if not os.path.exists(destdir):
327-
os.makedirs(destdir)
324+
destdir = dest.parent
325+
if not destdir.exists():
326+
destdir.mkdir(parents=True)
328327

329328
copyfile(source, dest)
330329

@@ -337,17 +336,17 @@ def setup(app):
337336
app.add_directive("tab", TabDirective)
338337
app.add_directive("group-tab", GroupTabDirective)
339338
app.add_directive("code-tab", CodeTabDirective)
340-
for path in ["sphinx_tabs/" + f for f in FILES]:
341-
if path.endswith(".css"):
339+
for path in [Path("sphinx_tabs") / f for f in FILES]:
340+
if path.suffix == ".css":
342341
if "add_css_file" in dir(app):
343-
app.add_css_file(path)
342+
app.add_css_file(path.as_posix())
344343
else:
345-
app.add_stylesheet(path)
346-
if path.endswith(".js"):
344+
app.add_stylesheet(path.as_posix())
345+
if path.suffix == ".js":
347346
if "add_script_file" in dir(app):
348-
app.add_script_file(path)
347+
app.add_script_file(path.as_posix())
349348
else:
350-
app.add_js_file(path)
349+
app.add_js_file(path.as_posix())
351350
app.connect("html-page-context", update_context)
352351
app.connect("build-finished", copy_assets)
353352

‎test/basic/index.html.1

-28
This file was deleted.

‎test/basic/index.html.2

-36
This file was deleted.

‎test/conditionalassets/index.html

-10
This file was deleted.

‎test/conditionalassets/other.html

-4
This file was deleted.

‎test/conditionalassets/other2.html

-4
This file was deleted.

‎test/linenos/index.html.1

-55
This file was deleted.

‎test/linenos/index.html.2

-55
This file was deleted.

‎test/linenos/index.html.3

-57
This file was deleted.

0 commit comments

Comments
 (0)