def test_single_reference_path(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.path('/l10n')) cfg.set_locales(['de']) cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/good.ftl', 'reference': self.path('/reference/good.ftl') }) mocks = [ self.path('/reference/good.ftl'), self.path('/reference/not/subdir/bad.ftl'), ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual(list(files), [ (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), ]) self.assertTupleEqual( files.match(self.path('/reference/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), ) self.assertTupleEqual( files.match(self.path('/l10n/de/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), )
def test_validation_mode(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.path('/l10n')) cfg.locales.append('de') cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*', 'reference': self.path('/reference/*') }) mocks = [ self.path(leaf) for leaf in [ '/l10n/de/good.ftl', '/l10n/de/not/subdir/bad.ftl', '/l10n/fr/good.ftl', '/l10n/fr/not/subdir/bad.ftl', '/reference/ref.ftl', '/reference/not/subdir/bad.ftl', ] ] # `None` switches on validation mode files = MockProjectFiles(mocks, None, [cfg]) self.assertListEqual( list(files), [ (self.path('/reference/ref.ftl'), self.path('/reference/ref.ftl'), None, set()), ])
def test_l10n_path(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.root) cfg.set_locales(['de']) cfg.add_paths({'l10n': '{l10n_base}/{locale}/*'}) mocks = [ self.path(leaf) for leaf in ( '/de/good.ftl', '/de/not/subdir/bad.ftl', '/fr/good.ftl', '/fr/not/subdir/bad.ftl', ) ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual(list(files), [(self.path('/de/good.ftl'), None, None, set())]) self.assertTupleEqual(files.match(self.path('/de/good.ftl')), (self.path('/de/good.ftl'), None, None, set())) self.assertIsNone(files.match(self.path('/fr/something.ftl'))) files = MockProjectFiles(mocks, 'de', [cfg], mergebase='merging') self.assertListEqual( list(files), [(self.path('/de/good.ftl'), None, 'merging/de/good.ftl', set())]) self.assertTupleEqual(files.match(self.path('/de/something.ftl')), (self.path('/de/something.ftl'), None, 'merging/de/something.ftl', set())) # 'fr' is not in the locale list, should return no files files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual(list(files), [])
def test_l10n_path(self): cfg = ProjectConfig() cfg.add_environment(l10n_base='/tmp') cfg.locales.append('de') cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*' }) mocks = { '/tmp/de/': [ 'good.ftl', 'not/subdir/bad.ftl' ], '/tmp/fr/': [ 'good.ftl', 'not/subdir/bad.ftl' ], } files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual( list(files), [('/tmp/de/good.ftl', None, None, set())]) self.assertTupleEqual( files.match('/tmp/de/something.ftl'), ('/tmp/de/something.ftl', None, None, set())) self.assertIsNone(files.match('/tmp/fr/something.ftl')) files = MockProjectFiles(mocks, 'de', [cfg], mergebase='merging') self.assertListEqual( list(files), [('/tmp/de/good.ftl', None, 'merging/de/good.ftl', set())]) self.assertTupleEqual( files.match('/tmp/de/something.ftl'), ('/tmp/de/something.ftl', None, 'merging/de/something.ftl', set())) # 'fr' is not in the locale list, should return no files files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual(list(files), [])
def test_validation_mode(self): cfg = ProjectConfig() cfg.add_environment(l10n_base='/tmp/l10n') cfg.locales.append('de') cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*', 'reference': '/tmp/reference/*' }) mocks = { '/tmp/l10n/de/': [ 'good.ftl', 'not/subdir/bad.ftl' ], '/tmp/l10n/fr/': [ 'good.ftl', 'not/subdir/bad.ftl' ], '/tmp/reference/': [ 'ref.ftl', 'not/subdir/bad.ftl' ], } # `None` switches on validation mode files = MockProjectFiles(mocks, None, [cfg]) self.assertListEqual( list(files), [ ('/tmp/reference/ref.ftl', '/tmp/reference/ref.ftl', None, set()), ])
def test_l10n_path(self): cfg = ProjectConfig() cfg.locales.append('de') cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*' }) cfg.add_environment(l10n_base='/tmp') mocks = { '/tmp/de/': [ 'good.ftl', 'not/subdir/bad.ftl' ], '/tmp/fr/': [ 'good.ftl', 'not/subdir/bad.ftl' ], } files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual( list(files), [('/tmp/de/good.ftl', None, None, set())]) self.assertTupleEqual( files.match('/tmp/de/something.ftl'), ('/tmp/de/something.ftl', None, None, set())) self.assertIsNone(files.match('/tmp/fr/something.ftl')) files = MockProjectFiles(mocks, 'de', [cfg], mergebase='merging') self.assertListEqual( list(files), [('/tmp/de/good.ftl', None, 'merging/de/good.ftl', set())]) self.assertTupleEqual( files.match('/tmp/de/something.ftl'), ('/tmp/de/something.ftl', None, 'merging/de/something.ftl', set())) # 'fr' is not in the locale list, should return no files files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual(list(files), [])
def test_single_reference_path(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.path('/l10n')) cfg.set_locales(['de']) cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/good.ftl', 'reference': self.path('/reference/good.ftl') }) mocks = [ self.path('/reference/good.ftl'), self.path('/reference/not/subdir/bad.ftl'), ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual( list(files), [ (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), ]) self.assertTupleEqual( files.match(self.path('/reference/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), ) self.assertTupleEqual( files.match(self.path('/l10n/de/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), )
def test_validation_mode(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.path('/l10n')) cfg.set_locales(['de']) cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*', 'reference': self.path('/reference/*') }) mocks = [ self.path(leaf) for leaf in [ '/l10n/de/good.ftl', '/l10n/de/not/subdir/bad.ftl', '/l10n/fr/good.ftl', '/l10n/fr/not/subdir/bad.ftl', '/reference/ref.ftl', '/reference/not/subdir/bad.ftl', ] ] # `None` switches on validation mode files = MockProjectFiles(mocks, None, [cfg]) self.assertListEqual( list(files), [ (self.path('/reference/ref.ftl'), self.path('/reference/ref.ftl'), None, set()), ])
def test_expand_paths(self): pc = ProjectConfig() pc.add_environment(one="first_path") self.assertEqual(pc.expand('foo'), 'foo') self.assertEqual(pc.expand('foo{one}bar'), 'foofirst_pathbar') pc.add_environment(l10n_base='../tmp/localizations') self.assertEqual( pc.expand('{l}dir', {'l': '{l10n_base}/{locale}/'}), '../tmp/localizations/{locale}/dir') self.assertEqual( pc.expand('{l}dir', { 'l': '{l10n_base}/{locale}/', 'l10n_base': '../merge-base' }), '../merge-base/{locale}/dir')
def test_expand_paths(self): pc = ProjectConfig() pc.add_environment(one="first_path") self.assertEqual(pc.expand('foo'), 'foo') self.assertEqual(pc.expand('foo{one}bar'), 'foofirst_pathbar') pc.add_environment(l10n_base='../tmp/localizations') self.assertEqual( pc.expand('{l}dir', {'l': '{l10n_base}/{locale}/'}), '../tmp/localizations/{locale}/dir') self.assertEqual( pc.expand('{l}dir', { 'l': '{l10n_base}/{locale}/', 'l10n_base': '../merge-base' }), '../merge-base/{locale}/dir')
def test_l10n_path(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.root) cfg.set_locales(['de']) cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*' }) mocks = [ self.path(leaf) for leaf in ( '/de/good.ftl', '/de/not/subdir/bad.ftl', '/fr/good.ftl', '/fr/not/subdir/bad.ftl', ) ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual( list(files), [ (self.path('/de/good.ftl'), None, None, set()) ] ) self.assertTupleEqual( files.match(self.path('/de/good.ftl')), (self.path('/de/good.ftl'), None, None, set()) ) self.assertIsNone(files.match(self.path('/fr/something.ftl'))) files = MockProjectFiles(mocks, 'de', [cfg], mergebase='merging') self.assertListEqual( list(files), [ (self.path('/de/good.ftl'), None, 'merging/de/good.ftl', set()) ] ) self.assertTupleEqual( files.match(self.path('/de/something.ftl')), (self.path('/de/something.ftl'), None, 'merging/de/something.ftl', set())) # 'fr' is not in the locale list, should return no files files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual(list(files), [])
def test_reference_path(self): cfg = ProjectConfig(None) cfg.add_environment(l10n_base=self.path('/l10n')) cfg.locales.append('de') cfg.add_paths({ 'l10n': '{l10n_base}/{locale}/*', 'reference': self.path('/reference/*') }) mocks = [ self.path(leaf) for leaf in [ '/l10n/de/good.ftl', '/l10n/de/not/subdir/bad.ftl', '/l10n/fr/good.ftl', '/l10n/fr/not/subdir/bad.ftl', '/reference/ref.ftl', '/reference/not/subdir/bad.ftl', ] ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual( list(files), [ (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), (self.path('/l10n/de/ref.ftl'), self.path('/reference/ref.ftl'), None, set()), ]) self.assertTupleEqual( files.match(self.path('/l10n/de/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), ) self.assertTupleEqual( files.match(self.path('/reference/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), None, set()), ) self.assertIsNone(files.match(self.path('/l10n/de/subdir/bad.ftl'))) self.assertIsNone(files.match(self.path('/reference/subdir/bad.ftl'))) files = MockProjectFiles(mocks, 'de', [cfg], mergebase='merging') self.assertListEqual( list(files), [ (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), 'merging/de/good.ftl', set()), (self.path('/l10n/de/ref.ftl'), self.path('/reference/ref.ftl'), 'merging/de/ref.ftl', set()), ]) self.assertTupleEqual( files.match(self.path('/l10n/de/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), 'merging/de/good.ftl', set()), ) self.assertTupleEqual( files.match(self.path('/reference/good.ftl')), (self.path('/l10n/de/good.ftl'), self.path('/reference/good.ftl'), 'merging/de/good.ftl', set()), ) # 'fr' is not in the locale list, should return no files files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual(list(files), [])