Bug 971272 - Part 2: Expose FileRegistry.required_directories. r=gps

This commit is contained in:
Nick Alexander 2014-02-13 09:09:08 -08:00
parent b3c684284a
commit f52b37797f
2 changed files with 36 additions and 0 deletions

View File

@ -134,6 +134,15 @@ class FileRegistry(object):
'''
return self._files.iteritems()
def required_directories(self):
'''
Return the set of directories required by the paths in the container,
in no particular order. The returned directories are relative to an
unspecified (virtual) root directory (and do not include said root
directory).
'''
return set(k for k, v in self._required_directories.items() if v > 0)
class FileCopyResult(object):
"""Represents results of a FileCopier.copy operation."""

View File

@ -116,6 +116,33 @@ class TestFileRegistry(MatchTestTemplate, unittest.TestCase):
self.registry.remove('bar/zot')
self.registry.add('bar/zot', GeneratedFile('barzot'))
def test_required_directories(self):
self.registry = FileRegistry()
self.registry.add('foo', GeneratedFile('foo'))
self.assertEqual(self.registry.required_directories(), set())
self.registry.add('bar/baz', GeneratedFile('barbaz'))
self.assertEqual(self.registry.required_directories(), {'bar'})
self.registry.add('bar/zot', GeneratedFile('barzot'))
self.assertEqual(self.registry.required_directories(), {'bar'})
self.registry.add('bar/zap/zot', GeneratedFile('barzapzot'))
self.assertEqual(self.registry.required_directories(), {'bar', 'bar/zap'})
self.registry.remove('bar/zap/zot')
self.assertEqual(self.registry.required_directories(), {'bar'})
self.registry.remove('bar/baz')
self.assertEqual(self.registry.required_directories(), {'bar'})
self.registry.remove('bar/zot')
self.assertEqual(self.registry.required_directories(), set())
self.registry.add('x/y/z', GeneratedFile('xyz'))
self.assertEqual(self.registry.required_directories(), {'x', 'x/y'})
class TestFileCopier(TestWithTmpDir):
def all_dirs(self, base):