read examples data from testdata dir; adapt tests

adapt tests to accommodate storing the test data in a separate directory
inspect example objects for signature checking (and extension checking)
adhere to pep8 and pyflakes conventions
This commit is contained in:
Martin A. Brown 2016-02-13 10:54:38 -08:00
parent 0ee20461f3
commit eaf2823fd6
3 changed files with 24 additions and 20 deletions

View File

@ -5,48 +5,49 @@ import os
import tldp.doctypes
datadir = os.path.join(os.path.dirname(__file__), 'testdata')
opj = os.path.join
testdatadir = os.path.join(os.path.dirname(__file__), 'testdata')
ex_linuxdoc = {
'ext': '.sgml',
'type': tldp.doctypes.linuxdoc.Linuxdoc,
'filename': os.path.join(datadir, 'linuxdoc-simple.sgml'),
'filename': opj(testdatadir, 'linuxdoc-simple.sgml'),
}
ex_docbooksgml = {
'ext': '.sgml',
'type': tldp.doctypes.docbooksgml.DocbookSGML,
'filename': os.path.join(datadir, 'docbooksgml-simple.sgml'),
'filename': opj(testdatadir, 'docbooksgml-simple.sgml'),
}
ex_docbook4xml = {
'ext': '.xml',
'type': tldp.doctypes.docbook4xml.Docbook4XML,
'filename': os.path.join(datadir, 'docbook4xml-simple.xml'),
'filename': opj(testdatadir, 'docbook4xml-simple.xml'),
}
ex_docbook5xml = {
'ext': '.xml',
'type': tldp.doctypes.docbook5xml.Docbook5XML,
'filename': os.path.join(datadir, 'docbook5xml-simple.xml'),
'filename': opj(testdatadir, 'docbook5xml-simple.xml'),
}
ex_rst = {
'ext': '.rst',
'type': tldp.doctypes.rst.RestructuredText,
'filename': os.path.join(datadir, 'restructuredtext-simple.rst'),
'filename': opj(testdatadir, 'restructuredtext-simple.rst'),
}
ex_text = {
'ext': '.txt',
'type': tldp.doctypes.text.Text,
'filename': os.path.join(datadir, 'text-simple.txt'),
'filename': opj(testdatadir, 'text-simple.txt'),
}
ex_markdown = {
'ext': '.md',
'type': tldp.doctypes.markdown.Markdown,
'filename': os.path.join(datadir, 'markdown-simple.md'),
'filename': opj(testdatadir, 'markdown-simple.md'),
}

View File

@ -6,10 +6,11 @@ import unittest
from tempfile import NamedTemporaryFile as ntf
# -- Test Data
from examples import *
import examples
# -- SUT
from tldp.typeguesser import guess
from tldp.doctypes.common import SignatureChecker
def genericGuessTest(content, ext):
@ -25,15 +26,16 @@ def genericGuessTest(content, ext):
class TestDoctypes(unittest.TestCase):
def testDetectionBySignature(self):
for example in (ex_linuxdoc, ex_docbooksgml, ex_docbook4xml,
ex_docbook5xml):
dt = genericGuessTest(example['content'], example['ext'])
self.assertEqual(example['type'], dt)
for ex in examples.examples:
if isinstance(ex['type'], SignatureChecker):
dt = genericGuessTest(ex['content'], ex['ext'])
self.assertEqual(ex['type'], dt)
def testDetectionByExtension(self):
for example in (ex_rst, ex_markdown, ex_text):
dt = genericGuessTest(example['content'], example['ext'])
self.assertEqual(example['type'], dt)
for ex in examples.examples:
if not isinstance(ex['type'], SignatureChecker):
dt = genericGuessTest(ex['content'], ex['ext'])
self.assertEqual(ex['type'], dt)
def testDetectionBogusExtension(self):
dt = genericGuessTest('franks-cheese-shop', '.wmix')
@ -51,12 +53,12 @@ class TestDoctypes(unittest.TestCase):
self.assertIsNone(dt)
def testGuessTooManyMatches(self):
a = ex_docbook4xml['content']
b = ex_docbook5xml['content']
four, fourdt = a + b, ex_docbook4xml['type']
a = examples.ex_docbook4xml['content']
b = examples.ex_docbook5xml['content']
four, fourdt = a + b, examples.ex_docbook4xml['type']
dt = genericGuessTest(four, '.xml')
self.assertIs(dt, fourdt)
five, fivedt = b + a, ex_docbook5xml['type']
five, fivedt = b + a, examples.ex_docbook5xml['type']
dt = genericGuessTest(five, '.xml')
self.assertIs(dt, fivedt)

View File

@ -32,6 +32,7 @@ class Test_which(unittest.TestCase):
self.assertEqual(f.name, found)
os.unlink(f.name)
class Test_makefh(unittest.TestCase):
def test_makefh(self):