diff --git a/kmip/core/attributes.py b/kmip/core/attributes.py index 0eabf25..4e34150 100644 --- a/kmip/core/attributes.py +++ b/kmip/core/attributes.py @@ -16,13 +16,12 @@ import six from kmip.core import enums +from kmip.core import exceptions from kmip.core.enums import HashingAlgorithm as HashingAlgorithmEnum from kmip.core.enums import KeyFormatType as KeyFormatTypeEnum from kmip.core.enums import Tags -from kmip.core.errors import ErrorStrings - from kmip.core.misc import KeyFormatType from kmip.core.primitives import Boolean @@ -138,7 +137,7 @@ class Name(Struct): def __validate(self): name = Name.__name__ - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV if self.name_value and \ not isinstance(self.name_value, Name.NameValue) and \ not isinstance(self.name_value, str): @@ -165,7 +164,7 @@ class Name(Struct): value = cls.NameValue(name_value) else: name = 'Name' - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV member = 'name_value' raise TypeError(msg.format('{0}.{1}'.format(name, member), 'name_value', type(Name.NameValue), @@ -177,7 +176,7 @@ class Name(Struct): n_type = cls.NameType(name_type) else: name = 'Name' - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV member = 'name_type' raise TypeError(msg.format('{0}.{1}'.format(name, member), 'name_type', type(Name.NameType), diff --git a/kmip/core/errors.py b/kmip/core/errors.py deleted file mode 100644 index acdf4e3..0000000 --- a/kmip/core/errors.py +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -class ErrorStrings: - BAD_EXP_RECV = "Bad {0} {1}: expected {2}, received {3}" - BAD_ENCODING = "Bad {0} {1}: encoding mismatch" - - -class BaseError(Exception): - """Base class for exceptions defined in this module.""" - - def __init__(self, args): - [setattr(self, k, v) for k, v in args.items() if k is not 'self'] - - -class KMIPServerError(BaseError): - """Base Exception for KMIP server errors.""" - def __init__(self, args): - super(KMIPServerError, self).__init__(args) - - -class KMIPServerZombieError(KMIPServerError): - """KMIP server error for hung and persistent live KMIP servers.""" - def __init__(self, pid): - message = 'KMIP server alive after termination: PID {0}'.format(pid) - super(KMIPServerZombieError, self).__init__({'message': message}) - - def __str__(self): - return self.message - - -class KMIPServerSuicideError(KMIPServerError): - """KMIP server error for prematurely dead KMIP servers.""" - def __init__(self, pid): - message = 'KMIP server dead prematurely: PID {0}'.format(pid) - super(KMIPServerSuicideError, self).__init__({'message': message}) - - def __str__(self): - return self.message - - -class InitError(BaseError): - """Exception thrown for bad initializations.""" - def __init__(self, cls, exp, recv): - super(InitError, self).__init__(locals()) - - def __str__(self): - msg = "Tried to initialize {0} instance with bad type: " - msg += "expected {1}, received {2}" - return msg.format(self.cls, self.exp, self.recv) - - -class WriteValueError(BaseError): - def __init__(self, cls, attr, value): - super(WriteValueError, self).__init__(locals()) - - def __str__(self): - msg = "Tried to write {0}.{1} with invalid value: {2}" - return msg.format(self.cls, self.attr, self.value) - - -class WriteTypeError(BaseError): - def __init__(self, cls, attr, value): - super(WriteTypeError, self).__init__(locals()) - - def __str__(self): - msg = "Tried to write {0}.{1} with invalid type: {2}" - return msg.format(self.cls, self.attr, self.value) - - -class WriteOverflowError(BaseError): - def __init__(self, cls, attr, exp, recv): - super(WriteOverflowError, self).__init__(locals()) - - def __str__(self): - msg = "Tried to write {0}.{1} with too many bytes: " - msg += "expected {2}, received {3}" - return msg.format(self.cls, self.attr, self.exp, self.recv) - - -class ReadValueError(BaseError): - def __init__(self, cls, attr, exp, recv): - super(ReadValueError, self).__init__(locals()) - - def __str__(self): - msg = "Tried to read {0}.{1}: expected {2}, received {3}" - return msg.format(self.cls, self.attr, self.exp, self.recv) - - -class InvalidLengthError(ValueError): - def __init__(self, cls, exp, recv): - msg = "Invalid length read for {0}: expected {1}, received {2}" - super(InvalidLengthError, self).__init__(msg.format(cls, exp, recv)) - - -class StreamNotEmptyError(BaseError): - def __init__(self, cls, extra): - super(StreamNotEmptyError, self).__init__(locals()) - - def __str__(self): - msg = "Invalid length used to read {0}, bytes remaining: {1}" - return msg.format(self.cls, self.extra) - - -class StateTypeError(TypeError): - def __init__(self, cls, exp, recv): - msg = "Tried to initialize {0} instance with bad type: " - msg += "expected {1}, received {2}" - super(StateTypeError, self).__init__(msg.format(cls, exp, recv)) - - -class StateOverflowError(ValueError): - def __init__(self, cls, attr, exp, recv): - msg = "Tried to write {0}.{1} with too many bytes: " - msg += "expected {2}, received {3}" - super(StateOverflowError, self).__init__(msg.format(cls, attr, exp, - recv)) diff --git a/kmip/core/exceptions.py b/kmip/core/exceptions.py index 368e5b2..30b609a 100644 --- a/kmip/core/exceptions.py +++ b/kmip/core/exceptions.py @@ -290,3 +290,73 @@ class InvalidPrimitiveLength(Exception): lengths. """ pass + + +class StreamNotEmptyError(Exception): + def __init__(self, cls, extra): + super(StreamNotEmptyError, self).__init__() + + self.cls = cls + self.extra = extra + + def __str__(self): + msg = "Invalid length used to read {0}, bytes remaining: {1}" + return msg.format(self.cls, self.extra) + + +class ReadValueError(Exception): + def __init__(self, cls, attr, exp, recv): + super(ReadValueError, self).__init__() + + self.cls = cls + self.attr = attr + self.exp = exp + self.recv = recv + + def __str__(self): + msg = "Tried to read {0}.{1}: expected {2}, received {3}" + return msg.format(self.cls, self.attr, self.exp, self.recv) + + +class WriteOverflowError(Exception): + def __init__(self, cls, attr, exp, recv): + super(WriteOverflowError, self).__init__() + + self.cls = cls + self.attr = attr + self.exp = exp + self.recv = recv + + def __str__(self): + msg = "Tried to write {0}.{1} with too many bytes: " + msg += "expected {2}, received {3}" + return msg.format(self.cls, self.attr, self.exp, self.recv) + + +class KMIPServerZombieError(Exception): + """KMIP server error for hung and persistent live KMIP servers.""" + def __init__(self, pid): + super(KMIPServerZombieError, self).__init__() + + self.message = 'KMIP server alive after termination: PID {0}'.format( + pid + ) + + def __str__(self): + return self.message + + +class KMIPServerSuicideError(Exception): + """KMIP server error for prematurely dead KMIP servers.""" + def __init__(self, pid): + super(KMIPServerSuicideError, self).__init__() + + self.message = 'KMIP server dead prematurely: PID {0}'.format(pid) + + def __str__(self): + return self.message + + +class ErrorStrings: + BAD_EXP_RECV = "Bad {0} {1}: expected {2}, received {3}" + BAD_ENCODING = "Bad {0} {1}: encoding mismatch" diff --git a/kmip/core/factories/secrets.py b/kmip/core/factories/secrets.py index c9b61b8..5b62da8 100644 --- a/kmip/core/factories/secrets.py +++ b/kmip/core/factories/secrets.py @@ -17,7 +17,6 @@ from kmip.core.attributes import CryptographicAlgorithm from kmip.core.attributes import CryptographicLength from kmip.core.enums import ObjectType -from kmip.core.errors import ErrorStrings from kmip.core.misc import KeyFormatType @@ -36,12 +35,13 @@ from kmip.core.secrets import SymmetricKey from kmip.core.secrets import Template from kmip.core import utils +from kmip.core import exceptions class SecretFactory(object): def __init__(self): - self.base_error = ErrorStrings.BAD_EXP_RECV + self.base_error = exceptions.ErrorStrings.BAD_EXP_RECV self.template_input = self.base_error.format('Template', '{0}', '{1}', '{2}') diff --git a/kmip/core/objects.py b/kmip/core/objects.py index 2c35cbb..20c38a3 100644 --- a/kmip/core/objects.py +++ b/kmip/core/objects.py @@ -27,8 +27,8 @@ from kmip.core.enums import Tags from kmip.core.enums import Types from kmip.core.enums import CredentialType from kmip.core.enums import RevocationReasonCode as RevocationReasonCodeEnum +from kmip.core import exceptions -from kmip.core.errors import ErrorStrings from kmip.core.misc import KeyFormatType from kmip.core import primitives @@ -474,8 +474,12 @@ class KeyBlock(Struct): member = 'KeyBlock.key_format_type' exp_type = KeyFormatType rcv_type = type(self.key_format_type) - msg = ErrorStrings.BAD_EXP_RECV.format(member, 'type', - exp_type, rcv_type) + msg = exceptions.ErrorStrings.BAD_EXP_RECV.format( + member, + 'type', + exp_type, + rcv_type + ) raise TypeError(msg) diff --git a/kmip/core/primitives.py b/kmip/core/primitives.py index 175305c..b979c85 100644 --- a/kmip/core/primitives.py +++ b/kmip/core/primitives.py @@ -22,10 +22,7 @@ import time from struct import pack, unpack -from kmip.core.errors import ErrorStrings - from kmip.core import enums -from kmip.core import errors from kmip.core import exceptions from kmip.core import utils @@ -45,7 +42,7 @@ class Base(object): def is_oversized(self, stream): extra = len(stream.peek()) if extra > 0: - raise errors.StreamNotEmptyError(Base.__name__, extra) + raise exceptions.StreamNotEmptyError(Base.__name__, extra) def read_tag(self, istream): # Read in the bytes for the tag @@ -56,8 +53,12 @@ class Base(object): # Verify that the tag matches for the current object if enum_tag is not self.tag: - raise errors.ReadValueError(Base.__name__, 'tag', - hex(self.tag.value), hex(tag)) + raise exceptions.ReadValueError( + Base.__name__, + 'tag', + hex(self.tag.value), + hex(tag) + ) def read_type(self, istream): # Read in the bytes for the type @@ -65,15 +66,23 @@ class Base(object): num_bytes = len(tts) if num_bytes != self.TYPE_SIZE: min_bytes = 'a minimum of {0} bytes'.format(self.TYPE_SIZE) - raise errors.ReadValueError(Base.__name__, 'type', min_bytes, - '{0} bytes'.format(num_bytes)) + raise exceptions.ReadValueError( + Base.__name__, + 'type', + min_bytes, + '{0} bytes'.format(num_bytes) + ) typ = unpack('!B', tts)[0] enum_typ = enums.Types(typ) if enum_typ is not self.type: - raise errors.ReadValueError(Base.__name__, 'type', - self.type.value, typ) + raise exceptions.ReadValueError( + Base.__name__, + 'type', + self.type.value, + typ + ) def read_length(self, istream): # Read in the bytes for the length @@ -81,8 +90,12 @@ class Base(object): num_bytes = len(lst) if num_bytes != self.LENGTH_SIZE: min_bytes = 'a minimum of {0} bytes'.format(self.LENGTH_SIZE) - raise errors.ReadValueError(Base.__name__, 'length', min_bytes, - '{0} bytes'.format(num_bytes)) + raise exceptions.ReadValueError( + Base.__name__, + 'length', + min_bytes, + '{0} bytes'.format(num_bytes) + ) self.length = unpack('!I', lst)[0] def read_value(self, istream): @@ -99,20 +112,24 @@ class Base(object): def write_type(self, ostream): if type(self.type) is not enums.Types: - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV raise TypeError(msg.format(Base.__name__, 'type', enums.Types, type(self.type))) ostream.write(pack('!B', self.type.value)) def write_length(self, ostream): if type(self.length) is not int: - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV raise TypeError(msg.format(Base.__name__, 'length', int, type(self.length))) num_bytes = utils.count_bytes(self.length) if num_bytes > self.LENGTH_SIZE: - raise errors.WriteOverflowError(Base.__name__, 'length', - self.LENGTH_SIZE, num_bytes) + raise exceptions.WriteOverflowError( + Base.__name__, + 'length', + self.LENGTH_SIZE, + num_bytes + ) ostream.write(pack('!I', self.length)) def write_value(self, ostream): @@ -188,15 +205,23 @@ class Integer(Base): def read_value(self, istream): if self.length is not self.LENGTH: - raise errors.ReadValueError(Integer.__name__, 'length', - self.LENGTH, self.length) + raise exceptions.ReadValueError( + Integer.__name__, + 'length', + self.LENGTH, + self.length + ) self.value = unpack(self.pack_string, istream.read(self.length))[0] pad = unpack(self.pack_string, istream.read(self.padding_length))[0] if pad is not 0: - raise errors.ReadValueError(Integer.__name__, 'pad', 0, - pad) + raise exceptions.ReadValueError( + Integer.__name__, + 'pad', + 0, + pad + ) self.validate() def read(self, istream): @@ -799,8 +824,12 @@ class TextString(Base): for _ in range(self.padding_length): pad = unpack('!B', istream.read(1))[0] if pad is not 0: - raise errors.ReadValueError(TextString.__name__, 'pad', 0, - pad) + raise exceptions.ReadValueError( + TextString.__name__, + 'pad', + 0, + pad + ) def read(self, istream): super(TextString, self).read(istream) @@ -826,7 +855,7 @@ class TextString(Base): def __validate(self): if self.value is not None: if not isinstance(self.value, six.string_types): - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV raise TypeError(msg.format('TextString', 'value', str, type(self.value))) @@ -890,8 +919,12 @@ class ByteString(Base): for _ in range(self.padding_length): pad = unpack('!B', istream.read(1))[0] if pad is not 0: - raise errors.ReadValueError(TextString.__name__, 'pad', 0, - pad) + raise exceptions.ReadValueError( + TextString.__name__, + 'pad', + 0, + pad + ) def read(self, istream): super(ByteString, self).read(istream) @@ -919,7 +952,7 @@ class ByteString(Base): if self.value is not None: data_type = type(self.value) if data_type is not bytes: - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV raise TypeError(msg.format('ByteString', 'value', bytes, data_type)) diff --git a/kmip/core/utils.py b/kmip/core/utils.py index 41b3882..8352580 100644 --- a/kmip/core/utils.py +++ b/kmip/core/utils.py @@ -16,7 +16,7 @@ from binascii import hexlify import io -from kmip.core.errors import ErrorStrings +from kmip.core import exceptions def bit_length(num): @@ -52,9 +52,8 @@ def is_stream_empty(stream): def build_er_error(class_object, descriptor, expected, received, attribute=None): - msg = ErrorStrings.BAD_EXP_RECV + msg = exceptions.ErrorStrings.BAD_EXP_RECV - class_string = '' if attribute is None: class_string = '{0}'.format(class_object.__name__) else: diff --git a/kmip/tests/integration/services/test_kmip_client.py b/kmip/tests/integration/services/test_kmip_client.py index 9dbefd3..47de636 100644 --- a/kmip/tests/integration/services/test_kmip_client.py +++ b/kmip/tests/integration/services/test_kmip_client.py @@ -35,8 +35,8 @@ from kmip.core.enums import KeyFormatType as KeyFormatTypeEnum from kmip.core.enums import ResultStatus from kmip.core.enums import ResultReason -from kmip.core.errors import KMIPServerSuicideError -from kmip.core.errors import KMIPServerZombieError +from kmip.core.exceptions import KMIPServerSuicideError +from kmip.core.exceptions import KMIPServerZombieError from kmip.core.factories.attributes import AttributeFactory from kmip.core.factories.credentials import CredentialFactory diff --git a/kmip/tests/unit/core/messages/test_messages.py b/kmip/tests/unit/core/messages/test_messages.py index f0105d4..20a6633 100644 --- a/kmip/tests/unit/core/messages/test_messages.py +++ b/kmip/tests/unit/core/messages/test_messages.py @@ -35,9 +35,7 @@ from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum from kmip.core.enums import CryptographicUsageMask from kmip.core.enums import NameType -from kmip.core import errors -from kmip.core.errors import ErrorStrings - +from kmip.core import exceptions from kmip.core import objects from kmip.core.messages import contents @@ -60,7 +58,7 @@ class TestRequestMessage(TestCase): super(TestRequestMessage, self).setUp() self.stream = BytearrayStream() self.attribute_factory = AttributeFactory() - self.msg = errors.ErrorStrings.BAD_EXP_RECV + self.msg = exceptions.ErrorStrings.BAD_EXP_RECV self.create = ( b'\x42\x00\x78\x01\x00\x00\x01\x20\x42\x00\x77\x01\x00\x00\x00\x38' b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04' @@ -735,28 +733,44 @@ class TestRequestMessage(TestCase): names = template_attribute.names exp_type = list rcv_type = type(names) - msg = ErrorStrings.BAD_EXP_RECV.format('TemplateAttribute.names', - 'type', '{0}', '{0}') + msg = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'TemplateAttribute.names', + 'type', + '{0}', + '{0}' + ) self.assertIsInstance(names, exp_type, msg.format(exp_type, rcv_type)) exp_length = 0 rcv_length = len(names) - msg = ErrorStrings.BAD_EXP_RECV.format('TemplateAttribute.names', - 'length', '{0}', '{0}') + msg = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'TemplateAttribute.names', + 'length', + '{0}', + '{0}' + ) self.assertEqual(exp_length, rcv_length, msg.format(exp_length, rcv_length)) attributes = template_attribute.attributes exp_type = list rcv_type = type(attributes) - msg = ErrorStrings.BAD_EXP_RECV.format( - 'TemplateAttribute.attributes', 'type', '{0}', '{1}') + msg = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'TemplateAttribute.attributes', + 'type', + '{0}', + '{1}' + ) self.assertIsInstance(names, exp_type, msg.format(exp_type, rcv_type)) exp_length = 0 rcv_length = len(attributes) - msg = ErrorStrings.BAD_EXP_RECV.format( - 'TemplateAttribute.attributes', 'length', '{0}', '{1}') + msg = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'TemplateAttribute.attributes', + 'length', + '{0}', + '{1}' + ) self.assertEqual(exp_length, rcv_length, msg.format(exp_length, rcv_length)) @@ -1144,7 +1158,7 @@ class TestResponseMessage(TestCase): super(TestResponseMessage, self).setUp() self.stream = BytearrayStream() self.secret_factory = SecretFactory() - self.msg = errors.ErrorStrings.BAD_EXP_RECV + self.msg = exceptions.ErrorStrings.BAD_EXP_RECV self.create = ( b'\x42\x00\x7B\x01\x00\x00\x00\xC0\x42\x00\x7A\x01\x00\x00\x00\x48' b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04' diff --git a/kmip/tests/unit/core/primitives/test_base.py b/kmip/tests/unit/core/primitives/test_base.py index 5df37c8..ca43f25 100644 --- a/kmip/tests/unit/core/primitives/test_base.py +++ b/kmip/tests/unit/core/primitives/test_base.py @@ -15,7 +15,7 @@ import testtools -from kmip.core import errors +from kmip.core import exceptions from kmip.core import primitives from kmip.core import utils @@ -26,11 +26,11 @@ class TestBase(testtools.TestCase): super(TestBase, self).setUp() self.stream = utils.BytearrayStream() self.bad_init = 'Bad Base initialization: attribute {0} missing' - self.bad_write = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_write = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.Base.{0}', 'write', '{1}', '{2}') - self.bad_encoding = errors.ErrorStrings.BAD_ENCODING.format( + self.bad_encoding = exceptions.ErrorStrings.BAD_ENCODING.format( 'primitives.Base.{0}', 'write') - self.bad_match = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_match = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.Base.{0}', 'comparison', '{1}', '{2}') def tearDown(self): @@ -44,7 +44,10 @@ class TestBase(testtools.TestCase): self.stream.write(b'\x00') base = primitives.Base() self.assertRaises( - errors.StreamNotEmptyError, base.is_oversized, self.stream) + exceptions.StreamNotEmptyError, + base.is_oversized, + self.stream + ) def test_read_tag(self): encoding = (b'\x42\x00\x00') @@ -56,7 +59,11 @@ class TestBase(testtools.TestCase): encoding = (b'\x42\x00\x01') base = primitives.Base() self.stream = utils.BytearrayStream(encoding) - self.assertRaises(errors.ReadValueError, base.read_tag, self.stream) + self.assertRaises( + exceptions.ReadValueError, + base.read_tag, + self.stream + ) def test_read_type(self): self.stream.write(b'\x00') @@ -66,11 +73,19 @@ class TestBase(testtools.TestCase): def test_read_type_error(self): self.stream.write(b'\x01') base = primitives.Base() - self.assertRaises(errors.ReadValueError, base.read_type, self.stream) + self.assertRaises( + exceptions.ReadValueError, + base.read_type, + self.stream + ) def test_read_type_underflow(self): base = primitives.Base() - self.assertRaises(errors.ReadValueError, base.read_type, self.stream) + self.assertRaises( + exceptions.ReadValueError, + base.read_type, + self.stream + ) def test_read_type_overflow(self): self.stream.write(b'\x00\x00') @@ -87,7 +102,11 @@ class TestBase(testtools.TestCase): self.stream.write(b'\x00') base = primitives.Base() base.length = 4 - self.assertRaises(errors.ReadValueError, base.read_length, self.stream) + self.assertRaises( + exceptions.ReadValueError, + base.read_length, + self.stream + ) def test_read_length_overflow(self): self.stream.write(b'\x00\x00\x00\x04\x00') diff --git a/kmip/tests/unit/core/primitives/test_byte_string.py b/kmip/tests/unit/core/primitives/test_byte_string.py index f8c9436..13e218f 100644 --- a/kmip/tests/unit/core/primitives/test_byte_string.py +++ b/kmip/tests/unit/core/primitives/test_byte_string.py @@ -15,7 +15,7 @@ import testtools -from kmip.core import errors +from kmip.core import exceptions from kmip.core import primitives from kmip.core import utils @@ -25,17 +25,17 @@ class TestByteString(testtools.TestCase): def setUp(self): super(TestByteString, self).setUp() self.stream = utils.BytearrayStream() - self.bad_type = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_type = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.ByteString.{0}', 'type', '{1}', '{2}') - self.bad_value = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_value = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.ByteString.{0}', 'value', '{1}', '{2}') - self.bad_read = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_read = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.ByteString.{0}', '', '{1}', '{2}') - self.bad_write = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_write = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.ByteString.{0}', 'write', '{1}', '{2}') - self.bad_encoding = errors.ErrorStrings.BAD_ENCODING.format( + self.bad_encoding = exceptions.ErrorStrings.BAD_ENCODING.format( 'primitives.ByteString', '') - self.bad_length = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_length = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.ByteString', 'length', '{0} bytes', '{1} bytes') def tearDown(self): @@ -142,7 +142,7 @@ class TestByteString(testtools.TestCase): self.stream = utils.BytearrayStream(encoding) bs = primitives.ByteString() - self.assertRaises(errors.ReadValueError, bs.read, self.stream) + self.assertRaises(exceptions.ReadValueError, bs.read, self.stream) def test_write_value(self): encoding = b'\x01\x02\x03\x00\x00\x00\x00\x00' diff --git a/kmip/tests/unit/core/primitives/test_integer.py b/kmip/tests/unit/core/primitives/test_integer.py index 02b05dd..9cfbfe2 100644 --- a/kmip/tests/unit/core/primitives/test_integer.py +++ b/kmip/tests/unit/core/primitives/test_integer.py @@ -15,7 +15,7 @@ import testtools -from kmip.core import errors +from kmip.core import exceptions from kmip.core import primitives from kmip.core import utils @@ -146,7 +146,11 @@ class TestInteger(testtools.TestCase): self.stream = utils.BytearrayStream(encoding) i = primitives.Integer() - self.assertRaises(errors.ReadValueError, i.read, self.stream) + self.assertRaises( + exceptions.ReadValueError, + i.read, + self.stream + ) def test_read_on_invalid_padding(self): encoding = ( @@ -155,7 +159,11 @@ class TestInteger(testtools.TestCase): self.stream = utils.BytearrayStream(encoding) i = primitives.Integer() - self.assertRaises(errors.ReadValueError, i.read, self.stream) + self.assertRaises( + exceptions.ReadValueError, + i.read, + self.stream + ) def test_write_value(self): encoding = (b'\x00\x00\x00\x01\x00\x00\x00\x00') diff --git a/kmip/tests/unit/core/primitives/test_text_string.py b/kmip/tests/unit/core/primitives/test_text_string.py index 9710f1d..fb1a78e 100644 --- a/kmip/tests/unit/core/primitives/test_text_string.py +++ b/kmip/tests/unit/core/primitives/test_text_string.py @@ -16,7 +16,7 @@ import six import testtools -from kmip.core import errors +from kmip.core import exceptions from kmip.core import primitives from kmip.core import utils @@ -26,17 +26,17 @@ class TestTextString(testtools.TestCase): def setUp(self): super(TestTextString, self).setUp() self.stream = utils.BytearrayStream() - self.bad_type = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_type = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.TextString.{0}', 'type', '{1}', '{2}') - self.bad_value = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_value = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.TextString.{0}', 'value', '{1}', '{2}') - self.bad_read = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_read = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.TextString.{0}', '', '{1}', '{2}') - self.bad_write = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_write = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.TextString.{0}', 'write', '{1}', '{2}') - self.bad_encoding = errors.ErrorStrings.BAD_ENCODING.format( + self.bad_encoding = exceptions.ErrorStrings.BAD_ENCODING.format( 'primitives.TextString', '') - self.bad_length = errors.ErrorStrings.BAD_EXP_RECV.format( + self.bad_length = exceptions.ErrorStrings.BAD_EXP_RECV.format( 'primitives.TextString', 'length', '{0} bytes', '{1} bytes') def tearDown(self): @@ -139,7 +139,7 @@ class TestTextString(testtools.TestCase): self.stream = utils.BytearrayStream(encoding) ts = primitives.TextString() - self.assertRaises(errors.ReadValueError, ts.read, self.stream) + self.assertRaises(exceptions.ReadValueError, ts.read, self.stream) def test_write_value(self): encoding = ( diff --git a/kmip/tests/unit/core/test_utils.py b/kmip/tests/unit/core/test_utils.py index 324f318..fbcc886 100644 --- a/kmip/tests/unit/core/test_utils.py +++ b/kmip/tests/unit/core/test_utils.py @@ -15,8 +15,7 @@ from testtools import TestCase -from kmip.core.errors import ErrorStrings - +from kmip.core import exceptions from kmip.core import utils @@ -62,12 +61,24 @@ class TestBytearrayStream(TestCase): super(TestBytearrayStream, self).setUp() self.stream = utils.BytearrayStream() - self.bad_type = ErrorStrings.BAD_EXP_RECV.format('BytearrayStream.{0}', - 'type', '{1}', '{2}') - self.bad_len = ErrorStrings.BAD_EXP_RECV.format('BytearrayStream.{0}', - 'length', '{1}', '{2}') - self.bad_val = ErrorStrings.BAD_EXP_RECV.format('BytearrayStream.{0}', - 'value', '{1}', '{2}') + self.bad_type = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'BytearrayStream.{0}', + 'type', + '{1}', + '{2}' + ) + self.bad_len = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'BytearrayStream.{0}', + 'length', + '{1}', + '{2}' + ) + self.bad_val = exceptions.ErrorStrings.BAD_EXP_RECV.format( + 'BytearrayStream.{0}', + 'value', + '{1}', + '{2}' + ) def tearDown(self): super(TestBytearrayStream, self).tearDown()