示例#1
0
    def test_l10n_not_merge_ftl(self):
        """Test that JarMaker doesn't merge source .ftl files"""
        self._create_fluent_setup()
        jm = JarMaker(outputFormat="symlink")
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.l10nbase = self.l10nbase
        jm.l10nmerge = self.l10nmerge
        jm.relativesrcdir = "app/locales"
        jm.makeJar(os.path.join(self.srcdir, "jar.mn"), self.builddir)

        # test.ftl should be taken from the l10ndir, since it is present there
        destpath = os.path.join(self.builddir, "localization", "test", "app",
                                "test.ftl")
        srcpath = os.path.join(self.l10nbase, "app", "app", "test.ftl")
        self.assertTrue(
            is_symlink_to(destpath, srcpath),
            "{0} should be a symlink to {1}".format(destpath, srcpath),
        )

        # test2.ftl on the other hand, is only present in en-US dir, and should
        # not be linked from the build dir
        destpath = os.path.join(self.builddir, "localization", "test", "app",
                                "test2.ftl")
        self.assertFalse(os.path.isfile(destpath),
                         "test2.ftl should not be taken from en-US")
示例#2
0
    def test_l10n_not_merge_ftl(self):
        '''Test that JarMaker doesn't merge source .ftl files'''
        self._create_fluent_setup()
        jm = JarMaker(outputFormat='symlink')
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.l10nbase = self.l10nbase
        jm.l10nmerge = self.l10nmerge
        jm.relativesrcdir = 'app/locales'
        jm.makeJar(os.path.join(self.srcdir, 'jar.mn'), self.builddir)

        # test.ftl should be taken from the l10ndir, since it is present there
        destpath = os.path.join(self.builddir, 'localization', 'test', 'app',
                                'test.ftl')
        srcpath = os.path.join(self.l10nbase, 'app', 'app', 'test.ftl')
        self.assertTrue(
            is_symlink_to(destpath, srcpath),
            '{0} should be a symlink to {1}'.format(destpath, srcpath))

        # test2.ftl on the other hand, is only present in en-US dir, and should
        # not be linked from the build dir
        destpath = os.path.join(self.builddir, 'localization', 'test', 'app',
                                'test2.ftl')
        self.assertFalse(os.path.isfile(destpath),
                         'test2.ftl should not be taken from en-US')
示例#3
0
    def test_l10n_not_merge_ftl(self):
        '''Test that JarMaker doesn't merge source .ftl files'''
        self._create_fluent_setup()
        jm = JarMaker(outputFormat='symlink')
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.l10nbase = self.l10nbase
        jm.l10nmerge = self.l10nmerge
        jm.relativesrcdir = 'app/locales'
        jm.makeJar(os.path.join(self.srcdir, 'jar.mn'), self.builddir)

        # test.ftl should be taken from the l10ndir, since it is present there
        destpath = os.path.join(
            self.builddir, 'localization', 'test', 'app', 'test.ftl')
        srcpath = os.path.join(self.l10nbase, 'app', 'app', 'test.ftl')
        self.assertTrue(is_symlink_to(destpath, srcpath),
                        '{0} should be a symlink to {1}'.format(destpath,
                                                                srcpath))

        # test2.ftl on the other hand, is only present in en-US dir, and should
        # not be linked from the build dir
        destpath = os.path.join(
            self.builddir, 'localization', 'test', 'app', 'test2.ftl')
        self.assertFalse(
            os.path.isfile(destpath),
            'test2.ftl should not be taken from en-US')
示例#4
0
    def test_a_simple_symlink(self):
        '''Test a simple jar.mn with a symlink'''
        if not symlinks_supported(self.srcdir):
            raise unittest.SkipTest('symlinks not supported')

        self._create_simple_setup()
        jm = JarMaker(outputFormat='symlink')
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.makeJar(os.path.join(self.srcdir,'jar.mn'), self.builddir)
        # All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
        srcbar = os.path.join(self.srcdir, 'bar')
        destfoo = os.path.join(self.builddir, 'chrome', 'test', 'dir', 'foo')
        self.assertTrue(is_symlink_to(destfoo, srcbar),
                        "{0} is not a symlink to {1}".format(destfoo, srcbar))
示例#5
0
 def _jar_and_compare(self, infile, **kwargs):
     jm = JarMaker(outputFormat='jar')
     jardir = os.path.join(self.builddir, 'chrome')
     if 'topsourcedir' not in kwargs:
         kwargs['topsourcedir'] = self.srcdir
     for attr in ('topsourcedir', 'sourcedirs'):
         if attr in kwargs:
             setattr(jm, attr, kwargs[attr])
     jm.makeJar(infile, jardir)
     cwd = os.getcwd()
     os.chdir(self.builddir)
     try:
         # expand build to stage
         for path, dirs, files in os.walk('.'):
             stagedir = os.path.join(self.stagedir, path)
             if not os.path.isdir(stagedir):
                 os.mkdir(stagedir)
             for file in files:
                 if file.endswith('.jar'):
                     # expand jar
                     stagepath = os.path.join(stagedir, file)
                     os.mkdir(stagepath)
                     zf = ZipFile(os.path.join(path, file))
                     # extractall is only in 2.6, do this manually :-(
                     for entry_name in zf.namelist():
                         segs = entry_name.split('/')
                         fname = segs.pop()
                         dname = os.path.join(stagepath, *segs)
                         if not os.path.isdir(dname):
                             os.makedirs(dname)
                         if not fname:
                             # directory, we're done
                             continue
                         _c = zf.read(entry_name)
                         open(os.path.join(dname, fname), 'wb').write(_c)
                     zf.close()
                 else:
                     copy2(os.path.join(path, file), stagedir)
         # compare both dirs
         os.chdir('..')
         td = _TreeDiff('ref', 'stage')
         return td.allResults('reference', 'build')
     finally:
         os.chdir(cwd)
示例#6
0
 def _jar_and_compare(self, infile, **kwargs):
     jm = JarMaker(outputFormat="jar")
     if "topsourcedir" not in kwargs:
         kwargs["topsourcedir"] = self.srcdir
     for attr in ("topsourcedir", "sourcedirs"):
         if attr in kwargs:
             setattr(jm, attr, kwargs[attr])
     jm.makeJar(infile, self.builddir)
     cwd = os.getcwd()
     os.chdir(self.builddir)
     try:
         # expand build to stage
         for path, dirs, files in os.walk("."):
             stagedir = os.path.join(self.stagedir, path)
             if not os.path.isdir(stagedir):
                 os.mkdir(stagedir)
             for file in files:
                 if file.endswith(".jar"):
                     # expand jar
                     stagepath = os.path.join(stagedir, file)
                     os.mkdir(stagepath)
                     zf = ZipFile(os.path.join(path, file))
                     # extractall is only in 2.6, do this manually :-(
                     for entry_name in zf.namelist():
                         segs = entry_name.split("/")
                         fname = segs.pop()
                         dname = os.path.join(stagepath, *segs)
                         if not os.path.isdir(dname):
                             os.makedirs(dname)
                         if not fname:
                             # directory, we're done
                             continue
                         _c = zf.read(entry_name)
                         open(os.path.join(dname, fname), "wb").write(_c)
                     zf.close()
                 else:
                     copy2(os.path.join(path, file), stagedir)
         # compare both dirs
         os.chdir("..")
         td = _TreeDiff("ref", "stage")
         return td.allResults("reference", "build")
     finally:
         os.chdir(cwd)
示例#7
0
    def test_a_wildcard_symlink(self):
        '''Test a wildcard in jar.mn with symlinks'''
        if not symlinks_supported(self.srcdir):
            raise unittest.SkipTest('symlinks not supported')

        self._create_wildcard_setup()
        jm = JarMaker(outputFormat='symlink')
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jardir = os.path.join(self.builddir, 'chrome')
        jm.makeJar(os.path.join(self.srcdir,'jar.mn'), jardir)

        expected_symlinks = {
            ('bar', 'foo.js'): ('foo.js',),
            ('bar', 'bar.js'): ('bar.js',),
            ('hoge', 'foo', '1'): ('qux', 'foo', '1'),
            ('hoge', 'foo', '2'): ('qux', 'foo', '2'),
            ('hoge', 'baz'): ('qux', 'baz'),
        }
        for dest, src in expected_symlinks.iteritems():
            srcpath = os.path.join(self.srcdir, *src)
            destpath = os.path.join(self.builddir, 'chrome', 'test', 'dir',
                                    *dest)
            self.assertTrue(is_symlink_to(destpath, srcpath),
                            "{0} is not a symlink to {1}".format(destpath,
                                                                 srcpath))
示例#8
0
    def test_a_wildcard_symlink(self):
        """Test a wildcard in jar.mn with symlinks"""
        if not symlinks_supported(self.srcdir):
            raise unittest.SkipTest("symlinks not supported")

        self._create_wildcard_setup()
        jm = JarMaker(outputFormat="symlink")
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.makeJar(os.path.join(self.srcdir, "jar.mn"), self.builddir)

        expected_symlinks = {
            ("bar", "foo.js"): ("foo.js", ),
            ("bar", "bar.js"): ("bar.js", ),
            ("hoge", "foo", "1"): ("qux", "foo", "1"),
            ("hoge", "foo", "2"): ("qux", "foo", "2"),
            ("hoge", "baz"): ("qux", "baz"),
        }
        for dest, src in six.iteritems(expected_symlinks):
            srcpath = os.path.join(self.srcdir, *src)
            destpath = os.path.join(self.builddir, "chrome", "test", "dir",
                                    *dest)
            self.assertTrue(
                is_symlink_to(destpath, srcpath),
                "{0} is not a symlink to {1}".format(destpath, srcpath),
            )
示例#9
0
    def test_a_simple_symlink(self):
        '''Test a simple jar.mn with a symlink'''
        if not symlinks_supported(self.srcdir):
            raise unittest.SkipTest('symlinks not supported')

        self._create_simple_setup()
        jm = JarMaker(outputFormat='symlink')
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.makeJar(os.path.join(self.srcdir, 'jar.mn'), self.builddir)
        # All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
        srcbar = os.path.join(self.srcdir, 'bar')
        destfoo = os.path.join(self.builddir, 'chrome', 'test', 'dir', 'foo')
        self.assertTrue(is_symlink_to(destfoo, srcbar),
                        "{0} is not a symlink to {1}".format(destfoo, srcbar))
示例#10
0
    def test_a_simple_symlink(self):
        """Test a simple jar.mn with a symlink"""
        if not symlinks_supported(self.srcdir):
            raise unittest.SkipTest("symlinks not supported")

        self._create_simple_setup()
        jm = JarMaker(outputFormat="symlink")
        jm.sourcedirs = [self.srcdir]
        jm.topsourcedir = self.srcdir
        jm.makeJar(os.path.join(self.srcdir, "jar.mn"), self.builddir)
        # All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
        srcbar = os.path.join(self.srcdir, "bar")
        destfoo = os.path.join(self.builddir, "chrome", "test", "dir", "foo")
        self.assertTrue(
            is_symlink_to(destfoo, srcbar),
            "{0} is not a symlink to {1}".format(destfoo, srcbar),
        )
示例#11
0
 def setUp(self):
     self.jm = JarMaker()
     self.jm.topsourcedir = '/TOPSOURCEDIR'
     self.jm.relativesrcdir = 'browser/locales'
     self.fake_empty_file = StringIO()
     self.fake_empty_file.name = 'fake_empty_file'