Skip to content

Commit 96243ae

Browse files
committed
fix
2 parents 1ce7302 + ed8d015 commit 96243ae

File tree

10 files changed

+173
-11
lines changed

10 files changed

+173
-11
lines changed

.github/workflows/black-ruff.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ jobs:
44
black-format-check:
55
runs-on: ubuntu-latest
66
steps:
7-
- uses: actions/checkout@v3
7+
- uses: actions/checkout@v4
88
- uses: psf/black@stable
99
with:
1010
options: "--diff --check"
1111
src: "."
1212
ruff-format-check:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
- uses: chartboost/ruff-action@v1

.github/workflows/check-urls.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111

1212
- name: urls-checker-code
1313
uses: urlstechie/urlchecker-action@master

.github/workflows/codeql.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ jobs:
3232

3333
steps:
3434
- name: Checkout repository
35-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3636

3737
# Initializes the CodeQL tools for scanning.
3838
- name: Initialize CodeQL
39-
uses: github/codeql-action/init@v2
39+
uses: github/codeql-action/init@v3
4040
# Override language selection by uncommenting this and choosing your languages
4141
# with:
4242
# languages: go, javascript, csharp, python, cpp, java, ruby
4343

4444
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
4545
# If this step fails, then you should remove it and run the build manually (see below).
4646
- name: Autobuild
47-
uses: github/codeql-action/autobuild@v2
47+
uses: github/codeql-action/autobuild@v3
4848

4949
# ℹ️ Command-line programs to run using the OS shell.
5050
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -58,4 +58,4 @@ jobs:
5858
# make release
5959

6060
- name: Perform CodeQL Analysis
61-
uses: github/codeql-action/analyze@v2
61+
uses: github/codeql-action/analyze@v3

.github/workflows/documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
os: [ubuntu-latest]
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121

2222
- uses: tlylt/install-graphviz@v1
2323

@@ -52,7 +52,7 @@ jobs:
5252
export PYTHONPATH=
5353
5454
- name: Upload coverage reports to Codecov
55-
uses: codecov/codecov-action@v3
55+
uses: codecov/codecov-action@v4
5656
env:
5757
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5858

.github/workflows/spell-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
# Checkout the repository
1515
- name: Checkout code
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
# Install codespell
1919
- name: Install codespell

.github/workflows/tests.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
tests:
9+
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
10+
runs-on: ${{ matrix.os }}
11+
permissions:
12+
contents: read
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- os: ubuntu-latest
18+
python-version: '3.13'
19+
- os: ubuntu-latest
20+
python-version: '3.12'
21+
- os: windows-latest
22+
python-version: '3.12'
23+
- os: macos-latest
24+
python-version: '3.12'
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Install system dependencies (Linux)
34+
if: runner.os == 'Linux'
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y pandoc graphviz
38+
39+
- name: Install system dependencies (macOS)
40+
if: runner.os == 'macOS'
41+
run: brew install pandoc graphviz
42+
43+
- name: Install pip tools
44+
run: python -m pip install --upgrade pip setuptools wheel
45+
46+
- name: Install requirements
47+
run: pip install -r requirements.txt
48+
49+
- name: Install requirements-dev
50+
run: pip install -r requirements-dev.txt
51+
52+
- name: Build wheel
53+
run: python -m pip wheel . --wheel-dir dist
54+
55+
- name: Install package
56+
run: pip install .
57+
58+
- name: Run tests
59+
run: python -m pytest --durations=10 --ignore-glob=**LONG*.py --ignore-glob=**notebook*.py
60+
61+
- uses: actions/upload-artifact@v4
62+
with:
63+
name: wheel-${{ matrix.os }}-${{ matrix.python-version }}
64+
path: dist/

.github/workflows/wheels-any.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
os: [ubuntu-latest]
1616

1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919

2020
- uses: actions/setup-python@v5
2121
with:

CHANGELOGS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Change Logs
44
0.4.2
55
+++++
66

