Skip to content

Commit 82c3f1c

Browse files
committed
Refactoring
1 parent b58fbb1 commit 82c3f1c

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

vunit/test/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def simulator_is(*names):
2121
"""
2222
Check that current simulator is any of names
2323
"""
24+
supported_names = [sim.name for sim in VUnit.supported_simulators()]
2425
for name in names:
25-
assert name in VUnit.available_simulators()
26+
assert name in supported_names
2627
return VUnit.select_simulator().name in names
2728

2829

vunit/ui.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
LOGGER = logging.getLogger(__name__)
4646

4747

48-
class VUnit(object): # pylint: disable=too-many-instance-attributes
48+
class VUnit(object): # pylint: disable=too-many-instance-attributes, too-many-public-methods
4949
"""
5050
The public interface of VUnit
5151
"""
@@ -141,37 +141,47 @@ def _create_argument_parser(cls):
141141
return parser
142142

143143
@staticmethod
144-
def available_simulators():
144+
def supported_simulators():
145+
"""
146+
Return a list of supported simulator classes
147+
"""
148+
return [ModelSimInterface]
149+
150+
@classmethod
151+
def available_simulators(cls):
145152
"""
146153
Return a list of available simulators
147154
"""
148-
sims = {}
149-
if ModelSimInterface.is_available():
150-
sims[ModelSimInterface.name] = ModelSimInterface
151-
if len(sims) == 0:
152-
raise RuntimeError("No simulator detected. "
153-
"Simulator executables must be available in PATH environment variable.")
154-
return sims
155+
return [simulator_class
156+
for simulator_class in cls.supported_simulators()
157+
if simulator_class.is_available()]
155158

156159
@classmethod
157160
def select_simulator(cls):
158161
"""
159162
Select simulator class, either from VUNIT_SIMULATOR environment variable
160163
or the first available
161164
"""
162-
simulators = cls.available_simulators()
163165
environ_name = "VUNIT_SIMULATOR"
164166

167+
available_simulators = cls.available_simulators()
168+
name_mapping = {simulator_class.name: simulator_class for simulator_class in cls.supported_simulators()}
169+
if len(available_simulators) == 0:
170+
raise RuntimeError("No available simulator detected. "
171+
"Simulator executables must be available in PATH environment variable.")
172+
165173
if environ_name in os.environ:
166174
simulator_name = os.environ[environ_name]
167-
if simulator_name not in simulators:
175+
if simulator_name not in name_mapping:
168176
raise RuntimeError(
169-
("Simulator from " + environ_name + " environment variable %r is not available. "
170-
"Available simulators are %r")
171-
% (simulator_name, simulators.keys()))
177+
("Simulator from " + environ_name + " environment variable %r is not supported. "
178+
"Supported simulators are %r")
179+
% (simulator_name, name_mapping.keys()))
180+
simulator_class = name_mapping[simulator_name]
172181
else:
173-
simulator_name = simulators.keys()[0]
174-
return simulators[simulator_name]
182+
simulator_class = available_simulators[0]
183+
184+
return simulator_class
175185

176186
def __init__(self, # pylint: disable=too-many-locals, too-many-arguments
177187
output_path,
@@ -221,7 +231,10 @@ def __init__(self, # pylint: disable=too-many-locals, too-many-arguments
221231
if simulator_class is not None:
222232
self._simulator_class = simulator_class
223233
else:
224-
self._simulator_class = self.available_simulators().values()[0]
234+
self._simulator_class = self.select_simulator()
235+
236+
if not self._simulator_class.is_available():
237+
raise AssertionError("Simulator %s is not available" % self._simulator_class.name)
225238

226239
self._sim_specific_path = join(self._output_path, self._simulator_class.name)
227240
self._create_output_path(clean)

0 commit comments

Comments
 (0)