From ef355ad8fb1d823365debc32bb7887c044160ace Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Wed, 17 Feb 2016 19:30:25 -0800 Subject: [PATCH] add inventory category for broken outputs --- tests/test_inventory.py | 32 ++++++++++++++++++++++++++++++++ tldp/inventory.py | 11 ++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index b334f23..87445c4 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -74,6 +74,18 @@ class TestInventoryBase(TestToolsFilesystem): mysource = TestSourceDocSkeleton(self.sourcedir) mysource.addsourcefile(stem + ex.ext, ex.filename) + def add_broken(self, stem, ex): + self.setupcollections() + mysource = TestSourceDocSkeleton(self.sourcedir) + mysource.addsourcefile(stem + ex.ext, ex.filename) + myoutput = TestOutputDirSkeleton(os.path.join(self.pubdir, stem), stem) + myoutput.mkdir() + myoutput.create_expected_docs() + prop = random.choice(myoutput.expected) + fname = getattr(myoutput, prop, None) + assert fname is not None + os.unlink(fname) + def add_new(self, stem, ex): self.setupcollections() mysource = TestSourceDocSkeleton(self.sourcedir) @@ -96,6 +108,12 @@ class TestInventoryBase(TestToolsFilesystem): class TestInventoryUsage(TestInventoryBase): + def test_inventory_repr(self): + ex = random.choice(example.sources) + self.add_published('Frobnitz-HOWTO', ex) + i = Inventory(self.pubdir, self.sourcedirs) + self.assertTrue('1 published' in str(i)) + def test_detect_status_published(self): ex = random.choice(example.sources) self.add_published('Frobnitz-HOWTO', ex) @@ -104,6 +122,7 @@ class TestInventoryUsage(TestInventoryBase): self.assertEquals(1, len(i.published)) self.assertEquals(0, len(i.new)) self.assertEquals(0, len(i.orphans)) + self.assertEquals(0, len(i.broken)) def test_detect_status_new(self): ex = random.choice(example.sources) @@ -113,6 +132,7 @@ class TestInventoryUsage(TestInventoryBase): self.assertEquals(0, len(i.published)) self.assertEquals(1, len(i.new)) self.assertEquals(0, len(i.orphans)) + self.assertEquals(0, len(i.broken)) def test_detect_status_orphan(self): ex = random.choice(example.sources) @@ -122,6 +142,7 @@ class TestInventoryUsage(TestInventoryBase): self.assertEquals(0, len(i.published)) self.assertEquals(0, len(i.new)) self.assertEquals(1, len(i.orphans)) + self.assertEquals(0, len(i.broken)) def test_detect_status_stale(self): ex = random.choice(example.sources) @@ -131,6 +152,17 @@ class TestInventoryUsage(TestInventoryBase): self.assertEquals(1, len(i.published)) self.assertEquals(0, len(i.new)) self.assertEquals(0, len(i.orphans)) + self.assertEquals(0, len(i.broken)) + + def test_detect_status_stale(self): + ex = random.choice(example.sources) + self.add_broken('Frobnitz-HOWTO', ex) + i = Inventory(self.pubdir, self.sourcedirs) + self.assertEquals(0, len(i.stale)) + self.assertEquals(1, len(i.published)) + self.assertEquals(0, len(i.new)) + self.assertEquals(0, len(i.orphans)) + self.assertEquals(1, len(i.broken)) # # -- end of file diff --git a/tldp/inventory.py b/tldp/inventory.py index 4f9811a..7688969 100644 --- a/tldp/inventory.py +++ b/tldp/inventory.py @@ -15,12 +15,13 @@ from argparse import Namespace class Inventory(object): def __repr__(self): - return '<%s: %d published, %d orphans, %d new, %d stale>' % ( + return '<%s: %d published, %d orphans, %d new, %d stale, %d broken>' % ( self.__class__.__name__, len(self.published), len(self.orphans), len(self.new), len(self.stale), + len(self.broken), ) def __init__(self, pubdir, sourcedirs): @@ -76,6 +77,14 @@ class Inventory(object): logger.info("Identified %d stale documents: %r.", len(self.stale), self.stale.keys()) + # -- stale identification + # + self.broken = SourceCollection() + for stem, sdoc in s.items(): + if not sdoc.output.iscomplete: + self.broken[stem] = sdoc + logger.info("Identified %d broken documents: %r.", len(self.broken), + self.broken.keys()) def get_sources(sourcedirs): return SourceCollection(sourcedirs)