Make the constant Sentinel() class public
This pattern can be useful so make it publicly available. Change-Id: I8fab1a5804aecf17a00a908646b6a20869c4a03b
This commit is contained in:
@@ -246,15 +246,18 @@ DEVICE_NAME_MAX_LEN = 15
|
||||
ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%f'
|
||||
|
||||
|
||||
class Sentinel(object):
|
||||
"""A constant object that does not change even when copied."""
|
||||
def __deepcopy__(self, memo):
|
||||
# Always return the same object because this is essentially a constant.
|
||||
return self
|
||||
|
||||
|
||||
#############################
|
||||
# Attribute related constants
|
||||
#############################
|
||||
class _Sentinel(object):
|
||||
def __deepcopy__(self, memo):
|
||||
# always return the same object because this is essentially a constant
|
||||
return self
|
||||
|
||||
ATTR_NOT_SPECIFIED = _Sentinel()
|
||||
ATTR_NOT_SPECIFIED = Sentinel()
|
||||
|
||||
HEX_ELEM = '[0-9A-Fa-f]'
|
||||
UUID_PATTERN = '-'.join([HEX_ELEM + '{8}', HEX_ELEM + '{4}',
|
||||
|
@@ -12,17 +12,16 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
test_neutron_lib
|
||||
----------------------------------
|
||||
import copy
|
||||
|
||||
Tests for `neutron_lib` module.
|
||||
"""
|
||||
from neutron_lib import constants
|
||||
|
||||
from neutron_lib.tests import _base as base
|
||||
|
||||
|
||||
class TestNeutron_lib(base.BaseTestCase):
|
||||
class TestNeutronLib(base.BaseTestCase):
|
||||
|
||||
def test_something(self):
|
||||
pass
|
||||
def test_sentinel_constant(self):
|
||||
foo = constants.Sentinel()
|
||||
bar = copy.deepcopy(foo)
|
||||
self.assertEqual(id(foo), id(bar))
|
||||
|
Reference in New Issue
Block a user