From 56b1a027cacb4fbe85670085150e884647ec1cd5 Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Mon, 29 Feb 2016 18:03:16 -0800 Subject: [PATCH] access inventory by status class name create method getByStatusClass() and add testing --- tests/test_inventory.py | 16 ++++++++++++++++ tldp/inventory.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index f4509a8..eb6a868 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -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) diff --git a/tldp/inventory.py b/tldp/inventory.py index 0fc8a8c..df128c4 100644 --- a/tldp/inventory.py +++ b/tldp/inventory.py @@ -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