7+
* :pr:`53`: Disable gdot call to graphviz if ``UNITTEST_GOING=1``
78
* :pr:`51`: Uses GitHub actions for CI
89
* :pr:`49`: Cache gdot script execution results in Sphinx environment`
910
* :pr:`47`: use svg by default with gdot

_unittests/ut_gdot/test_gdot_extension.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import unittest
22
import logging
3+
import os
34
import sys
5+
from contextlib import contextmanager
46
from sphinx_runpython.process_rst import rst2html
57
from sphinx_runpython.ext_test_case import (
68
ExtTestCase,
@@ -10,6 +12,20 @@
1012
)
1113

1214

15+
@contextmanager
16+
def unittest_going():
17+
"""Context manager that sets UNITTEST_GOING=1 for the duration of the block."""
18+
old = os.environ.get("UNITTEST_GOING", None)
19+
os.environ["UNITTEST_GOING"] = "1"
20+
try:
21+
yield
22+
finally:
23+
if old is None:
24+
os.environ.pop("UNITTEST_GOING", None)
25+
else:
26+
os.environ["UNITTEST_GOING"] = old
27+
28+
1329
class TestGDotExtension(ExtTestCase):
1430
def setUp(self):
1531
logger = logging.getLogger("gdot")
@@ -176,6 +192,58 @@ def test_gdot_script_cache(self):
176192
count, 2, f"Expected the DOT code to appear twice, got {count}"
177193
)
178194

195+
def test_gdot_unittest_going_svg(self):
196+
"""When UNITTEST_GOING=1, a dummy SVG containing 'DISABLED FOR TESTS' is rendered."""
197+
content = """
198+
before
199+
200+
.. gdot::
201+
:format: svg
202+
203+
digraph foo {
204+
"bar" -> "baz";
205+
}
206+
207+
after
208+
""".replace(" ", "")
209+
210+
with unittest_going():
211+
html = rst2html(
212+
content, writer_name="html", new_extensions=["sphinx_runpython.gdot"]
213+
)
214+
215+
self.assertIn("DISABLED FOR TESTS", html)
216+
self.assertIn("<svg", html)
217+
self.assertNotIn("<img", html)
218+
219+
@ignore_warnings(PendingDeprecationWarning)
220+
def test_gdot_unittest_going_png(self):
221+
"""
222+
When UNITTEST_GOING=1, a dummy image containing
223+
'DISABLED FOR TESTS' is rendered.
224+
"""
225+
content = """
226+
before
227+
228+
.. gdot::
229+
:format: png
230+
231+
digraph foo {
232+
"bar" -> "baz";
233+
}
234+
235+
after
236+
""".replace(" ", "")
237+
238+
with unittest_going():
239+
html = rst2html(
240+
content, writer_name="html", new_extensions=["sphinx_runpython.gdot"]
241+
)
242+
243+
self.assertIn("DISABLED FOR TESTS", html)
244+
self.assertIn("<img", html)
245+
self.assertNotIn("<svg", html)
246+
179247

180248
if __name__ == "__main__":
181249
unittest.main(verbosity=2)

sphinx_runpython/gdot/sphinx_gdot_extension.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ def depart_gdot_node_rst(self, node):
235235
self.end_state(wrap=False)
236236

237237

238+
_DUMMY_SVG = (
239+
'<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">'
240+
'<text x="10" y="50">DISABLED FOR TESTS</text>'
241+
"</svg>"
242+
)
243+
244+
_DUMMY_PNG_HTML = (
245+
'<img src="data:image/png;base64,'
246+
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQI12NgAAIABQ"
247+
'AABjkB6QAAAABJRU5ErkJggg==" alt="DISABLED FOR TESTS" />'
248+
)
249+
250+
251+
def _emit_dummy_output(self, format: str = "svg"):
252+
"""Emit a placeholder graphic when ``UNITTEST_GOING=1`` is set."""
253+
self.body.append('<div class="graphviz">')
254+
if format == "png":
255+
self.body.append(_DUMMY_PNG_HTML)
256+
else:
257+
self.body.append(_DUMMY_SVG)
258+
self.body.append("</div>\n")
259+
raise nodes.SkipNode
260+
261+
238262
def render_dot_html(
239263
self,
240264
node: gdot_node,
@@ -246,6 +270,9 @@ def render_dot_html(
246270
filename: str | None = None,
247271
format: str = "svg",
248272
) -> tuple[str, str]:
273+
if os.environ.get("UNITTEST_GOING", "0") == "1":
274+
_emit_dummy_output(self, format=format)
275+
249276
if format not in {"png", "svg"}:
250277
logger = logging.getLogger(__name__)
251278
logger.warning(__("format must be either 'png' or 'svg', but is %r"), format)
@@ -381,6 +408,8 @@ def visit_gdot_node_html(self, node):
381408
and the :epkg:`SVG` format.
382409
"""
383410
if node["format"].lower() == "png":
411+
if os.environ.get("UNITTEST_GOING", "0") == "1":
412+
_emit_dummy_output(self, format="png")
384413
from sphinx.ext.graphviz import html_visit_graphviz
385414

386415
return html_visit_graphviz(self, node)

0 commit comments

Comments
 (0)