Skip to content

Commit 49863b5

Browse files
committed
Add tests for skin and yosys_script options
This commit adds the unit tests for skin and yosys_option. It also provides the basic test mechanism that can be used to check the correctness of both particular functions and the whole extension usage in Sphinx. Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
1 parent dc60c26 commit 49863b5

File tree

13 files changed

+2825
-3
lines changed

13 files changed

+2825
-3
lines changed

.travis.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@ language: minimal
33
before_install:
44
- make env
55

6-
script:
7-
- make test
8-
- make build
6+
stages:
7+
- name:
8+
- Test
9+
- Build
10+
11+
jobs:
12+
- stage: Tests
13+
name: "Test :skin: option"
14+
script:
15+
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
16+
- cd tests && python3 -m unittest test.TestSkins
17+
18+
- stage: Tests
19+
name: "Test :yosys_script: option"
20+
script:
21+
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
22+
- cd tests && python3 -m unittest test.TestYosysScript
23+
24+
- stage: Build
25+
name: "Build"
26+
script:
27+
- make build
928

1029
before_deploy:
1130
- make clean

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ upload: build | $(CONDA_ENV_PYTHON)
6262

6363
test: $(VERSION_PY) | $(CONDA_ENV_PYTHON)
6464
$(IN_CONDA_ENV) cd docs; make html
65+
$(IN_CONDA_ENV) cd tests; make test
6566

6667
.PHONY: test

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ sphinx
44

55
# Needed to upload to PyPi
66
twine
7+
8+
# Needed for tests
9+
jinja2

tests/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test:
2+
make clean
3+
python3 test.py
4+
5+
clean:
6+
-rm -rf build
7+
8+
.PHONY: test clean

tests/conf.py.template

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
16+
sys.path.insert(0, {{ verilog_diagrams_path }})
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'Sphinx Verilog Diagrams Tests'
21+
copyright = '2020, SymbiFlow Team'
22+
author = 'SymbiFlow Team'
23+
24+
# The full version, including alpha/beta/rc tags
25+
release = '0.1'
26+
27+
28+
# -- General configuration ---------------------------------------------------
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = [
34+
'sphinxcontrib_verilog_diagrams',
35+
]
36+
37+
# Add any paths that contain templates here, relative to this directory.
38+
templates_path = ['_templates']
39+
40+
# List of patterns, relative to source directory, that match files and
41+
# directories to ignore when looking for source files.
42+
# This pattern also affects html_static_path and html_extra_path.
43+
exclude_patterns = []
44+
45+
46+
# -- Options for HTML output -------------------------------------------------
47+
48+
# The theme to use for HTML and HTML Help pages. See the documentation for
49+
# a list of builtin themes.
50+
#
51+
html_theme = 'alabaster'
52+
53+
# Add any paths that contain custom static files (such as style sheets) here,
54+
# relative to this directory. They are copied after the builtin static files,
55+
# so a file named "default.css" will overwrite the builtin "default.css".
56+
57+
master_doc = {{ master_doc }}
58+
{{ custom_variables }}

tests/test.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import shutil
5+
import unittest
6+
7+
from jinja2 import Environment, FileSystemLoader
8+
from sphinx.application import Sphinx
9+
from sphinx.util.docutils import docutils_namespace
10+
11+
VERILOG_DIAGRAMS_PATH = os.path.abspath("..")
12+
13+
14+
def get_sphinx_dirs(test_build_dir):
15+
sphinx_dirs = {
16+
"srcdir": test_build_dir,
17+
"confdir": test_build_dir,
18+
"outdir": os.path.join(test_build_dir, "build"),
19+
"doctreedir": os.path.join(test_build_dir, "build", "doctrees")
20+
}
21+
return sphinx_dirs
22+
23+
24+
def generate_sphinx_config(test_build_dir, **jinja_dict):
25+
sphinx_config_path = os.path.join(test_build_dir, "conf.py")
26+
27+
with open(sphinx_config_path, "w") as fd:
28+
env = Environment(loader=FileSystemLoader('.'))
29+
template = env.get_template("conf.py.template")
30+
template.stream(**jinja_dict).dump(fd)
31+
32+
33+
class TestSkins(unittest.TestCase):
34+
35+
TEST_CASE_NAME = "TestSkins"
36+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
37+
38+
def test_netlistsvg_diagram(self):
39+
TEST_NAME = "test_skins"
40+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
41+
TEST_FILES = [
42+
"test_skins/test_skins.rst",
43+
"test_skins/skin-orange.svg",
44+
"test_skins/skin-yellow.svg",
45+
"verilog/adder.v"
46+
]
47+
TEST_JINJA_DICT = {
48+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
49+
"master_doc": "'test_skins'",
50+
"custom_variables": "verilog_diagram_skin = os.path.realpath('skin-orange.svg')"
51+
}
52+
53+
# Create the TestCase build directory
54+
os.makedirs(TEST_BUILD_DIR, exist_ok=True)
55+
56+
# Generate a Sphinx config
57+
generate_sphinx_config(TEST_BUILD_DIR, **TEST_JINJA_DICT)
58+
59+
# Copy the test files
60+
for src in TEST_FILES:
61+
src_basename = os.path.basename(src)
62+
dst = os.path.join(TEST_BUILD_DIR, src_basename)
63+
shutil.copyfile(src, dst)
64+
65+
# Run the Sphinx
66+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
67+
with docutils_namespace():
68+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
69+
app.build(force_all=True)
70+
71+
72+
class TestYosysScript(unittest.TestCase):
73+
74+
TEST_CASE_NAME = "TestYosysScript"
75+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
76+
77+
def test_yosys_script(self):
78+
TEST_NAME = "test_yosys_script"
79+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
80+
TEST_FILES = [
81+
"test_yosys_script/test_yosys_script.rst",
82+
"test_yosys_script/yosys_script.ys",
83+
"test_yosys_script/yosys_script2.ys",
84+
"verilog/adder.v"
85+
]
86+
TEST_JINJA_DICT = {
87+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
88+
"master_doc": "'test_yosys_script'",
89+
"custom_variables": "verilog_diagram_yosys_script = os.path.realpath('yosys_script.ys')"
90+
}
91+
92+
# Create the TestCase build directory
93+
os.makedirs(TEST_BUILD_DIR, exist_ok=True)
94+
95+
# Generate a Sphinx config
96+
generate_sphinx_config(TEST_BUILD_DIR, **TEST_JINJA_DICT)
97+
98+
# Copy the test files
99+
for src in TEST_FILES:
100+
src_basename = os.path.basename(src)
101+
dst = os.path.join(TEST_BUILD_DIR, src_basename)
102+
shutil.copyfile(src, dst)
103+
104+
# Run the Sphinx
105+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
106+
with docutils_namespace():
107+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
108+
app.build(force_all=True)
109+
110+
111+
if __name__ == '__main__':
112+
unittest.main()

0 commit comments

Comments
 (0)