From ce060fc5d037b29d348a30cb9bcc70b1ae6139d9 Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Tue, 16 Feb 2016 14:15:15 -0800 Subject: [PATCH] improving coverage of cases in OutputDirectory and OutputCollection --- tests/test_outputs.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index fc3ac24..fa0340c 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -17,7 +17,7 @@ except ImportError: from tldptesttools import * # -- Test Data -import examples +import example # -- SUT from tldp.outputs import OutputCollection @@ -27,12 +27,6 @@ from tldp.outputs import OutputNamingConvention datadir = os.path.join(os.path.dirname(__file__), 'testdata') -def stem_and_ext(name): - stem, ext = os.path.splitext(os.path.basename(name)) - assert ext != '' - return stem, ext - - class TestOutputNamingConvention(unittest.TestCase): def test_namesets(self): @@ -44,7 +38,7 @@ class TestOutputNamingConvention(unittest.TestCase): self.assertTrue(onc.name_index.endswith("index.html")) -class TestMissingOutputCollection(TestToolsFilesystem): +class TestOutputCollection(TestToolsFilesystem): def test_not_a_directory(self): missing = os.path.join(self.tempdir, 'vanishing') @@ -53,5 +47,31 @@ class TestMissingOutputCollection(TestToolsFilesystem): e = ecm.exception self.assertEquals(errno.ENOENT, e.errno) + def test_file_in_output_collection(self): + reldir, absdir = self.adddir('collection') + self.addfile('collection', __file__, stem='non-directory') + oc = OutputCollection(absdir) + self.assertEquals(0, len(oc)) + + def test_manyfiles(self): + reldir, absdir = self.adddir('manyfiles') + count = random.randint(8, 15) + for x in range(count): + self.adddir('manyfiles/Document-Stem-' + str(x)) + oc = OutputCollection(absdir) + self.assertEquals(count, len(oc)) + + +class TestOutputDirectory(TestToolsFilesystem): + + def test_no_parent_dir(self): + odoc = os.path.join(self.tempdir, 'non-existent-parent', 'stem') + with self.assertRaises(IOError) as ecm: + OutputDirectory(odoc) + e = ecm.exception + self.assertEquals(errno.ENOENT, e.errno) + + + # # -- end of file