diff --git a/tests/test_sources.py b/tests/test_sources.py index d4f093b..f2a3b26 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -19,7 +19,8 @@ from tldptesttools import TestToolsFilesystem import example # -- SUT -from tldp.sources import SourceCollection, SourceDocument, scansourcedirs +from tldp.sources import SourceCollection, SourceDocument +from tldp.sources import scansourcedirs, sourcedoc_fromdir sampledocs = os.path.join(os.path.dirname(__file__), 'sample-documents') @@ -139,6 +140,11 @@ class TestSourceDocument(unittest.TestCase): doc = SourceDocument(dirname) self.assertIsInstance(doc, SourceDocument) + def test_sourcedoc_fromdir_withdots(self): + dirname = os.path.dirname(example.ex_docbook4xml_dir.filename) + doc = sourcedoc_fromdir(dirname) + self.assertIsNotNone(doc) + def test_detail(self): ex = example.ex_linuxdoc_dir s = SourceDocument(ex.filename) diff --git a/tldp/sources.py b/tldp/sources.py index 41784ea..8d22d43 100644 --- a/tldp/sources.py +++ b/tldp/sources.py @@ -87,18 +87,19 @@ def arg_issourcedoc(filename): return None -def sourcedoc_fromdir(dirname): +def sourcedoc_fromdir(name): candidates = list() - stem, _ = stem_and_ext(dirname) - parentdir = os.path.dirname(dirname) + if not os.path.isdir(name): + return None + stem = os.path.basename(name) for ext in knownextensions: - possible = os.path.join(parentdir, stem, stem + ext) + possible = os.path.join(name, stem + ext) if os.path.isfile(possible): candidates.append(possible) if len(candidates) > 1: logger.warning("%s multiple document choices in dir %s, bailing....", - stem, dirname) - raise Exception("multiple document choices in " + dirname) + stem, name) + raise Exception("multiple document choices in " + name) elif len(candidates) == 0: return None else: