Updated factory so that `get_command()` raises an error if the factory has not yet been loaded.

development
Shawn Davis 4 years ago
parent 2518a3e08b
commit 0a1fe58584
  1. 6
      scripttease/factory.py
  2. 5
      tests/test_factory.py

@ -43,7 +43,13 @@ class Factory(object):
:rtype: scripttease.library.commands.Command | scripttease.library.commands.ItemizedCommand
:raise: RuntimeError
:raises: ``RuntimeError`` if the factory has not yet been loaded.
"""
if not self.is_loaded:
raise RuntimeError("Factory has not been loaded, so no commands are available. Call load() method first!")
if not self.overlay.command_exists(name):
log.warning("Command does not exist in %s overlay: %s" % (self._overlay, name))
return None

@ -1,3 +1,4 @@
import pytest
from scripttease.library.commands import Command, ItemizedCommand
from scripttease.factory import Factory
@ -5,6 +6,10 @@ from scripttease.factory import Factory
class TestFactory(object):
def test_get_command(self):
f = Factory("ubuntu")
with pytest.raises(RuntimeError):
f.get_command("testing")
f = Factory("ubuntu")
f.load()

Loading…
Cancel
Save