Make sure ConfigType is an abstract class

Use the abstract class to ensure that all types provide the
method _formatter.

Change-Id: Ifa2e9ca7b91d71887d2bd4ce2e6bb21c2f616722
This commit is contained in:
ChangBo Guo(gcb) 2016-05-24 12:39:25 +08:00
parent 93e2449ab0
commit 1c02ce8ff3
2 changed files with 20 additions and 0 deletions

View File

@ -18,6 +18,25 @@ import unittest
from oslo_config import types
class ConfigTypeTests(unittest.TestCase):
def test_none_concrete_class(self):
class MyString(types.ConfigType):
def __init__(self, type_name='mystring value'):
super(MyString, self).__init__(type_name=type_name)
self.assertRaises(TypeError, MyString)
def test_concrete_class(self):
class MyString(types.ConfigType):
def __init__(self, type_name='mystring value'):
super(MyString, self).__init__(type_name=type_name)
def _formatter(self, value):
return value
MyString()
class TypeTestHelper(object):
def setUp(self):
super(TypeTestHelper, self).setUp()

View File

@ -28,6 +28,7 @@ import netaddr
import six
@six.add_metaclass(abc.ABCMeta)
class ConfigType(object):
def __init__(self, type_name='unknown type'):
self.type_name = type_name