NoSuchTypeError -> InvalidTypeError
This commit is contained in:
parent
5e087fd280
commit
e6c5563a16
6 changed files with 15 additions and 8 deletions
|
@ -21,7 +21,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
from cdist.core.cdist_type import CdistType
|
from cdist.core.cdist_type import CdistType
|
||||||
from cdist.core.cdist_type import NoSuchTypeError
|
from cdist.core.cdist_type import NoSuchTypeError, InvalidTypeError
|
||||||
from cdist.core.cdist_object import CdistObject
|
from cdist.core.cdist_object import CdistObject
|
||||||
from cdist.core.cdist_object import IllegalObjectIdError
|
from cdist.core.cdist_object import IllegalObjectIdError
|
||||||
from cdist.core.explorer import Explorer
|
from cdist.core.explorer import Explorer
|
||||||
|
|
|
@ -32,10 +32,17 @@ class NoSuchTypeError(cdist.Error):
|
||||||
self.type_absolute_path = type_absolute_path
|
self.type_absolute_path = type_absolute_path
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Type '%s' does not exist at %s" % (
|
return "Type '%s' does not exist at '%s'" % (
|
||||||
self.type_path, self.type_absolute_path)
|
self.type_path, self.type_absolute_path)
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidTypeError(NoSuchTypeError):
|
||||||
|
def __str__(self):
|
||||||
|
return "Invalid type '%s' at '%s' defined at '%s'" % (
|
||||||
|
self.type_path, self.type_absolute_path,
|
||||||
|
os.path.realpath(self.type_absolute_path))
|
||||||
|
|
||||||
|
|
||||||
class CdistType(object):
|
class CdistType(object):
|
||||||
"""Represents a cdist type.
|
"""Represents a cdist type.
|
||||||
|
|
||||||
|
@ -51,7 +58,7 @@ class CdistType(object):
|
||||||
self.path = self.name
|
self.path = self.name
|
||||||
self.absolute_path = os.path.join(self.base_path, self.path)
|
self.absolute_path = os.path.join(self.base_path, self.path)
|
||||||
if not os.path.isdir(self.absolute_path):
|
if not os.path.isdir(self.absolute_path):
|
||||||
raise NoSuchTypeError(self.name, self.path, self.absolute_path)
|
raise InvalidTypeError(self.name, self.path, self.absolute_path)
|
||||||
self.manifest_path = os.path.join(self.name, "manifest")
|
self.manifest_path = os.path.join(self.name, "manifest")
|
||||||
self.explorer_path = os.path.join(self.name, "explorer")
|
self.explorer_path = os.path.join(self.name, "explorer")
|
||||||
self.gencode_local_path = os.path.join(self.name, "gencode-local")
|
self.gencode_local_path = os.path.join(self.name, "gencode-local")
|
||||||
|
|
|
@ -247,7 +247,7 @@ class Emulator(object):
|
||||||
# Raises an error, if object cannot be created
|
# Raises an error, if object cannot be created
|
||||||
try:
|
try:
|
||||||
cdist_object = self.cdist_object.object_from_name(requirement)
|
cdist_object = self.cdist_object.object_from_name(requirement)
|
||||||
except core.cdist_type.NoSuchTypeError as e:
|
except core.cdist_type.InvalidTypeError as e:
|
||||||
self.log.error(("%s requires object %s, but type %s does not"
|
self.log.error(("%s requires object %s, but type %s does not"
|
||||||
" exist. Defined at %s" % (
|
" exist. Defined at %s" % (
|
||||||
self.cdist_object.name,
|
self.cdist_object.name,
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TypeTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def test_nonexistent_type(self):
|
def test_nonexistent_type(self):
|
||||||
base_path = fixtures
|
base_path = fixtures
|
||||||
self.assertRaises(core.NoSuchTypeError, core.CdistType, base_path,
|
self.assertRaises(core.InvalidTypeError, core.CdistType, base_path,
|
||||||
'__i-dont-exist')
|
'__i-dont-exist')
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
|
|
|
@ -151,7 +151,7 @@ class ConfigRunTestCase(test.CdistTestCase):
|
||||||
"""Unknown type should be detected in the resolving process"""
|
"""Unknown type should be detected in the resolving process"""
|
||||||
first = self.object_index['__first/man']
|
first = self.object_index['__first/man']
|
||||||
first.requirements = ['__nosuchtype/not/exist']
|
first.requirements = ['__nosuchtype/not/exist']
|
||||||
with self.assertRaises(cdist.core.cdist_type.NoSuchTypeError):
|
with self.assertRaises(cdist.core.cdist_type.InvalidTypeError):
|
||||||
self.config.iterate_until_finished()
|
self.config.iterate_until_finished()
|
||||||
|
|
||||||
def test_requirement_singleton_where_no_singleton(self):
|
def test_requirement_singleton_where_no_singleton(self):
|
||||||
|
|
|
@ -76,14 +76,14 @@ class EmulatorTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def test_nonexistent_type_exec(self):
|
def test_nonexistent_type_exec(self):
|
||||||
argv = ['__does-not-exist']
|
argv = ['__does-not-exist']
|
||||||
self.assertRaises(core.cdist_type.NoSuchTypeError, emulator.Emulator,
|
self.assertRaises(core.cdist_type.InvalidTypeError, emulator.Emulator,
|
||||||
argv, env=self.env)
|
argv, env=self.env)
|
||||||
|
|
||||||
def test_nonexistent_type_requirement(self):
|
def test_nonexistent_type_requirement(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
self.env['require'] = '__does-not-exist/some-id'
|
self.env['require'] = '__does-not-exist/some-id'
|
||||||
emu = emulator.Emulator(argv, env=self.env)
|
emu = emulator.Emulator(argv, env=self.env)
|
||||||
self.assertRaises(core.cdist_type.NoSuchTypeError, emu.run)
|
self.assertRaises(core.cdist_type.InvalidTypeError, emu.run)
|
||||||
|
|
||||||
def test_illegal_object_id_requirement(self):
|
def test_illegal_object_id_requirement(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
|
|
Loading…
Reference in a new issue