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_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_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_partial_l10n(self): cfg = ProjectConfig(None) cfg.set_locales(['de', 'fr']) cfg.add_paths({'l10n': self.path('/{locale}/major/*')}, { 'l10n': self.path('/{locale}/minor/*'), 'locales': ['de'] }) mocks = [ self.path(leaf) for leaf in [ '/de/major/good.ftl', '/de/major/not/subdir/bad.ftl', '/de/minor/good.ftl', '/fr/major/good.ftl', '/fr/major/not/subdir/bad.ftl', '/fr/minor/good.ftl', ] ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual(list(files), [ (self.path('/de/major/good.ftl'), None, None, set()), (self.path('/de/minor/good.ftl'), None, None, set()), ]) self.assertTupleEqual( files.match(self.path('/de/major/some.ftl')), (self.path('/de/major/some.ftl'), None, None, set())) self.assertIsNone(files.match(self.path('/de/other/some.ftl'))) # 'fr' is not in the locale list of minor, should only return major files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual(list(files), [ (self.path('/fr/major/good.ftl'), None, None, set()), ]) self.assertIsNone(files.match(self.path('/fr/minor/some.ftl')))
def test_children(self): one = ProjectConfig('one.toml') one.add_child(ProjectConfig('inner.toml')) one.set_locales(['ab']) other = ProjectConfig('one.toml') self.assertFalse(one.same(other)) other.add_child(ProjectConfig('inner.toml')) self.assertTrue(one.same(other))
def test_children(self): one = ProjectConfig('one.toml') one.add_child(ProjectConfig('inner.toml')) one.set_locales(['ab']) other = ProjectConfig('one.toml') self.assertFalse(one.same(other)) other.add_child(ProjectConfig('inner.toml')) self.assertTrue(one.same(other))
def test_paths(self): one = ProjectConfig('one.toml') one.set_locales(['ab']) one.add_paths({'l10n': '/tmp/somedir/{locale}/**'}) other = ProjectConfig('one.toml') self.assertFalse(one.same(other)) other.add_paths({'l10n': '/tmp/somedir/{locale}/**'}) self.assertTrue(one.same(other))
def test_paths(self): one = ProjectConfig('one.toml') one.set_locales(['ab']) one.add_paths({ 'l10n': '/tmp/somedir/{locale}/**' }) other = ProjectConfig('one.toml') self.assertFalse(one.same(other)) other.add_paths({ 'l10n': '/tmp/somedir/{locale}/**' }) self.assertTrue(one.same(other))
def test_locales_in_paths(self): pc = ProjectConfig(None) child = ProjectConfig(None) child.add_paths({ 'l10n': '/tmp/somedir/{locale}/toolkit/**', 'locales': ['it'] }) child.set_locales([]) pc.add_child(child) self.assertListEqual(pc.all_locales, ['it']) pc.set_locales(['de', 'fr']) self.assertListEqual(pc.all_locales, ['de', 'fr', 'it'])
class SetupMixin(object): def setUp(self): self.cfg = ProjectConfig(None) self.file = File( '/tmp/somedir/de/browser/one/two/file.ftl', 'file.ftl', module='browser', locale='de') self.other_file = File( '/tmp/somedir/de/toolkit/two/one/file.ftl', 'file.ftl', module='toolkit', locale='de') self.cfg.set_locales(['de'])
class SetupMixin(object): def setUp(self): self.cfg = ProjectConfig(None) self.file = File('/tmp/somedir/de/browser/one/two/file.ftl', 'file.ftl', module='browser', locale='de') self.other_file = File('/tmp/somedir/de/toolkit/two/one/file.ftl', 'file.ftl', module='toolkit', locale='de') self.cfg.set_locales(['de'])
def test_locales_in_paths(self): pc = ProjectConfig(None) child = ProjectConfig(None) child.add_paths({ 'l10n': '/tmp/somedir/{locale}/toolkit/**', 'locales': ['it'] }) child.set_locales([]) pc.add_child(child) self.assertListEqual(pc.all_locales, ['it']) pc.set_locales(['de', 'fr']) self.assertListEqual(pc.all_locales, ['de', 'fr', 'it'])
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_partial_l10n(self): cfg = ProjectConfig(None) cfg.set_locales(['de', 'fr']) cfg.add_paths({ 'l10n': self.path('/{locale}/major/*') }, { 'l10n': self.path('/{locale}/minor/*'), 'locales': ['de'] }) mocks = [ self.path(leaf) for leaf in [ '/de/major/good.ftl', '/de/major/not/subdir/bad.ftl', '/de/minor/good.ftl', '/fr/major/good.ftl', '/fr/major/not/subdir/bad.ftl', '/fr/minor/good.ftl', ] ] files = MockProjectFiles(mocks, 'de', [cfg]) self.assertListEqual( list(files), [ (self.path('/de/major/good.ftl'), None, None, set()), (self.path('/de/minor/good.ftl'), None, None, set()), ]) self.assertTupleEqual( files.match(self.path('/de/major/some.ftl')), (self.path('/de/major/some.ftl'), None, None, set())) self.assertIsNone(files.match(self.path('/de/other/some.ftl'))) # 'fr' is not in the locale list of minor, should only return major files = MockProjectFiles(mocks, 'fr', [cfg]) self.assertListEqual( list(files), [ (self.path('/fr/major/good.ftl'), None, None, set()), ]) self.assertIsNone(files.match(self.path('/fr/minor/some.ftl')))
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_path(self): one = ProjectConfig('one.toml') one.set_locales(['ab']) self.assertTrue(one.same(ProjectConfig('one.toml'))) self.assertFalse(one.same(ProjectConfig('two.toml')))
def test_path(self): one = ProjectConfig('one.toml') one.set_locales(['ab']) self.assertTrue(one.same(ProjectConfig('one.toml'))) self.assertFalse(one.same(ProjectConfig('two.toml')))