diff --git a/tests/test_sources.py b/tests/test_sources.py index 5e84c8c..f45789a 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -18,7 +18,7 @@ except ImportError: import examples # -- SUT -from tldp.sources import SourceDirs, SourceDocument +from tldp.sources import SourceCollection, SourceDocument datadir = os.path.join(os.path.dirname(__file__), 'testdata') @@ -29,7 +29,7 @@ def stem_and_ext(name): return stem, ext -class TestSourceDirs(unittest.TestCase): +class TestSourceCollection(unittest.TestCase): def setUp(self): self.tempdir = mkdtemp(prefix='tldp-sources-test-') @@ -59,7 +59,7 @@ class TestSourceDirs(unittest.TestCase): return relname, newname -class TestFileSourceDirsMultiDir(TestSourceDirs): +class TestFileSourceCollectionMultiDir(TestSourceCollection): def test_multidir_finding_singlefiles(self): ex = random.choice(examples.examples) @@ -69,21 +69,21 @@ class TestFileSourceDirsMultiDir(TestSourceDirs): for d in documents: d.reldir, d.absdir = self.mkdir_components(d.components) d.relname, d.absname = self.addfile(d.absdir, ex, stem=d.stem) - s = SourceDirs([x.absdir for x in documents]) + s = SourceCollection([x.absdir for x in documents]) self.assertEquals(2, len(s)) sought = set([x.stem for x in documents]) found = set([x for x in s]) self.assertEquals(sought, found) -class TestFileSourceDirsOneDir(TestSourceDirs): +class TestFileSourceCollectionOneDir(TestSourceCollection): def test_finding_singlefile(self): ex = random.choice(examples.examples) maindir = ['LDP', 'LDP', 'howto'] reldir, absdir = self.mkdir_components(maindir) _, _ = self.addfile(absdir, ex) - s = SourceDirs([absdir]) + s = SourceCollection([absdir]) self.assertEquals(1, len(s)) def test_skipping_misnamed_singlefile(self): @@ -91,16 +91,16 @@ class TestFileSourceDirsOneDir(TestSourceDirs): maindir = ['LDP', 'LDP', 'howto'] reldir, absdir = self.mkdir_components(maindir) self.addfile(absdir, ex, ext=".mis") - s = SourceDirs([absdir]) + s = SourceCollection([absdir]) self.assertEquals(1, len(s)) -class TestInvalidSourceDirs(TestSourceDirs): +class TestInvalidSourceCollection(TestSourceCollection): def test_validateDirs_onebad(self): invalid0 = os.path.join(self.tempdir, 'unique', 'rabbit') with self.assertRaises(IOError) as ecm: - SourceDirs([invalid0]) + SourceCollection([invalid0]) e = ecm.exception self.assertTrue('unique/rabbit' in e.filename) @@ -108,18 +108,18 @@ class TestInvalidSourceDirs(TestSourceDirs): invalid0 = os.path.join(self.tempdir, 'unique', 'rabbit') invalid1 = os.path.join(self.tempdir, 'affable', 'elephant') with self.assertRaises(IOError) as ecm: - SourceDirs([invalid0, invalid1]) + SourceCollection([invalid0, invalid1]) e = ecm.exception self.assertTrue('affable/elephant' in e.filename) def testEmptyDir(self): - s = SourceDirs([self.tempdir]) + s = SourceCollection([self.tempdir]) import pprint pprint.pprint(s.__dict__) self.assertEquals(0, len(s)) -class TestMissingSourceDocuments(TestSourceDirs): +class TestMissingSourceDocuments(TestSourceCollection): def test_init_missing(self): missing = os.path.join(self.tempdir, 'vanishing') diff --git a/tldp/sources.py b/tldp/sources.py index 70680cd..aa7f519 100644 --- a/tldp/sources.py +++ b/tldp/sources.py @@ -10,22 +10,22 @@ from .utils import logger from .typeguesser import guess, knownextensions -class SourceDirs(collections.MutableMapping): +class SourceCollection(collections.MutableMapping): def __repr__(self): return '<%s:(%s docs)>' % \ (self.__class__.__name__, len(self)) def __init__(self, args): - sourcedirs = [os.path.abspath(x) for x in args] - results = [os.path.exists(x) for x in sourcedirs] + dirs = [os.path.abspath(x) for x in args] + results = [os.path.exists(x) for x in dirs] if not all(results): - for result, sdir in zip(results, sourcedirs): + for result, sdir in zip(results, dirs): logger.critical("Directory does not exist: " + sdir) raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), sdir) - for sdir in sourcedirs: + for sdir in dirs: docs = dict() for fname in os.listdir(sdir): possible = os.path.join(sdir, fname)