1010
1111VERILOG_DIAGRAMS_PATH = os .path .abspath (".." )
1212
13+ ## Helpers
1314
1415def get_sphinx_dirs (test_build_dir ):
1516 sphinx_dirs = {
@@ -29,8 +30,37 @@ def generate_sphinx_config(test_build_dir, **jinja_dict):
2930 template = env .get_template ("conf.py.template" )
3031 template .stream (** jinja_dict ).dump (fd )
3132
33+ ## Base class for tests
3234
33- class TestSkins (unittest .TestCase ):
35+ class TestBase (unittest .TestCase ):
36+
37+ def print_test_header (self , case_name , test_name ):
38+ print ("" )
39+ print ("# ---------------------------------------------------------- #" )
40+ print ("# TEST CASE: {}" .format (case_name ))
41+ print ("# TEST NAME: {}" .format (test_name ))
42+ print ("# ---------------------------------------------------------- #" )
43+ print ("" )
44+
45+ def prepare_test (self , test_name , test_build_dir , test_files , ** test_jinja_dict ):
46+ self .print_test_header (self .TEST_CASE_NAME , test_name )
47+
48+ # Create the TestCase build directory
49+ os .makedirs (test_build_dir , exist_ok = True )
50+
51+ # Generate a Sphinx config
52+ generate_sphinx_config (test_build_dir , ** test_jinja_dict )
53+
54+ # Copy the test files
55+ for src in test_files :
56+ src_basename = os .path .basename (src )
57+ dst = os .path .join (test_build_dir , src_basename )
58+ shutil .copyfile (src , dst )
59+
60+
61+ ## Test cases
62+
63+ class TestSkins (TestBase ):
3464
3565 TEST_CASE_NAME = "TestSkins"
3666 TEST_CASE_BUILD_DIR = os .path .join ("build" , TEST_CASE_NAME )
@@ -50,17 +80,7 @@ def test_netlistsvg_diagram(self):
5080 "custom_variables" : "verilog_diagram_skin = os.path.realpath('skin-purple.svg')"
5181 }
5282
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 )
83+ self .prepare_test (TEST_NAME , TEST_BUILD_DIR , TEST_FILES , ** TEST_JINJA_DICT )
6484
6585 # Run the Sphinx
6686 sphinx_dirs = get_sphinx_dirs (TEST_BUILD_DIR )
@@ -69,7 +89,7 @@ def test_netlistsvg_diagram(self):
6989 app .build (force_all = True )
7090
7191
72- class TestYosysScript (unittest . TestCase ):
92+ class TestYosysScript (TestBase ):
7393
7494 TEST_CASE_NAME = "TestYosysScript"
7595 TEST_CASE_BUILD_DIR = os .path .join ("build" , TEST_CASE_NAME )
@@ -89,24 +109,86 @@ def test_yosys_script(self):
89109 "custom_variables" : "verilog_diagram_yosys_script = os.path.realpath('yosys_script.ys')"
90110 }
91111
92- # Create the TestCase build directory
93- os .makedirs (TEST_BUILD_DIR , exist_ok = True )
112+ self .prepare_test (TEST_NAME , TEST_BUILD_DIR , TEST_FILES , ** TEST_JINJA_DICT )
94113
95- # Generate a Sphinx config
96- generate_sphinx_config (TEST_BUILD_DIR , ** TEST_JINJA_DICT )
114+ # Run the Sphinx
115+ sphinx_dirs = get_sphinx_dirs (TEST_BUILD_DIR )
116+ with docutils_namespace ():
117+ app = Sphinx (buildername = "html" , warningiserror = True , ** sphinx_dirs )
118+ app .build (force_all = True )
97119
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 )
120+ class TestYosysType (TestBase ):
121+
122+ TEST_CASE_NAME = "TestYowasp"
123+ TEST_CASE_BUILD_DIR = os .path .join ("build" , TEST_CASE_NAME )
124+
125+ def test_yosys_yowasp (self ):
126+ TEST_NAME = "test_yosys_yowasp"
127+ TEST_BUILD_DIR = os .path .join ("build" , self .TEST_CASE_NAME , TEST_NAME )
128+ TEST_FILES = [
129+ "test_yosys_type/test_yosys_yowasp.rst" ,
130+ "verilog/adder.v"
131+ ]
132+ TEST_JINJA_DICT = {
133+ "verilog_diagrams_path" : "'{}'" .format (VERILOG_DIAGRAMS_PATH ),
134+ "master_doc" : "'test_yosys_yowasp'" ,
135+ "custom_variables" : ""
136+ }
137+
138+ self .prepare_test (TEST_NAME , TEST_BUILD_DIR , TEST_FILES , ** TEST_JINJA_DICT )
139+
140+ # Run the Sphinx
141+ sphinx_dirs = get_sphinx_dirs (TEST_BUILD_DIR )
142+ with docutils_namespace ():
143+ app = Sphinx (buildername = "html" , warningiserror = True , ** sphinx_dirs )
144+ app .build (force_all = True )
145+
146+ @unittest .skipIf (shutil .which ('yosys' ) is None , 'Skipping test_yosys_system. Yosys is not installed!' )
147+ def test_yosys_system (self ):
148+ TEST_NAME = "test_yosys_system"
149+ TEST_BUILD_DIR = os .path .join ("build" , self .TEST_CASE_NAME , TEST_NAME )
150+ TEST_FILES = [
151+ "test_yosys_type/test_yosys_system.rst" ,
152+ "verilog/adder.v"
153+ ]
154+ TEST_JINJA_DICT = {
155+ "verilog_diagrams_path" : "'{}'" .format (VERILOG_DIAGRAMS_PATH ),
156+ "master_doc" : "'test_yosys_system'" ,
157+ "custom_variables" : "verilog_diagram_yosys = 'system'"
158+ }
159+
160+ self .prepare_test (TEST_NAME , TEST_BUILD_DIR , TEST_FILES , ** TEST_JINJA_DICT )
103161
104162 # Run the Sphinx
105163 sphinx_dirs = get_sphinx_dirs (TEST_BUILD_DIR )
106164 with docutils_namespace ():
107165 app = Sphinx (buildername = "html" , warningiserror = True , ** sphinx_dirs )
108166 app .build (force_all = True )
109167
168+ @unittest .skipIf (shutil .which ('yosys' ) is None , 'Skipping test_yosys_path. Yosys is not installed!' )
169+ def test_yosys_path (self ):
170+ TEST_NAME = "test_yosys_path"
171+ TEST_BUILD_DIR = os .path .join ("build" , self .TEST_CASE_NAME , TEST_NAME )
172+ TEST_FILES = [
173+ "test_yosys_type/test_yosys_path.rst" ,
174+ "verilog/adder.v"
175+ ]
176+
177+ yosys_path = shutil .which ("yosys" )
178+
179+ TEST_JINJA_DICT = {
180+ "verilog_diagrams_path" : "'{}'" .format (VERILOG_DIAGRAMS_PATH ),
181+ "master_doc" : "'test_yosys_path'" ,
182+ "custom_variables" : "verilog_diagram_yosys = '{}'" .format (yosys_path )
183+ }
184+
185+ self .prepare_test (TEST_NAME , TEST_BUILD_DIR , TEST_FILES , ** TEST_JINJA_DICT )
186+
187+ # Run the Sphinx
188+ sphinx_dirs = get_sphinx_dirs (TEST_BUILD_DIR )
189+ with docutils_namespace ():
190+ app = Sphinx (buildername = "html" , warningiserror = True , ** sphinx_dirs )
191+ app .build (force_all = True )
110192
111193if __name__ == '__main__' :
112194 unittest .main ()
0 commit comments