Skip to content

Commit d2865ed

Browse files
committed
Use Paths rather than strings where possible
1 parent fbe8d06 commit d2865ed

17 files changed

+194
-179
lines changed

tests/unit/test_activehdl_interface.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _test_compile_project_vhdl(self, standard, process, check_output):
7070
str(Path("prefix") / "vcom"),
7171
"-quiet",
7272
"-j",
73-
self.output_path,
73+
str(self.output_path),
7474
f"-{standard}",
7575
"-work",
7676
"lib",
@@ -116,7 +116,7 @@ def test_compile_project_vhdl_extra_flags(self, process, check_output):
116116
str(Path("prefix") / "vcom"),
117117
"-quiet",
118118
"-j",
119-
self.output_path,
119+
str(self.output_path),
120120
"custom",
121121
"flags",
122122
"-2008",
@@ -322,7 +322,7 @@ def test_supports_vhdl_package_generics_false(self, find_prefix):
322322
self.assertFalse(simif.supports_vhdl_package_generics())
323323

324324
def setUp(self):
325-
self.output_path = str(Path(__file__).parent / "test_activehdl_out")
325+
self.output_path = Path(__file__).parent / "test_activehdl_out"
326326
renew_path(self.output_path)
327327
self.project = Project()
328328
self.cwd = os.getcwd()

