python-tldp/tests/test_outputs.py

78 lines
2.2 KiB
Python
Raw Normal View History

2016-02-16 07:52:52 +00:00
from __future__ import absolute_import, division, print_function
import os
import errno
import unittest
from tempfile import NamedTemporaryFile as ntf
from tempfile import mkdtemp, mkstemp
import shutil
import random
try:
from types import SimpleNamespace
except ImportError:
from utils import SimpleNamespace
from tldptesttools import *
2016-02-16 07:52:52 +00:00
# -- Test Data
import example
2016-02-16 07:52:52 +00:00
# -- SUT
from tldp.outputs import OutputCollection
from tldp.outputs import OutputDirectory
from tldp.outputs import OutputNamingConvention
2016-02-16 07:52:52 +00:00
datadir = os.path.join(os.path.dirname(__file__), 'testdata')
class TestOutputNamingConvention(unittest.TestCase):
2016-02-16 07:52:52 +00:00
def test_namesets(self):
onc = OutputNamingConvention("Stem", "/path/to/output/")
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"))
self.assertTrue(onc.name_index.endswith("index.html"))
2016-02-16 07:52:52 +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)
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-16 07:52:52 +00:00
#
# -- end of file