mirror of https://github.com/tLDP/python-tldp
access inventory by status class name
create method getByStatusClass() and add testing
This commit is contained in:
parent
d807c02173
commit
56b1a027ca
|
@ -20,6 +20,22 @@ class TestInventoryUsage(TestInventoryBase):
|
|||
i = Inventory(self.pubdir, self.sourcedirs)
|
||||
self.assertTrue('1 published' in str(i))
|
||||
|
||||
def test_status_class_accessors(self):
|
||||
ex = random.choice(example.sources)
|
||||
self.add_published('Published-HOWTO', ex)
|
||||
self.add_new('New-HOWTO', ex)
|
||||
self.add_stale('Stale-HOWTO', ex)
|
||||
self.add_orphan('Orphan-HOWTO', ex)
|
||||
self.add_broken('Broken-HOWTO', ex)
|
||||
i = Inventory(self.pubdir, self.sourcedirs)
|
||||
self.assertTrue('Orphan-HOWTO' in i.orphans.keys())
|
||||
self.assertTrue('Orphan-HOWTO' in i.orphaned.keys())
|
||||
self.assertTrue(3, len(i.problems.keys()))
|
||||
self.assertTrue(4, len(i.work.keys()))
|
||||
self.assertTrue(5, len(i.all.keys()))
|
||||
self.assertTrue(5, len(i.sources.keys()))
|
||||
self.assertTrue(5, len(i.outputs.keys()))
|
||||
|
||||
def test_detect_status_published(self):
|
||||
ex = random.choice(example.sources)
|
||||
self.add_published('Frobnitz-HOWTO', ex)
|
||||
|
|
|
@ -147,5 +147,41 @@ class Inventory(object):
|
|||
logger.debug("Identified %d broken documents: %r.", len(self.broken),
|
||||
self.broken.keys())
|
||||
|
||||
def getByStatusClass(self, status_class):
|
||||
desired = status_classes.get(status_class, None)
|
||||
assert isinstance(desired, list)
|
||||
collection = SourceCollection()
|
||||
for status_type in desired:
|
||||
collection.update(getattr(self, status_type))
|
||||
return collection
|
||||
|
||||
@property
|
||||
def outputs(self):
|
||||
return self.getByStatusClass('outputs')
|
||||
|
||||
@property
|
||||
def sources(self):
|
||||
return self.getByStatusClass('sources')
|
||||
|
||||
@property
|
||||
def problems(self):
|
||||
return self.getByStatusClass('problems')
|
||||
|
||||
@property
|
||||
def work(self):
|
||||
return self.getByStatusClass('work')
|
||||
|
||||
@property
|
||||
def orphans(self):
|
||||
return self.getByStatusClass('orphans')
|
||||
|
||||
@property
|
||||
def orphaned(self):
|
||||
return self.getByStatusClass('orphaned')
|
||||
|
||||
@property
|
||||
def all(self):
|
||||
return self.getByStatusClass('all')
|
||||
|
||||
#
|
||||
# -- end of file
|
||||
|
|
Loading…
Reference in New Issue