tests/unit/test_incisive_interface.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,12 @@ def test_simulate_vhdl(self, run_command, find_cds_root_irun, find_cds_root_virt
514514
"-f",
515515
Path(elaborate_args_file).name,
516516
],
517-
cwd=str(Path(elaborate_args_file).parent),
517+
cwd=Path(elaborate_args_file).parent,
518518
env=simif.get_env(),
519519
),
520520
mock.call(
521521
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
522-
cwd=str(Path(simulate_args_file).parent),
522+
cwd=Path(simulate_args_file).parent,
523523
env=simif.get_env(),
524524
),
525525
]
@@ -602,12 +602,12 @@ def test_simulate_verilog(self, run_command, find_cds_root_irun, find_cds_root_v
602602
"-f",
603603
Path(elaborate_args_file).name,
604604
],
605-
cwd=str(Path(elaborate_args_file).parent),
605+
cwd=Path(elaborate_args_file).parent,
606606
env=simif.get_env(),
607607
),
608608
mock.call(
609609
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
610-
cwd=str(Path(simulate_args_file).parent),
610+
cwd=Path(simulate_args_file).parent,
611611
env=simif.get_env(),
612612
),
613613
]
@@ -681,12 +681,12 @@ def test_simulate_extra_flags(self, run_command, find_cds_root_irun, find_cds_ro
681681
"-f",
682682
Path(elaborate_args_file).name,
683683
],
684-
cwd=str(Path(elaborate_args_file).parent),
684+
cwd=Path(elaborate_args_file).parent,
685685
env=simif.get_env(),
686686
),
687687
mock.call(
688688
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
689-
cwd=str(Path(simulate_args_file).parent),
689+
cwd=Path(simulate_args_file).parent,
690690
env=simif.get_env(),
691691
),
692692
]
@@ -719,12 +719,12 @@ def test_simulate_generics_and_parameters(self, run_command, find_cds_root_irun,
719719
"-f",
720720
Path(elaborate_args_file).name,
721721
],
722-
cwd=str(Path(elaborate_args_file).parent),
722+
cwd=Path(elaborate_args_file).parent,
723723
env=simif.get_env(),
724724
),
725725
mock.call(
726726
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
727-
cwd=str(Path(simulate_args_file).parent),
727+
cwd=Path(simulate_args_file).parent,
728728
env=simif.get_env(),
729729
),
730730
]
@@ -755,12 +755,12 @@ def test_simulate_hdlvar(self, run_command, find_cds_root_irun, find_cds_root_vi
755755
"-f",
756756
Path(elaborate_args_file).name,
757757
],
758-
cwd=str(Path(elaborate_args_file).parent),
758+
cwd=Path(elaborate_args_file).parent,
759759
env=simif.get_env(),
760760
),
761761
mock.call(
762762
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
763-
cwd=str(Path(simulate_args_file).parent),
763+
cwd=Path(simulate_args_file).parent,
764764
env=simif.get_env(),
765765
),
766766
]
@@ -788,7 +788,7 @@ def test_elaborate(self, run_command, find_cds_root_irun, find_cds_root_virtuoso
788788
"-f",
789789
Path(elaborate_args_file).name,
790790
],
791-
cwd=str(Path(elaborate_args_file).parent),
791+
cwd=Path(elaborate_args_file).parent,
792792
env=simif.get_env(),
793793
)
794794
]
@@ -836,7 +836,7 @@ def test_elaborate_fail(self, run_command, find_cds_root_irun, find_cds_root_vir
836836
"-f",
837837
Path(elaborate_args_file).name,
838838
],
839-
cwd=str(Path(elaborate_args_file).parent),
839+
cwd=Path(elaborate_args_file).parent,
840840
env=simif.get_env(),
841841
)
842842
]
@@ -861,12 +861,12 @@ def test_simulate_fail(self, run_command, find_cds_root_irun, find_cds_root_virt
861861
"-f",
862862
Path(elaborate_args_file).name,
863863
],
864-
cwd=str(Path(elaborate_args_file).parent),
864+
cwd=Path(elaborate_args_file).parent,
865865
env=simif.get_env(),
866866
),
867867
mock.call(
868868
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
869-
cwd=str(Path(simulate_args_file).parent),
869+
cwd=Path(simulate_args_file).parent,
870870
env=simif.get_env(),
871871
),
872872
]
@@ -899,12 +899,12 @@ def test_simulate_gui(self, run_command, find_cds_root_irun, find_cds_root_virtu
899899
"-f",
900900
Path(elaborate_args_file).name,
901901
],
902-
cwd=str(Path(elaborate_args_file).parent),
902+
cwd=Path(elaborate_args_file).parent,
903903
env=simif.get_env(),
904904
),
905905
mock.call(
906906
[str(Path("prefix") / "irun"), "-f", Path(simulate_args_file).name],
907-
cwd=str(Path(simulate_args_file).parent),
907+
cwd=Path(simulate_args_file).parent,
908908
env=simif.get_env(),
909909
),
910910
]
@@ -974,7 +974,7 @@ def test_configuration_and_entity_selection(self, find_cds_root_irun, find_cds_r
974974
self.assertEqual(simif._select_vhdl_top(config), "lib.tb_entity:arch") # pylint: disable=protected-access
975975

976976
def setUp(self):
977-
self.output_path = str(Path(__file__).parent / "test_incisive_out")
977+
self.output_path = Path(__file__).parent / "test_incisive_out"
978978
renew_path(self.output_path)
979979
self.project = Project()
980980
self.cwd = os.getcwd()

tests/unit/test_modelsim_interface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ def test_overwrites_modelsim_ini_file_from_user(self):
319319
def setUp(self):
320320
self.test_path = str(Path(__file__).parent / "test_modelsim_out")
321321

322-
self.output_path = str(Path(self.test_path) / "modelsim")
322+
self.output_path = Path(self.test_path) / "modelsim"
323323
self.prefix_path = str(Path(self.test_path) / "prefix" / "bin")
324324
renew_path(self.test_path)
325325
renew_path(self.output_path)
326326
renew_path(self.prefix_path)
327327
installed_modelsim_ini = str(Path(self.prefix_path) / ".." / "modelsim.ini")
328328
write_file(installed_modelsim_ini, "[Library]")
329329
self.project = Project()
330-
self.cwd = os.getcwd()
330+
self.cwd = Path(os.getcwd())
331331
os.chdir(self.test_path)
332332

333333
def tearDown(self):

tests/unit/test_rivierapro_interface.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_compile_project_vhdl_2019(self, _find_prefix, process, check_output):
5050
str(Path("prefix") / "vcom"),
5151
"-quiet",
5252
"-j",
53-
self.output_path,
53+
str(self.output_path),
5454
"-2019",
5555
"-work",
5656
"lib",
@@ -84,7 +84,7 @@ def test_compile_project_vhdl_2008(self, _find_prefix, process, check_output):
8484
str(Path("prefix") / "vcom"),
8585
"-quiet",
8686
"-j",
87-
self.output_path,
87+
str(self.output_path),
8888
"-2008",
8989
"-work",
9090
"lib",
@@ -118,7 +118,7 @@ def test_compile_project_vhdl_2002(self, _find_prefix, process, check_output):
118118
str(Path("prefix") / "vcom"),
119119
"-quiet",
120120
"-j",
121-
self.output_path,
121+
str(self.output_path),
122122
"-2002",
123123
"-work",
124124
"lib",
@@ -152,7 +152,7 @@ def test_compile_project_vhdl_93(self, _find_prefix, process, check_output):
152152
str(Path("prefix") / "vcom"),
153153
"-quiet",
154154
"-j",
155-
self.output_path,
155+
str(self.output_path),
156156
"-93",
157157
"-work",
158158
"lib",
@@ -187,7 +187,7 @@ def test_compile_project_vhdl_extra_flags(self, _find_prefix, process, check_out
187187
str(Path("prefix") / "vcom"),
188188
"-quiet",
189189
"-j",
190-
self.output_path,
190+
str(self.output_path),
191191
"custom",
192192
"flags",
193193
"-2008",
@@ -385,7 +385,7 @@ def test_compile_project_verilog_define(self, _find_prefix, process, check_outpu
385385
)
386386

387387
def setUp(self):
388-
self.output_path = str(Path(__file__).parent / "test_rivierapro_out")
388+
self.output_path = Path(__file__).parent / "test_rivierapro_out"
389389
renew_path(self.output_path)
390390
self.project = Project()
391391
self.cwd = os.getcwd()

tests/unit/test_test_runner.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ def test_get_output_path_on_linux(self):
146146
test_output = runner._get_output_path(test_name)
147147
self.assertEqual(
148148
test_output,
149-
str(Path(output_path).resolve() / (test_name + "_" + hash_string(test_name))),
149+
Path(output_path).resolve() / (test_name + "_" + hash_string(test_name)),
150150
)
151151

152152
output_path = "output_path"
153153
test_name = "123._-+"
154154
test_output = runner._get_output_path(test_name)
155155
self.assertEqual(
156156
test_output,
157-
str(Path(output_path).resolve() / (test_name + "_" + hash_string(test_name))),
157+
Path(output_path).resolve() / (test_name + "_" + hash_string(test_name)),
158158
)
159159

160160
output_path = "output_path"
@@ -163,7 +163,7 @@ def test_get_output_path_on_linux(self):
163163
test_output = runner._get_output_path(test_name)
164164
self.assertEqual(
165165
test_output,
166-
str(Path(output_path).resolve() / (safe_name + "_" + hash_string(test_name))),
166+
Path(output_path).resolve() / (safe_name + "_" + hash_string(test_name)),
167167
)
168168

169169
def test_get_output_path_on_windows(self):
@@ -175,15 +175,15 @@ def test_get_output_path_on_windows(self):
175175
with mock.patch("os.environ", new={}):
176176
test_name = "_" * 400
177177
test_output = runner._get_output_path(test_name)
178-
self.assertEqual(len(test_output), 260 - 100 + 1)
178+
self.assertEqual(len(str(test_output)), 260 - 100 + 1)
179179

180180
with mock.patch("os.environ", new={"VUNIT_TEST_OUTPUT_PATH_MARGIN": "-1000"}):
181181
output_path = "output_path"
182182
test_name = "_" * 400
183183
test_output = runner._get_output_path(test_name)
184184
self.assertEqual(
185185
test_output,
186-
str(Path(output_path).resolve() / (test_name + "_" + hash_string(test_name))),
186+
Path(output_path).resolve() / (test_name + "_" + hash_string(test_name)),
187187
)
188188

189189
with mock.patch("os.environ", new={"VUNIT_SHORT_TEST_OUTPUT_PATHS": ""}):
@@ -192,7 +192,7 @@ def test_get_output_path_on_windows(self):
192192
test_output = runner._get_output_path(test_name)
193193
self.assertEqual(
194194
test_output,
195-
str(Path(output_path).resolve() / hash_string(test_name)),
195+
Path(output_path).resolve() / hash_string(test_name),
196196
)
197197

198198
@staticmethod

vunit/sim_if/__init__.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class SimulatorInterface(object): # pylint: disable=too-many-public-methods
5050
supports_colors_in_gui = False
5151

5252
def __init__(self, output_path, gui):
53-
self._output_path = output_path
53+
self._output_path = Path(output_path)
5454
self._gui = gui
5555

5656
@property
57-
def output_path(self):
57+
def output_path(self) -> Path:
5858
return self._output_path
5959

6060
@property
@@ -319,6 +319,17 @@ def get_env():
319319
Allows inheriting classes to overload this to modify environment variables. Return None for default environment
320320
"""
321321

322+
def get_script_path(self, output_path) -> Path:
323+
"""
324+
Get path for scripts.
325+
326+
Also creates the required directories if they do not exist.
327+
"""
328+
script_path = Path(output_path) / self.name
329+
if not script_path.exists():
330+
script_path.mkdir(parents=True)
331+
return script_path
332+
322333

323334
def isfile(file_name):
324335
"""

0 commit comments

Comments
 (0)