2016-02-16 07:52:52 +00:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
|
import os
|
|
|
|
import errno
|
|
|
|
import unittest
|
|
|
|
import random
|
|
|
|
|
2016-02-17 03:55:40 +00:00
|
|
|
from tldptesttools import TestToolsFilesystem
|
2016-02-16 07:52:52 +00:00
|
|
|
|
|
|
|
# -- SUT
|
2016-02-16 18:57:44 +00:00
|
|
|
from tldp.outputs import OutputCollection
|
|
|
|
from tldp.outputs import OutputDirectory
|
|
|
|
from tldp.outputs import OutputNamingConvention
|
2016-02-16 07:52:52 +00:00
|
|
|
|
|
|
|
|
2016-02-16 18:57:44 +00:00
|
|
|
class TestOutputNamingConvention(unittest.TestCase):
|
2016-02-16 07:52:52 +00:00
|
|
|
|
2016-02-16 18:57:44 +00:00
|
|
|
def test_namesets(self):
|
2016-02-17 21:50:31 +00:00
|
|
|
onc = OutputNamingConvention("/path/to/output/", "Stem")
|
2016-02-16 18:57:44 +00:00
|
|
|
self.assertTrue(onc.name_txt.endswith(".txt"))
|
|
|
|
self.assertTrue(onc.name_pdf.endswith(".pdf"))
|
|
|
|
self.assertTrue(onc.name_html.endswith(".html"))
|
|
|
|
self.assertTrue(onc.name_htmls.endswith("-single.html"))
|
2016-02-18 17:15:47 +00:00
|
|
|
self.assertTrue(onc.name_indexhtml.endswith("index.html"))
|
2016-02-16 07:52:52 +00:00
|
|
|
|
|
|
|
|
2016-02-16 22:15:15 +00:00
|
|
|
class TestOutputCollection(TestToolsFilesystem):
|
2016-02-16 07:52:52 +00:00
|
|
|
|
|
|
|
def test_not_a_directory(self):
|
|
|
|
missing = os.path.join(self.tempdir, 'vanishing')
|
|
|
|
with self.assertRaises(IOError) as ecm:
|
|
|
|
OutputCollection(missing)
|
|
|
|
e = ecm.exception
|
|
|
|
self.assertEquals(errno.ENOENT, e.errno)
|
|
|
|
|
2016-02-16 22:15:15 +00:00
|
|
|
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)
|
|
|
|
|
2016-02-18 03:19:48 +00:00
|
|
|
def test_iscomplete(self):
|
|
|
|
reldir, absdir = self.adddir('outputs/Frobnitz-HOWTO')
|
|
|
|
o = OutputDirectory(absdir)
|
|
|
|
self.assertFalse(o.iscomplete)
|
|
|
|
for prop in o.expected:
|
|
|
|
fname = getattr(o, prop, None)
|
|
|
|
assert fname is not None
|
2016-02-18 03:36:52 +00:00
|
|
|
with open(fname, 'w'):
|
2016-02-18 03:19:48 +00:00
|
|
|
pass
|
|
|
|
self.assertTrue(o.iscomplete)
|
|
|
|
|
2016-02-16 07:52:52 +00:00
|
|
|
#
|
|
|
|
# -- end of file
|