mirror of https://github.com/tLDP/python-tldp
try to simplify testing logic
lots of adjustments to testing to make it more understandable (and self-contained), although not much shorter
This commit is contained in:
parent
890464310a
commit
b9f606988b
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import unittest
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
|
@ -14,95 +15,46 @@ import example
|
||||||
import tldp.config
|
import tldp.config
|
||||||
import tldp.driver
|
import tldp.driver
|
||||||
|
|
||||||
|
opj = os.path.join
|
||||||
|
opd = os.path.dirname
|
||||||
|
opa = os.path.abspath
|
||||||
|
extras = opa(opj(opd(opd(__file__)), 'extras'))
|
||||||
|
|
||||||
widths = Namespace(status=20, stem=50)
|
widths = Namespace(status=20, stem=50)
|
||||||
|
|
||||||
|
|
||||||
class TestDriverDetail(TestInventoryBase):
|
class TestDriverDetail(TestInventoryBase):
|
||||||
|
|
||||||
def test_stale_detail_verbosity(self):
|
def test_stale_detail_verbosity(self):
|
||||||
|
c = self.config
|
||||||
self.add_stale('Frobnitz-HOWTO', example.ex_docbook4xml)
|
self.add_stale('Frobnitz-HOWTO', example.ex_docbook4xml)
|
||||||
config = Namespace(
|
c.verbose=True,
|
||||||
pubdir=self.pubdir,
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
sourcedir=self.sourcedirs,
|
|
||||||
verbose=True,
|
|
||||||
)
|
|
||||||
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
|
||||||
docs = inv.all.values()
|
docs = inv.all.values()
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
tldp.driver.detail(config, docs, file=stdout)
|
tldp.driver.detail(c, docs, file=stdout)
|
||||||
stdout.seek(0)
|
stdout.seek(0)
|
||||||
self.assertTrue('newer file' in stdout.read())
|
self.assertTrue('newer file' in stdout.read())
|
||||||
|
|
||||||
def test_broken_detail_verbosity(self):
|
def test_broken_detail_verbosity(self):
|
||||||
|
c = self.config
|
||||||
self.add_broken('Frobnitz-HOWTO', example.ex_docbook4xml)
|
self.add_broken('Frobnitz-HOWTO', example.ex_docbook4xml)
|
||||||
config = Namespace(
|
c.verbose=True,
|
||||||
pubdir=self.pubdir,
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
sourcedir=self.sourcedirs,
|
|
||||||
verbose=True,
|
|
||||||
)
|
|
||||||
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
|
||||||
docs = inv.all.values()
|
docs = inv.all.values()
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
tldp.driver.detail(config, docs, file=stdout)
|
tldp.driver.detail(c, docs, file=stdout)
|
||||||
stdout.seek(0)
|
stdout.seek(0)
|
||||||
self.assertTrue('missing file' in stdout.read())
|
self.assertTrue('missing file' in stdout.read())
|
||||||
|
|
||||||
|
|
||||||
class TestDriverBuild(TestInventoryBase):
|
|
||||||
|
|
||||||
def test_build_linuxdoc(self):
|
|
||||||
self.add_new('Frobnitz-Linuxdoc-HOWTO', example.ex_linuxdoc)
|
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
|
||||||
config.pubdir = self.pubdir
|
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
config.skip = []
|
|
||||||
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
|
||||||
self.assertEquals(1, len(inv.all.keys()))
|
|
||||||
docs = inv.all.values()
|
|
||||||
tldp.driver.build(config, docs)
|
|
||||||
doc = docs.pop(0)
|
|
||||||
self.assertTrue(doc.output.iscomplete)
|
|
||||||
|
|
||||||
def test_build_docbooksgml(self):
|
|
||||||
self.add_new('Frobnitz-DocBook-SGML-HOWTO', example.ex_docbooksgml)
|
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
|
||||||
config.pubdir = self.pubdir
|
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
config.skip = ['Frobnitz-DocBook-SGML-HOWTO']
|
|
||||||
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
|
||||||
self.assertEquals(1, len(inv.all.keys()))
|
|
||||||
docs = inv.all.values()
|
|
||||||
tldp.driver.build(config, docs)
|
|
||||||
doc = docs.pop(0)
|
|
||||||
self.assertFalse(doc.output.iscomplete)
|
|
||||||
# -- after figuring out collateindex and friends, this should say
|
|
||||||
# self.assertTrue(doc.output.iscomplete)
|
|
||||||
|
|
||||||
def test_build_docbook4xml(self):
|
|
||||||
self.add_new('Frobnitz-DocBook-XML-4-HOWTO', example.ex_docbook4xml)
|
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
|
||||||
config.pubdir = self.pubdir
|
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
config.skip = ['Frobnitz-DocBook-XML-4-HOWTO']
|
|
||||||
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
|
||||||
self.assertEquals(1, len(inv.all.keys()))
|
|
||||||
docs = inv.all.values()
|
|
||||||
tldp.driver.build(config, docs)
|
|
||||||
doc = docs.pop(0)
|
|
||||||
self.assertFalse(doc.output.iscomplete)
|
|
||||||
# -- after figuring out the XSL files at test time, this should say
|
|
||||||
# self.assertTrue(doc.output.iscomplete)
|
|
||||||
|
|
||||||
|
|
||||||
class TestDriverSummary(TestInventoryBase):
|
class TestDriverSummary(TestInventoryBase):
|
||||||
|
|
||||||
def test_summary(self):
|
def test_summary(self):
|
||||||
|
c = self.config
|
||||||
self.add_new('Frobnitz-DocBook-XML-4-HOWTO', example.ex_docbook4xml)
|
self.add_new('Frobnitz-DocBook-XML-4-HOWTO', example.ex_docbook4xml)
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
|
||||||
config.pubdir = self.pubdir
|
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
tldp.driver.summary(config, None, file=stdout)
|
tldp.driver.summary(c, None, file=stdout)
|
||||||
stdout.seek(0)
|
stdout.seek(0)
|
||||||
parts = stdout.read().split()
|
parts = stdout.read().split()
|
||||||
idx = parts.index('new')
|
idx = parts.index('new')
|
||||||
|
@ -112,38 +64,52 @@ class TestDriverSummary(TestInventoryBase):
|
||||||
class TestDriverRun(TestInventoryBase):
|
class TestDriverRun(TestInventoryBase):
|
||||||
|
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
|
c = self.config
|
||||||
ex = example.ex_linuxdoc
|
ex = example.ex_linuxdoc
|
||||||
self.add_published('Published-HOWTO', ex)
|
self.add_published('Published-HOWTO', ex)
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
self.add_stale('Stale-HOWTO', ex)
|
self.add_stale('Stale-HOWTO', ex)
|
||||||
self.add_orphan('Orphan-HOWTO', ex)
|
self.add_orphan('Orphan-HOWTO', ex)
|
||||||
self.add_broken('Broken-HOWTO', ex)
|
self.add_broken('Broken-HOWTO', ex)
|
||||||
argv = ['--pubdir', self.pubdir, '--sourcedir', self.sourcedir]
|
argv = ['--pubdir', c.pubdir, '--sourcedir', c.sourcedir[0]]
|
||||||
fullpath = os.path.join(self.tempdir, 'sources', 'Published-HOWTO.sgml')
|
fullpath = os.path.join(self.tempdir, 'sources', 'New-HOWTO.sgml')
|
||||||
argv.extend(['stale', 'Orphan-HOWTO', fullpath])
|
argv.extend(['--build', 'stale', 'Orphan-HOWTO', fullpath])
|
||||||
tldp.driver.run(argv)
|
tldp.driver.run(argv)
|
||||||
inv = tldp.inventory.Inventory(self.pubdir, self.sourcedirs)
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(3, len(inv.published.keys()))
|
self.assertEquals(4, len(inv.published.keys()))
|
||||||
|
self.assertEquals(1, len(inv.broken.keys()))
|
||||||
|
|
||||||
|
def test_run_extra_args(self):
|
||||||
|
c = self.config
|
||||||
|
self.add_new('New-HOWTO', example.ex_linuxdoc)
|
||||||
|
argv = ['--pubdir', c.pubdir, '--sourcedir', c.sourcedir[0]]
|
||||||
|
fullpath = os.path.join(self.tempdir, 'sources', 'New-HOWTO.sgml')
|
||||||
|
argv.extend(['--build', 'stale', 'Orphan-HOWTO', fullpath, 'extra'])
|
||||||
|
val = tldp.driver.run(argv)
|
||||||
|
self.assertTrue('Unknown arguments' in val)
|
||||||
|
|
||||||
def test_run_no_action(self):
|
def test_run_no_action(self):
|
||||||
|
c = self.config
|
||||||
ex = example.ex_linuxdoc
|
ex = example.ex_linuxdoc
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
argv = ['--pubdir', self.pubdir, '--sourcedir', self.sourcedir]
|
argv = ['--pubdir', c.pubdir, '--sourcedir', c.sourcedir[0]]
|
||||||
tldp.driver.run(argv)
|
tldp.driver.run(argv)
|
||||||
inv = tldp.inventory.Inventory(self.pubdir, self.sourcedirs)
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(1, len(inv.published.keys()))
|
self.assertEquals(1, len(inv.published.keys()))
|
||||||
|
|
||||||
def test_run_oops_no_sourcedir(self):
|
def test_run_oops_no_sourcedir(self):
|
||||||
|
c = self.config
|
||||||
ex = example.ex_linuxdoc
|
ex = example.ex_linuxdoc
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
argv = ['--pubdir', self.pubdir]
|
argv = ['--pubdir', c.pubdir]
|
||||||
exit = tldp.driver.run(argv)
|
exit = tldp.driver.run(argv)
|
||||||
self.assertTrue('required for inventory' in exit)
|
self.assertTrue('required for inventory' in exit)
|
||||||
|
|
||||||
def test_run_oops_no_pubdir(self):
|
def test_run_oops_no_pubdir(self):
|
||||||
|
c = self.config
|
||||||
ex = example.ex_linuxdoc
|
ex = example.ex_linuxdoc
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
argv = ['--sourcedir', self.sourcedir]
|
argv = ['--sourcedir', c.sourcedir[0]]
|
||||||
exit = tldp.driver.run(argv)
|
exit = tldp.driver.run(argv)
|
||||||
self.assertTrue('required for inventory' in exit)
|
self.assertTrue('required for inventory' in exit)
|
||||||
|
|
||||||
|
@ -151,57 +117,84 @@ class TestDriverRun(TestInventoryBase):
|
||||||
class TestDriverProcessSkips(TestInventoryBase):
|
class TestDriverProcessSkips(TestInventoryBase):
|
||||||
|
|
||||||
def test_skipDocuments_status(self):
|
def test_skipDocuments_status(self):
|
||||||
|
c = self.config
|
||||||
ex = example.ex_linuxdoc
|
ex = example.ex_linuxdoc
|
||||||
self.add_published('Published-HOWTO', ex)
|
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
self.add_stale('Stale-HOWTO', ex)
|
self.add_stale('Stale-HOWTO', ex)
|
||||||
self.add_orphan('Orphan-HOWTO', ex)
|
c.skip = ['stale']
|
||||||
self.add_broken('Broken-HOWTO', ex)
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
|
||||||
config.pubdir = self.pubdir
|
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
config.skip = ['stale']
|
|
||||||
inv = tldp.inventory.Inventory(self.pubdir, self.sourcedirs)
|
|
||||||
docs = inv.all.values()
|
docs = inv.all.values()
|
||||||
inc, exc = tldp.driver.processSkips(config, docs)
|
inc, exc = tldp.driver.processSkips(c, docs)
|
||||||
self.assertTrue(1, len(exc))
|
self.assertTrue(1, len(exc))
|
||||||
excluded = exc.pop()
|
excluded = exc.pop()
|
||||||
self.assertEquals(excluded.stem, 'Stale-HOWTO')
|
self.assertEquals(excluded.stem, 'Stale-HOWTO')
|
||||||
self.assertEquals(len(inc) + 1, len(inv.all.keys()))
|
self.assertEquals(len(inc) + 1, len(inv.all.keys()))
|
||||||
|
|
||||||
def test_skipDocuments_stem(self):
|
def test_skipDocuments_stem(self):
|
||||||
|
c = self.config
|
||||||
ex = example.ex_linuxdoc
|
ex = example.ex_linuxdoc
|
||||||
self.add_published('Published-HOWTO', ex)
|
self.add_published('Published-HOWTO', ex)
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
self.add_stale('Stale-HOWTO', ex)
|
c.skip = ['Published-HOWTO']
|
||||||
self.add_orphan('Orphan-HOWTO', ex)
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
self.add_broken('Broken-HOWTO', ex)
|
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
|
||||||
config.pubdir = self.pubdir
|
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
config.skip = ['Published-HOWTO']
|
|
||||||
inv = tldp.inventory.Inventory(self.pubdir, self.sourcedirs)
|
|
||||||
docs = inv.all.values()
|
docs = inv.all.values()
|
||||||
inc, exc = tldp.driver.processSkips(config, docs)
|
inc, exc = tldp.driver.processSkips(c, docs)
|
||||||
self.assertTrue(1, len(exc))
|
self.assertTrue(1, len(exc))
|
||||||
excluded = exc.pop()
|
excluded = exc.pop()
|
||||||
self.assertEquals(excluded.stem, 'Published-HOWTO')
|
self.assertEquals(excluded.stem, 'Published-HOWTO')
|
||||||
self.assertEquals(len(inc) + 1, len(inv.all.keys()))
|
self.assertEquals(len(inc) + 1, len(inv.all.keys()))
|
||||||
|
|
||||||
def test_skipDocuments_doctype(self):
|
def test_skipDocuments_doctype(self):
|
||||||
|
c = self.config
|
||||||
self.add_published('Linuxdoc-HOWTO', example.ex_linuxdoc)
|
self.add_published('Linuxdoc-HOWTO', example.ex_linuxdoc)
|
||||||
self.add_new('Docbook4XML-HOWTO', example.ex_docbook4xml)
|
self.add_new('Docbook4XML-HOWTO', example.ex_docbook4xml)
|
||||||
config, args = tldp.config.collectconfiguration('ldptool', [])
|
c.skip = ['Docbook4XML']
|
||||||
config.pubdir = self.pubdir
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
config.sourcedir = self.sourcedirs
|
|
||||||
config.skip = ['Docbook4XML']
|
|
||||||
inv = tldp.inventory.Inventory(self.pubdir, self.sourcedirs)
|
|
||||||
docs = inv.all.values()
|
docs = inv.all.values()
|
||||||
inc, exc = tldp.driver.processSkips(config, docs)
|
inc, exc = tldp.driver.processSkips(c, docs)
|
||||||
self.assertTrue(1, len(exc))
|
self.assertTrue(1, len(exc))
|
||||||
excluded = exc.pop()
|
excluded = exc.pop()
|
||||||
self.assertEquals(excluded.stem, 'Docbook4XML-HOWTO')
|
self.assertEquals(excluded.stem, 'Docbook4XML-HOWTO')
|
||||||
self.assertEquals(len(inc) + 1, len(inv.all.keys()))
|
self.assertEquals(len(inc) + 1, len(inv.all.keys()))
|
||||||
|
|
||||||
|
@unittest.skip("Except when you want to spend time....")
|
||||||
|
class TestDriverBuild(TestInventoryBase):
|
||||||
|
|
||||||
|
def test_build_linuxdoc(self):
|
||||||
|
c = self.config
|
||||||
|
self.add_new('Frobnitz-Linuxdoc-HOWTO', example.ex_linuxdoc)
|
||||||
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
|
self.assertEquals(1, len(inv.all.keys()))
|
||||||
|
docs = inv.all.values()
|
||||||
|
c.skip = []
|
||||||
|
tldp.driver.build(c, docs)
|
||||||
|
doc = docs.pop(0)
|
||||||
|
self.assertTrue(doc.output.iscomplete)
|
||||||
|
|
||||||
|
def test_build_docbooksgml(self):
|
||||||
|
c = self.config
|
||||||
|
self.add_new('Frobnitz-DocBook-SGML-HOWTO', example.ex_docbooksgml)
|
||||||
|
c.docbooksgml_collateindex = os.path.join(extras, 'collateindex.pl')
|
||||||
|
c.docbooksgml_ldpdsl = os.path.join(extras, 'ldp.dsl')
|
||||||
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
|
self.assertEquals(1, len(inv.all.keys()))
|
||||||
|
docs = inv.all.values()
|
||||||
|
tldp.driver.build(c, docs)
|
||||||
|
doc = docs.pop(0)
|
||||||
|
self.assertTrue(doc.output.iscomplete)
|
||||||
|
|
||||||
|
def test_build_docbook4xml(self):
|
||||||
|
c = self.config
|
||||||
|
self.add_new('Frobnitz-DocBook-XML-4-HOWTO', example.ex_docbook4xml)
|
||||||
|
c.docbook4xml_xslsingle = os.path.join(extras, 'ldp-html.xsl')
|
||||||
|
c.docbook4xml_xslprint = os.path.join(extras, 'ldp-print.xsl')
|
||||||
|
c.docbook4xml_xslchunk = os.path.join(extras, 'ldp-html-chunk.xsl')
|
||||||
|
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
|
||||||
|
self.assertEquals(1, len(inv.all.keys()))
|
||||||
|
docs = inv.all.values()
|
||||||
|
tldp.driver.build(c, docs)
|
||||||
|
doc = docs.pop(0)
|
||||||
|
self.assertTrue(doc.output.iscomplete)
|
||||||
|
|
||||||
#
|
#
|
||||||
# -- end of file
|
# -- end of file
|
||||||
|
|
|
@ -15,19 +15,21 @@ from tldp.inventory import Inventory
|
||||||
class TestInventoryUsage(TestInventoryBase):
|
class TestInventoryUsage(TestInventoryBase):
|
||||||
|
|
||||||
def test_inventory_repr(self):
|
def test_inventory_repr(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_published('Frobnitz-HOWTO', ex)
|
self.add_published('Frobnitz-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertTrue('1 published' in str(i))
|
self.assertTrue('1 published' in str(i))
|
||||||
|
|
||||||
def test_status_class_accessors(self):
|
def test_status_class_accessors(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_published('Published-HOWTO', ex)
|
self.add_published('Published-HOWTO', ex)
|
||||||
self.add_new('New-HOWTO', ex)
|
self.add_new('New-HOWTO', ex)
|
||||||
self.add_stale('Stale-HOWTO', ex)
|
self.add_stale('Stale-HOWTO', ex)
|
||||||
self.add_orphan('Orphan-HOWTO', ex)
|
self.add_orphan('Orphan-HOWTO', ex)
|
||||||
self.add_broken('Broken-HOWTO', ex)
|
self.add_broken('Broken-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertTrue('Orphan-HOWTO' in i.orphans.keys())
|
self.assertTrue('Orphan-HOWTO' in i.orphans.keys())
|
||||||
self.assertTrue('Orphan-HOWTO' in i.orphaned.keys())
|
self.assertTrue('Orphan-HOWTO' in i.orphaned.keys())
|
||||||
self.assertTrue(3, len(i.problems.keys()))
|
self.assertTrue(3, len(i.problems.keys()))
|
||||||
|
@ -37,9 +39,10 @@ class TestInventoryUsage(TestInventoryBase):
|
||||||
self.assertTrue(5, len(i.outputs.keys()))
|
self.assertTrue(5, len(i.outputs.keys()))
|
||||||
|
|
||||||
def test_detect_status_published(self):
|
def test_detect_status_published(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_published('Frobnitz-HOWTO', ex)
|
self.add_published('Frobnitz-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(0, len(i.stale))
|
self.assertEquals(0, len(i.stale))
|
||||||
self.assertEquals(1, len(i.published))
|
self.assertEquals(1, len(i.published))
|
||||||
self.assertEquals(0, len(i.new))
|
self.assertEquals(0, len(i.new))
|
||||||
|
@ -47,9 +50,10 @@ class TestInventoryUsage(TestInventoryBase):
|
||||||
self.assertEquals(0, len(i.broken))
|
self.assertEquals(0, len(i.broken))
|
||||||
|
|
||||||
def test_detect_status_new(self):
|
def test_detect_status_new(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_new('Frobnitz-HOWTO', ex)
|
self.add_new('Frobnitz-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(0, len(i.stale))
|
self.assertEquals(0, len(i.stale))
|
||||||
self.assertEquals(0, len(i.published))
|
self.assertEquals(0, len(i.published))
|
||||||
self.assertEquals(1, len(i.new))
|
self.assertEquals(1, len(i.new))
|
||||||
|
@ -57,9 +61,10 @@ class TestInventoryUsage(TestInventoryBase):
|
||||||
self.assertEquals(0, len(i.broken))
|
self.assertEquals(0, len(i.broken))
|
||||||
|
|
||||||
def test_detect_status_orphan(self):
|
def test_detect_status_orphan(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_orphan('Frobnitz-HOWTO', ex)
|
self.add_orphan('Frobnitz-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(0, len(i.stale))
|
self.assertEquals(0, len(i.stale))
|
||||||
self.assertEquals(0, len(i.published))
|
self.assertEquals(0, len(i.published))
|
||||||
self.assertEquals(0, len(i.new))
|
self.assertEquals(0, len(i.new))
|
||||||
|
@ -67,9 +72,10 @@ class TestInventoryUsage(TestInventoryBase):
|
||||||
self.assertEquals(0, len(i.broken))
|
self.assertEquals(0, len(i.broken))
|
||||||
|
|
||||||
def test_detect_status_stale(self):
|
def test_detect_status_stale(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_stale('Frobnitz-HOWTO', ex)
|
self.add_stale('Frobnitz-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(1, len(i.stale))
|
self.assertEquals(1, len(i.stale))
|
||||||
self.assertEquals(1, len(i.published))
|
self.assertEquals(1, len(i.published))
|
||||||
self.assertEquals(0, len(i.new))
|
self.assertEquals(0, len(i.new))
|
||||||
|
@ -77,9 +83,10 @@ class TestInventoryUsage(TestInventoryBase):
|
||||||
self.assertEquals(0, len(i.broken))
|
self.assertEquals(0, len(i.broken))
|
||||||
|
|
||||||
def test_detect_status_broken(self):
|
def test_detect_status_broken(self):
|
||||||
|
c = self.config
|
||||||
ex = random.choice(example.sources)
|
ex = random.choice(example.sources)
|
||||||
self.add_broken('Frobnitz-HOWTO', ex)
|
self.add_broken('Frobnitz-HOWTO', ex)
|
||||||
i = Inventory(self.pubdir, self.sourcedirs)
|
i = Inventory(c.pubdir, c.sourcedir)
|
||||||
self.assertEquals(0, len(i.stale))
|
self.assertEquals(0, len(i.stale))
|
||||||
self.assertEquals(1, len(i.published))
|
self.assertEquals(1, len(i.published))
|
||||||
self.assertEquals(0, len(i.new))
|
self.assertEquals(0, len(i.new))
|
||||||
|
|
|
@ -9,6 +9,7 @@ import unittest
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from tempfile import NamedTemporaryFile as ntf
|
from tempfile import NamedTemporaryFile as ntf
|
||||||
|
|
||||||
|
from tldp.config import collectconfiguration
|
||||||
from tldp.outputs import OutputNamingConvention
|
from tldp.outputs import OutputNamingConvention
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,15 +56,17 @@ class TestToolsFilesystem(unittest.TestCase):
|
||||||
return relpath, absdir
|
return relpath, absdir
|
||||||
|
|
||||||
def addfile(self, reldir, filename, stem=None, ext=None):
|
def addfile(self, reldir, filename, stem=None, ext=None):
|
||||||
|
dirname = os.path.join(self.tempdir, reldir)
|
||||||
|
assert os.path.isdir(dirname)
|
||||||
if stem is None:
|
if stem is None:
|
||||||
stem, _ = stem_and_ext(filename)
|
stem, _ = stem_and_ext(filename)
|
||||||
if ext is None:
|
if ext is None:
|
||||||
_, ext = stem_and_ext(filename)
|
_, ext = stem_and_ext(filename)
|
||||||
newname = os.path.join(self.tempdir, reldir, stem + ext)
|
newname = os.path.join(dirname, stem + ext)
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
shutil.copy(filename, newname)
|
shutil.copy(filename, newname)
|
||||||
else:
|
else:
|
||||||
with open(newname):
|
with open(newname, 'w') as f:
|
||||||
pass
|
pass
|
||||||
relname = os.path.relpath(newname, self.tempdir)
|
relname = os.path.relpath(newname, self.tempdir)
|
||||||
return relname, newname
|
return relname, newname
|
||||||
|
@ -106,6 +109,8 @@ class TestOutputDirSkeleton(OutputNamingConvention):
|
||||||
class TestSourceDocSkeleton(object):
|
class TestSourceDocSkeleton(object):
|
||||||
|
|
||||||
def __init__(self, dirname):
|
def __init__(self, dirname):
|
||||||
|
if isinstance(dirname, list):
|
||||||
|
dirname = dirname[0]
|
||||||
if not os.path.abspath(dirname):
|
if not os.path.abspath(dirname):
|
||||||
raise Exception("Please use absolute path in unit tests....")
|
raise Exception("Please use absolute path in unit tests....")
|
||||||
self.dirname = dirname
|
self.dirname = dirname
|
||||||
|
@ -121,34 +126,42 @@ class TestSourceDocSkeleton(object):
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
|
||||||
class TestInventoryBase(TestToolsFilesystem):
|
class TestInventoryBase(unittest.TestCase):
|
||||||
|
|
||||||
def setupcollections(self):
|
def setUp(self):
|
||||||
attrs = ('pubdir', 'sourcedir', 'sourcedirs')
|
self.makeTempdir()
|
||||||
already = all([hasattr(self, x) for x in attrs])
|
self.config, _ = collectconfiguration('ldptool', [])
|
||||||
if already:
|
c = self.config
|
||||||
return
|
c.pubdir = os.path.join(self.tempdir, 'outputs')
|
||||||
self.pubdir = os.path.join(self.tempdir, 'outputs')
|
c.sourcedir = os.path.join(self.tempdir, 'sources')
|
||||||
self.sourcedir = os.path.join(self.tempdir, 'sources')
|
for d in (c.sourcedir, c.pubdir):
|
||||||
self.sourcedirs = [self.sourcedir]
|
|
||||||
for d in (self.sourcedir, self.pubdir):
|
|
||||||
if not os.path.isdir(d):
|
if not os.path.isdir(d):
|
||||||
os.mkdir(d)
|
os.mkdir(d)
|
||||||
|
c.sourcedir = [c.sourcedir]
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.removeTempdir()
|
||||||
|
|
||||||
|
def makeTempdir(self):
|
||||||
|
self.tempdir = mkdtemp(prefix='tldp-test-')
|
||||||
|
|
||||||
|
def removeTempdir(self):
|
||||||
|
shutil.rmtree(self.tempdir)
|
||||||
|
|
||||||
def add_stale(self, stem, ex):
|
def add_stale(self, stem, ex):
|
||||||
self.setupcollections()
|
c = self.config
|
||||||
myoutput = TestOutputDirSkeleton(os.path.join(self.pubdir, stem), stem)
|
myoutput = TestOutputDirSkeleton(os.path.join(c.pubdir, stem), stem)
|
||||||
myoutput.mkdir()
|
myoutput.mkdir()
|
||||||
myoutput.create_expected_docs()
|
myoutput.create_expected_docs()
|
||||||
time.sleep(0.002)
|
time.sleep(0.001)
|
||||||
mysource = TestSourceDocSkeleton(self.sourcedir)
|
mysource = TestSourceDocSkeleton(c.sourcedir)
|
||||||
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
||||||
|
|
||||||
def add_broken(self, stem, ex):
|
def add_broken(self, stem, ex):
|
||||||
self.setupcollections()
|
c = self.config
|
||||||
mysource = TestSourceDocSkeleton(self.sourcedir)
|
mysource = TestSourceDocSkeleton(c.sourcedir)
|
||||||
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
||||||
myoutput = TestOutputDirSkeleton(os.path.join(self.pubdir, stem), stem)
|
myoutput = TestOutputDirSkeleton(os.path.join(c.pubdir, stem), stem)
|
||||||
myoutput.mkdir()
|
myoutput.mkdir()
|
||||||
myoutput.create_expected_docs()
|
myoutput.create_expected_docs()
|
||||||
prop = random.choice(myoutput.expected)
|
prop = random.choice(myoutput.expected)
|
||||||
|
@ -157,21 +170,21 @@ class TestInventoryBase(TestToolsFilesystem):
|
||||||
os.unlink(fname)
|
os.unlink(fname)
|
||||||
|
|
||||||
def add_new(self, stem, ex):
|
def add_new(self, stem, ex):
|
||||||
self.setupcollections()
|
c = self.config
|
||||||
mysource = TestSourceDocSkeleton(self.sourcedir)
|
mysource = TestSourceDocSkeleton(c.sourcedir)
|
||||||
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
||||||
|
|
||||||
def add_orphan(self, stem, ex):
|
def add_orphan(self, stem, ex):
|
||||||
self.setupcollections()
|
c = self.config
|
||||||
myoutput = TestOutputDirSkeleton(os.path.join(self.pubdir, stem), stem)
|
myoutput = TestOutputDirSkeleton(os.path.join(c.pubdir, stem), stem)
|
||||||
myoutput.mkdir()
|
myoutput.mkdir()
|
||||||
myoutput.create_expected_docs()
|
myoutput.create_expected_docs()
|
||||||
|
|
||||||
def add_published(self, stem, ex):
|
def add_published(self, stem, ex):
|
||||||
self.setupcollections()
|
c = self.config
|
||||||
mysource = TestSourceDocSkeleton(self.sourcedir)
|
mysource = TestSourceDocSkeleton(c.sourcedir)
|
||||||
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
mysource.addsourcefile(stem + ex.ext, ex.filename)
|
||||||
myoutput = TestOutputDirSkeleton(os.path.join(self.pubdir, stem), stem)
|
myoutput = TestOutputDirSkeleton(os.path.join(c.pubdir, stem), stem)
|
||||||
myoutput.mkdir()
|
myoutput.mkdir()
|
||||||
myoutput.create_expected_docs()
|
myoutput.create_expected_docs()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue