예제 #1
0
 def find(self, dir_path):
     relpath = mozpath.relpath(dir_path, self.root)
     if relpath.startswith('..'):
         return None
     if relpath in ('', '.'):
         return self
     segs = mozpath.split(relpath)
     node = self
     while segs:
         seg = segs.pop(0)
         if seg not in node.dirs:
             return None
         node = node.dirs[seg]
     return node
예제 #2
0
 def _walk(self, base):
     base = mozpath.normpath(base)
     local_files = [
         mozpath.split(mozpath.relpath(f, base))
         for f in self.mocks if f.startswith(base)
     ]
     root = MockNode(base)
     for segs in local_files:
         node = root
         for n, seg in enumerate(segs[:-1]):
             if seg not in node.dirs:
                 node.dirs[seg] = MockNode('/'.join([base] + segs[:n+1]))
             node = node.dirs[seg]
         node.files.append(segs[-1])
     for tpl in root.walk():
         yield tpl
예제 #3
0
 def _walk(self, base):
     base = mozpath.normpath(base)
     local_files = [
         mozpath.split(mozpath.relpath(f, base))
         for f in self.mocks if f.startswith(base)
     ]
     root = MockNode(base)
     for segs in local_files:
         node = root
         for n, seg in enumerate(segs[:-1]):
             if seg not in node.dirs:
                 node.dirs[seg] = MockNode('/'.join([base] + segs[:n+1]))
             node = node.dirs[seg]
         node.files.append(segs[-1])
     for tpl in root.walk():
         yield tpl
예제 #4
0
 def __init__(self, root, paths):
     self.root = root
     self.files = []
     self.dirs = {}
     if not paths:
         return
     if isinstance(paths[0], six.string_types):
         paths = [
             mozpath.split(path)
             for path in sorted(paths)
         ]
     child_paths = defaultdict(list)
     for segs in paths:
         if len(segs) == 1:
             self.files.append(segs[0])
         else:
             child_paths[segs[0]].append(segs[1:])
     for root, leafs in child_paths.items():
         self.dirs[root] = MockOS(mozpath.join(self.root, root), leafs)
예제 #5
0
    def test_src_app(self):
        'Test parsing a App in source setup'
        # move toolkit to toplevel
        shutil.move(mozpath.join(self.stage, 'comm', 'mozilla'), self.stage)
        app = EnumerateSourceTreeApp(
            mozpath.join(self.stage, 'comm', 'mail', 'locales', 'l10n.ini'),
            self.stage,
            mozpath.join(self.stage, 'l10n-central'),
            {
                'mozilla-central': mozpath.join(self.stage, 'mozilla')
            }
        )
        self.assertListEqual(app.config.allLocales(), ['af', 'de', 'fr'])
        self.assertEqual(len(app.config.children), 1)
        projectconfig = app.asConfig()
        self.assertListEqual(projectconfig.locales, ['af', 'de', 'fr'])
        files = ProjectFiles('de', [projectconfig])
        files = list(files)
        self.assertEqual(len(files), 3)

        l10nfile, reffile, mergefile, test = files[0]
        self.assertListEqual(mozpath.split(l10nfile)[-3:],
                             ['de', 'mail', 'mail.ftl'])
        self.assertListEqual(mozpath.split(reffile)[-4:],
                             ['mail', 'locales', 'en-US', 'mail.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())

        l10nfile, reffile, mergefile, test = files[1]
        self.assertListEqual(mozpath.split(l10nfile)[-3:],
                             ['de', 'toolkit', 'localized.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-5:],
            ['mozilla', 'toolkit',
             'locales', 'en-US', 'localized.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())

        l10nfile, reffile, mergefile, test = files[2]
        self.assertListEqual(mozpath.split(l10nfile)[-3:],
                             ['de', 'toolkit', 'platform.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-5:],
            ['mozilla', 'toolkit', 'locales', 'en-US', 'platform.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())
예제 #6
0
    def test_app(self):
        'Test parsing a App'
        app = EnumerateApp(
            mozpath.join(self.stage, 'comm', 'mail', 'locales', 'l10n.ini'),
            mozpath.join(self.stage, 'l10n-central'))
        self.assertListEqual(app.locales, ['af', 'de', 'fr'])
        self.assertEqual(len(app.config.children), 1)
        projectconfig = app.asConfig()
        self.assertListEqual(projectconfig.locales, ['af', 'de', 'fr'])
        files = ProjectFiles('de', [projectconfig])
        files = list(files)
        self.assertEqual(len(files), 3)

        l10nfile, reffile, mergefile, test = files[0]
        self.assertListEqual(
            mozpath.split(l10nfile)[-3:], ['de', 'mail', 'mail.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-4:],
            ['mail', 'locales', 'en-US', 'mail.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())

        l10nfile, reffile, mergefile, test = files[1]
        self.assertListEqual(
            mozpath.split(l10nfile)[-3:], ['de', 'toolkit', 'localized.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-6:], [
                'comm', 'mozilla', 'toolkit', 'locales', 'en-US',
                'localized.ftl'
            ])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())

        l10nfile, reffile, mergefile, test = files[2]
        self.assertListEqual(
            mozpath.split(l10nfile)[-3:], ['de', 'toolkit', 'platform.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-6:],
            ['comm', 'mozilla', 'toolkit', 'locales', 'en-US', 'platform.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())
예제 #7
0
    def test_app(self):
        'Test parsing a App'
        app = EnumerateApp(
            mozpath.join(self.stage, 'comm', 'mail', 'locales', 'l10n.ini'),
            mozpath.join(self.stage, 'l10n-central'))
        self.assertListEqual(app.config.allLocales(), ['af', 'de', 'fr'])
        self.assertEqual(len(app.config.children), 1)
        projectconfig = app.asConfig()
        self.assertListEqual(projectconfig.locales, ['af', 'de', 'fr'])
        files = ProjectFiles('de', [projectconfig])
        files = list(files)
        self.assertEqual(len(files), 3)

        l10nfile, reffile, mergefile, test = files[0]
        self.assertListEqual(mozpath.split(l10nfile)[-3:],
                             ['de', 'mail', 'mail.ftl'])
        self.assertListEqual(mozpath.split(reffile)[-4:],
                             ['mail', 'locales', 'en-US', 'mail.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())

        l10nfile, reffile, mergefile, test = files[1]
        self.assertListEqual(mozpath.split(l10nfile)[-3:],
                             ['de', 'toolkit', 'localized.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-6:],
            ['comm', 'mozilla', 'toolkit',
             'locales', 'en-US', 'localized.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())

        l10nfile, reffile, mergefile, test = files[2]
        self.assertListEqual(mozpath.split(l10nfile)[-3:],
                             ['de', 'toolkit', 'platform.ftl'])
        self.assertListEqual(
            mozpath.split(reffile)[-6:],
            ['comm', 'mozilla', 'toolkit', 'locales', 'en-US', 'platform.ftl'])
        self.assertIsNone(mergefile)
        self.assertSetEqual(test, set())
예제 #8
0
 def test_split(self):
     self.assertEqual(split(self.SEP.join(('foo', 'bar', 'baz'))),
                      ['foo', 'bar', 'baz'])
예제 #9
0
 def test_split(self):
     self.assertEqual(split(self.SEP.join(('foo', 'bar', 'baz'))),
                      ['foo', 'bar', 'baz'])