Change Lock.name to a property
Change current attribute "name" in Lock class to a read only property to prevent accidental external changes. Change-Id: I401dde68aad3aef1b254f2544a56c66fb3ea3e04
This commit is contained in:
parent
d75a7d2085
commit
7c8f910f55
|
@ -25,7 +25,11 @@ class Lock(object):
|
|||
def __init__(self, name):
|
||||
if not name:
|
||||
raise ValueError("Locks must be provided a name")
|
||||
self.name = name
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
def __enter__(self):
|
||||
self.acquire()
|
||||
|
|
|
@ -726,6 +726,11 @@ class TestAPI(testscenarios.TestWithScenarios,
|
|||
self.assertFalse(self._coord.is_started)
|
||||
self._coord.start()
|
||||
|
||||
def do_test_name_property(self):
|
||||
name = self._get_random_uuid()
|
||||
lock = self._coord.get_lock(name)
|
||||
self.assertEqual(name, lock.name)
|
||||
|
||||
@staticmethod
|
||||
def _get_random_uuid():
|
||||
return str(uuid.uuid4()).encode('ascii')
|
||||
|
|
Loading…
Reference in New Issue