コード例 #1
0
ファイル: helper.py プロジェクト: dimonov/amo-validator
def _do_test(path, test, failure=True,
             require_install=False, set_type=0,
             listed=False, xpi_mode="r"):

    package_data = open(path, "rb")
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource("listed", True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type # Conduit test requires type
    if require_install:
        err.save_resource("has_install_rdf", True)
        rdf_data = package.read("install.rdf")
        install_rdf = RDFParser(err, rdf_data)
        err.save_resource("install_rdf", install_rdf)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
コード例 #2
0
def _do_test(path,
             test,
             failure=True,
             require_install=False,
             set_type=0,
             listed=False,
             xpi_mode='r'):

    package_data = open(path, 'rb')
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource('listed', True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type  # Conduit test requires type
    if require_install:
        err.save_resource('has_install_rdf', True)
        rdf_data = package.read('install.rdf')
        install_rdf = RDFParser(err, rdf_data)
        err.save_resource('install_rdf', install_rdf)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
コード例 #3
0
ファイル: helper.py プロジェクト: nmaier/amo-validator
def _do_test(path, test, failure=True,
             require_install=False, set_type=0):
    
    package_data = open(path, "rb")
    package = XPIManager(package_data, path)
    contents = package.get_file_data()
    err = ErrorBundle()
    
    # Populate in the dependencies.
    if set_type:
        err.set_type(set_type) # Conduit test requires type
    if require_install:
        err.save_resource("has_install_rdf", True)
        rdf_data = package.read("install.rdf")
        install_rdf = RDFParser(rdf_data)
        err.save_resource("install_rdf", install_rdf)
    
    test(err, contents, package)
    
    print err.print_summary(verbose=True)
    
    if failure:
        assert err.failed()
    else:
        assert not err.failed()
    
    return err
コード例 #4
0
def test_write_file():
    """Test that a file can be written in UTF-8 to the package."""
    with tempfile.NamedTemporaryFile(delete=False) as t:
        temp_fn = t.name
        try:
            z = XPIManager(temp_fn, mode='w')
            f, d = 'install.rdf', '注目のコレクション'.decode('utf-8')
            z.write(f, d)
            eq_(z.read(f), d.encode('utf-8'))
        finally:
            os.unlink(temp_fn)
コード例 #5
0
def test_write_file():
    """Test that a file can be written in UTF-8 to the package."""
    with tempfile.NamedTemporaryFile(delete=False) as t:
        temp_fn = t.name
        try:
            z = XPIManager(temp_fn, mode='w')
            f, d = 'install.rdf', '注目のコレクション'.decode('utf-8')
            z.write(f, d)
            eq_(z.read(f), d.encode('utf-8'))
        finally:
            os.unlink(temp_fn)
コード例 #6
0
ファイル: helper.py プロジェクト: diox/amo-validator
def _do_test(path, test, failure=True,
             require_install=False, set_type=0,
             listed=False, xpi_mode='r'):

    package_data = open(path, 'rb')
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource('listed', True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type # Conduit test requires type
    if require_install:
        if 'install.rdf' in package:
            err.save_resource('has_install_rdf', True)
            rdf_data = package.read('install.rdf')
            install_rdf = RDFParser(err, rdf_data)
            err.save_resource('install_rdf', install_rdf)
        elif 'manifest.json' in package:
            err.save_resource('has_manifest_json', True)
            manifest_data = package.read('manifest.json')
            manifest_json = ManifestJsonParser(err, manifest_data)
            err.save_resource('install_rdf', manifest_json)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
コード例 #7
0
def _test_type(file_, expectation, failure=False):
    "Tests a file against the expectations"

    err = ErrorBundle(None, True)
    package = XPIManager(open(file_, "rb"), file_)
    contents = package.get_file_data()

    # We need to have an install.rdf.
    assert "install.rdf" in contents

    # Load up the install.rdf into an RDFParser
    install_file = package.read("install.rdf")
    install_rdf = RDFParser(install_file)

    results = typedetection.detect_type(err, install_rdf, package)

    assert results == expectation
    if not failure:
        assert not err.failed()
    else:
        assert err.failed()
コード例 #8
0
def _test_type(file_, expectation, failure=False):
    'Tests a file against the expectations'

    err = ErrorBundle(None, True)
    package = XPIManager(open(file_), mode='r', name=file_)
    contents = package.package_contents()

    # We need to have an install.rdf.
    assert 'install.rdf' in contents

    # Load up the install.rdf into an RDFParser
    install_file = package.read('install.rdf')
    install_rdf = RDFParser(err, install_file)

    results = typedetection.detect_type(err, install_rdf, package)

    assert results == expectation
    if not failure:
        assert not err.failed()
    else:
        assert err.failed()

    return err
コード例 #9
0
def _test_type(file_, expectation, failure=False):
    'Tests a file against the expectations'

    err = ErrorBundle(None, True)
    package = XPIManager(open(file_), mode='r', name=file_)
    contents = package.package_contents()

    # We need to have an install.rdf.
    assert 'install.rdf' in contents

    # Load up the install.rdf into an RDFParser
    install_file = package.read('install.rdf')
    install_rdf = RDFParser(err, install_file)

    results = typedetection.detect_type(err, install_rdf, package)

    assert results == expectation
    if not failure:
        assert not err.failed()
    else:
        assert err.failed()

    return err
コード例 #10
0
def test_read_file():
    """Test that a file can be read from the package."""
    z = XPIManager(get_path('xpi/install_rdf_only.xpi'))
    assert z.read('install.rdf') is not None
コード例 #11
0
def test_read_file():
    """Test that a file can be read from the package."""
    z = XPIManager(get_path('xpi/install_rdf_only.xpi'))
    assert z.read('install.rdf') is not None
コード例 #12
0
def test_read_file():
    "Test that a file can be read from the package"
    z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
    assert z.read("install.rdf") is not None
コード例 #13
0
ファイル: bundle.py プロジェクト: rmoorman/transifex-adofex
    def __init__(self, filename, project=None, release=None, name=None):
        """
        Fills in a list of locales from the chrome.manifest file.
        """
        Bundle.__init__(self, project, release)
        self.xpi = XPIManager(filename, name=name)
        # here we will store managers for jarfiles
        self.jarfiles = {}
        chrome = ChromeManifest(self.xpi.read("chrome.manifest"), "manifest")
        locales = list(chrome.get_triples("locale"))

        if not locales:
            return None

        # read the list
        for locale in locales:
            code, location = locale["object"].split()

            # finding out the language of the locale
            try:
                lang = self._get_lang(code)
            except Language.DoesNotExist:
                self.log("Locale %s SKIPPED" % code, "font-weight:bold")
                continue

            # Locales can be bundled in JARs
            jarred = location.startswith("jar:")
            if jarred:
                # We just care about the JAR path
                location = location[4:]
                split_location = location.split("!", 2)
                # Ignore malformed JAR URIs.
                if len(split_location) < 2:
                    continue
                jarname, location = split_location

                # missing file mentioned
                if jarname not in self.xpi:
                    continue
                # may be we have already read this one
                if jarname in self.jarfiles:
                    package = self.jarfiles[jarname]
                else:
                    jar = StringIO(self.xpi.read(jarname))
                    package = XPIManager(jar, mode="r", name=jarname)
            else:
                package = self.xpi

            # and now we read files from there
            location = location.strip('/')
            result = {}
            for f in package.package_contents():
                f = f.strip("/")
                if f.startswith(location) and f != location:
                    result[f.split("/")[-1]] = package.read(f)

            # file with same name in different jars can get overwritten
            if lang not in self.locales:
                self.locales[lang] = result
            else:
                self.locales[lang].update(result)
コード例 #14
0
ファイル: bundle.py プロジェクト: rmoorman/transifex-adofex
    def __init__(self, filename, project=None, release=None, name=None):
        """
        Fills in a list of locales from the chrome.manifest file.
        """
        Bundle.__init__(self, project, release)
        self.xpi = XPIManager(filename, name=name)
         # here we will store managers for jarfiles
        self.jarfiles = {}
        chrome = ChromeManifest(self.xpi.read("chrome.manifest"), "manifest")
        locales = list(chrome.get_triples("locale"))

        if not locales:
            return None

        # read the list
        for locale in locales:
            code, location = locale["object"].split()

            # finding out the language of the locale
            try:
                lang = self._get_lang(code)
            except Language.DoesNotExist:
                self.log("Locale %s SKIPPED" % code, "font-weight:bold")
                continue

            # Locales can be bundled in JARs
            jarred = location.startswith("jar:")
            if jarred:
                # We just care about the JAR path
                location = location[4:]
                split_location = location.split("!", 2)
                # Ignore malformed JAR URIs.
                if len(split_location) < 2:
                    continue
                jarname, location = split_location

                # missing file mentioned
                if jarname not in self.xpi:
                    continue
                # may be we have already read this one
                if jarname in self.jarfiles:
                    package = self.jarfiles[jarname]
                else:
                    jar = StringIO(self.xpi.read(jarname))
                    package = XPIManager(jar, mode="r", name=jarname)
            else:
                package = self.xpi

            # and now we read files from there
            location = location.strip('/')
            result = {}
            for f in package.package_contents():
                f = f.strip("/")
                if f.startswith(location) and f != location:
                    result[f.split("/")[-1]] = package.read(f)

            # file with same name in different jars can get overwritten
            if lang not in self.locales:
                self.locales[lang] = result
            else:
                self.locales[lang].update(result)