diff --git a/scripttease/factory.py b/scripttease/factory.py index c2ccda4..e8dc498 100644 --- a/scripttease/factory.py +++ b/scripttease/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 diff --git a/tests/test_factory.py b/tests/test_factory.py index 63002f2..b1f95a5 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -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()