Browse Source

make sure that iter returns uniq objects..

main
John-Mark Gurney 2 years ago
parent
commit
0d258c04f4
2 changed files with 14 additions and 1 deletions
  1. +3
    -0
      ui/fixtures/cmd.basic.json
  2. +11
    -1
      ui/medashare/cli.py

+ 3
- 0
ui/fixtures/cmd.basic.json View File

@@ -178,6 +178,9 @@
"exit": 1,
"stderr": "ERROR: tag needs to start with a \"+\" (add) or a \"-\" (remove).\n"
},
{
"special": "iter is unique"
},
{
"skip": 1,
"title": "dump is correct",


+ 11
- 1
ui/medashare/cli.py View File

@@ -476,7 +476,13 @@ class ObjectStore(object):
return len(self._uuids)

def __iter__(self):
return iter(self._uuids.values())
seen = set()
for i in self._uuids.values():
if i['uuid'] in seen:
continue

yield i
seen.add(i['uuid'])

def store(self, fname):
'''Write out the objects in the store to the file named
@@ -1331,6 +1337,10 @@ class _TestCases(unittest.TestCase):
hostidpatch = mock.patch(__name__ + '.hostuuid')
hostidpatch.start().return_value = uuid.uuid4()
patches.append(hostidpatch)
elif special == 'iter is unique':
objst = ObjectStore.load(storefname)
uniqobjs = len(set((x['uuid'] for x in objst)))
self.assertEqual(len(list(objst)), uniqobjs)
else: # pragma: no cover
raise ValueError('unhandled special: %s' % repr(special))



Loading…
Cancel
Save