예제 #1
0
 def testDecideBug(self):
     s = solver.DefaultSolver(self.config)
     watch_xml = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'watchdog.xml')
     s.solve(watch_xml,
             arch.get_architecture(None, None),
             command_name='test')
예제 #2
0
    def testReplacedConflicts(self):
        self.import_feed('http://localhost:8000/Hello', 'Hello')
        s = solver.DefaultSolver(self.config)
        replaced_path = model.canonical_iface_uri(
            os.path.join(mydir, 'Replaced.xml'))
        replaced_conflicts_path = model.canonical_iface_uri(
            os.path.join(mydir, 'ReplacedConflicts.xml'))
        r = Requirements(replaced_conflicts_path)
        s.solve_for(r)
        assert s.ready, s.get_failure_reason()
        assert s.selections
        self.assertEqual("b",
                         s.selections.selections[replaced_conflicts_path].id)
        self.assertEqual(
            "2", s.selections.selections[replaced_conflicts_path].version)
        self.assertEqual(
            "sha1=3ce644dc725f1d21cfcf02562c76f375944b266a",
            s.selections.selections["http://localhost:8000/Hello"].id)
        self.assertEqual(2, len(s.selections.selections))

        s.extra_restrictions[self.config.iface_cache.get_interface(
            r.interface_uri)] = [
                model.VersionRangeRestriction(model.parse_version('2'), None)
            ]

        s.solve_for(r)
        assert s.ready, s.get_failure_reason()
        assert s.selections
        self.assertEqual(
            "1", s.selections.selections[replaced_conflicts_path].version)
        self.assertEqual("0", s.selections.selections[replaced_path].version)
        self.assertEqual(2, len(s.selections.selections))
예제 #3
0
 def testRecommendBug(self):
     s = solver.DefaultSolver(self.config)
     optional_missing_xml = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'OptionalMissing.xml')
     s.solve(optional_missing_xml,
             arch.get_architecture(None, None),
             command_name=None)
예제 #4
0
    def testLangs(self):
        iface_cache = self.config.iface_cache
        try:
            locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

            s = solver.DefaultSolver(self.config)
            iface = iface_cache.get_interface('http://foo/Langs.xml')
            self.import_feed(iface.uri, 'Langs.xml')

            # 1 is the oldest, but the only one in our language
            binary_arch = arch.get_architecture(None, 'arch_1')
            s.solve('http://foo/Langs.xml', binary_arch)
            assert s.ready
            self.assertEqual('sha1=1', s.selections[iface].id)

            # 6 is the newest, and close enough, even though not
            # quite the right locale
            binary_arch = arch.get_architecture(None, 'arch_2')
            s.solve('http://foo/Langs.xml', binary_arch)
            assert s.ready
            self.assertEqual('sha1=6', s.selections[iface].id)

            # 9 is the newest, although 7 is a closer match
            binary_arch = arch.get_architecture(None, 'arch_3')
            s.solve('http://foo/Langs.xml', binary_arch)
            assert s.ready
            self.assertEqual('sha1=9', s.selections[iface].id)

            # 11 is the newest we understand
            binary_arch = arch.get_architecture(None, 'arch_4')
            s.solve('http://foo/Langs.xml', binary_arch)
            assert s.ready
            self.assertEqual('sha1=11', s.selections[iface].id)

            # 13 is the newest we understand
            binary_arch = arch.get_architecture(None, 'arch_5')
            s.solve('http://foo/Langs.xml', binary_arch)
            assert s.ready
            self.assertEqual('sha1=13', s.selections[iface].id)

            def check(target_arch, langs, expected):
                s.langs = langs
                binary_arch = arch.get_architecture(None, target_arch)
                s.solve('http://foo/Langs.xml', binary_arch)
                assert s.ready
                self.assertEqual(expected, s.selections[iface].id)

            # We don't understand any, so pick the newest
            check('arch_2', ['es_ES'], 'sha1=6')

            # These two have the same version number. Choose the
            # one most appropriate to our country
            check('arch_6', ['zh_CN'], 'sha1=15')
            check('arch_6', ['zh_TW'], 'sha1=16')

            # Same, but one doesn't have a country code
            check('arch_7', ['bn'], 'sha1=17')
            check('arch_7', ['bn_IN'], 'sha1=18')
        finally:
            locale.setlocale(locale.LC_ALL, '')
예제 #5
0
    def testRanking(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)
        ranking = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'Ranking.xml')
        iface = iface_cache.get_interface(ranking)

        binary_arch = arch.get_architecture('Linux', 'x86_64')
        selected = []
        while True:
            s.solve(ranking, binary_arch)
            if not s.ready:
                break
            impl = s.selections[iface]
            selected.append(impl.get_version() + ' ' + impl.arch)
            impl.arch = 'Foo-odd'  # prevent reselection
        self.assertEqual(
            [
                '0.2 Linux-i386',  # poor arch, but newest version
                '0.1 Linux-x86_64',  # 64-bit is best match for host arch
                '0.1 Linux-i686',
                '0.1 Linux-i586',
                '0.1 Linux-i486'
            ],  # ordering of x86 versions
            selected)
예제 #6
0
    def testRestricts(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)
        uri = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                           'Conflicts.xml')
        versions = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                'Versions.xml')
        iface = iface_cache.get_interface(uri)

        r = Requirements(uri)

        # Selects 0.2 as the highest version, applying the restriction to versions < 4.
        s.solve_for(r)
        assert s.ready
        self.assertEqual("0.2", s.selections.selections[uri].version)
        self.assertEqual("3", s.selections.selections[versions].version)

        s.extra_restrictions[iface] = [
            model.VersionRestriction(model.parse_version('0.1'))
        ]
        s.solve_for(r)
        assert s.ready
        self.assertEqual("0.1", s.selections.selections[uri].version)
        self.assertEqual(None, s.selections.selections.get(versions, None))

        s.extra_restrictions[iface] = [
            model.VersionRestriction(model.parse_version('0.3'))
        ]
        s.solve_for(r)
        assert not s.ready
예제 #7
0
    def testSimple(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)

        foo = iface_cache.get_interface('http://foo/Binary.xml')
        self.import_feed(foo.uri, 'Binary.xml')
        foo_src = iface_cache.get_interface('http://foo/Source.xml')
        self.import_feed(foo_src.uri, 'Source.xml')
        compiler = iface_cache.get_interface('http://foo/Compiler.xml')
        self.import_feed(compiler.uri, 'Compiler.xml')

        binary_arch = arch.Architecture({None: 1}, {None: 1})
        assert str(binary_arch).startswith("<Arch")
        s.solve('http://foo/Binary.xml', binary_arch)

        assert s.ready
        assert s.feeds_used == set([foo.uri]), s.feeds_used
        assert s.selections[foo].id == 'sha1=123'

        # Now ask for source instead
        s.solve('http://foo/Binary.xml',
                arch.SourceArchitecture(binary_arch),
                command_name='compile')
        assert s.ready, s.get_failure_reason()
        assert s.feeds_used == set([foo.uri, foo_src.uri,
                                    compiler.uri]), s.feeds_used
        assert s.selections[foo].id == 'sha1=234'  # The source
        assert s.selections[
            compiler].id == 'sha1=345'  # A binary needed to compile it

        assert not s.details
예제 #8
0
    def testMultiArch(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)

        foo = iface_cache.get_interface('http://foo/MultiArch.xml')
        self.import_feed(foo.uri, 'MultiArch.xml')
        lib = iface_cache.get_interface('http://foo/MultiArchLib.xml')
        self.import_feed(lib.uri, 'MultiArchLib.xml')

        # On an i686 system we can only use the i486 implementation

        binary_arch = arch.get_architecture('Linux', 'i686')
        s.solve('http://foo/MultiArch.xml', binary_arch)
        assert s.ready
        assert s.selections[foo].machine == 'i486'
        assert s.selections[lib].machine == 'i486'

        # On an 64 bit system we could use either, but we prefer the 64
        # bit implementation. The i486 version of the library is newer,
        # but we must pick one that is compatible with the main binary.

        binary_arch = arch.get_architecture('Linux', 'x86_64')
        s.solve('http://foo/MultiArch.xml', binary_arch)
        assert s.ready
        assert s.selections[foo].machine == 'x86_64'
        assert s.selections[lib].machine == 'x86_64'
예제 #9
0
    def testDetails(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)

        foo_binary_uri = 'http://foo/Binary.xml'
        foo = iface_cache.get_interface(foo_binary_uri)
        self.import_feed(foo_binary_uri, 'Binary.xml')
        foo_src = iface_cache.get_interface('http://foo/Source.xml')
        self.import_feed(foo_src.uri, 'Source.xml')
        compiler = iface_cache.get_interface('http://foo/Compiler.xml')
        self.import_feed(compiler.uri, 'Compiler.xml')

        binary_arch = arch.Architecture({None: 1}, {None: 1})
        s.record_details = True
        s.solve('http://foo/Binary.xml',
                arch.SourceArchitecture(binary_arch),
                command_name='compile')
        assert s.ready, s.get_failure_reason()

        foo_src_impls = iface_cache.get_feed(foo_src.uri).implementations
        foo_impls = iface_cache.get_feed(foo.uri).implementations
        compiler_impls = iface_cache.get_feed(compiler.uri).implementations

        assert len(s.details) == 2
        self.assertEquals(
            [(foo_src_impls['sha1=234'], None),
             (foo_impls['sha1=123'], 'Unsupported machine type')],
            sorted(s.details[foo]))
        assert s.details[compiler] == [(compiler_impls['sha1=345'], None)]
예제 #10
0
 def testFeedBug(self):
     self.import_feed('http://foo/Build.xml', 'Build.xml')
     self.import_feed('http://foo/Compiler.xml', 'Compiler.xml')
     self.import_feed('http://foo/Compiler-new.xml', 'Compiler-new.xml')
     s = solver.DefaultSolver(self.config)
     s.solve('http://foo/Build.xml', arch.get_architecture(None, None))
     assert s.ready, s.get_failure_reason()
     assert s.selections
예제 #11
0
 def testCommand(self):
     s = solver.DefaultSolver(self.config)
     binary_arch = arch.Architecture({None: 1}, {None: 1})
     s.solve(command_dep, binary_arch)
     command = s.selections.selections[s.selections.interface].get_command(
         "run")
     dep, = command.requires
     dep_impl = s.selections.selections[dep.interface]
     assert dep_impl.get_command("run").path == "test-gui"
예제 #12
0
    def testRecursive(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)

        foo = iface_cache.get_interface('http://foo/Recursive.xml')
        self.import_feed(foo.uri, 'Recursive.xml')

        binary_arch = arch.Architecture({None: 1}, {None: 1})
        s.record_details = True
        s.solve('http://foo/Recursive.xml', binary_arch)
        assert s.ready

        foo_impls = iface_cache.get_feed(foo.uri).implementations

        assert len(s.details) == 1
        assert s.details[foo] == [(foo_impls['sha1=abc'], None)]
예제 #13
0
        def test(top_xml, diag_xml, expected_error):
            root = qdom.parse(
                BytesIO("""<?xml version="1.0" ?>
			<interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface" uri="{top}">
			  <name>Top-level</name>
			  <summary>Top-level</summary>
			  <group>
			    {top_xml}
			  </group>
			</interface>""".format(top=top_uri, top_xml=top_xml).encode("utf-8")))
            self.import_feed(top_uri, root)

            root = qdom.parse(
                BytesIO("""<?xml version="1.0" ?>
			<interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface" uri="{diag}">
			  <name>Diagnostics</name>
			  <summary>Diagnostics</summary>
			  <group>
			    {impls}
			  </group>
			</interface>""".format(diag=diag_uri, impls=diag_xml).encode("utf-8")))
            self.import_feed(diag_uri, root)

            root = qdom.parse(
                BytesIO("""<?xml version="1.0" ?>
			<interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface" uri="{old}">
			  <name>Old</name>
			  <summary>Old</summary>
			  <feed src='{diag}'/>
			  <replaced-by interface='{diag}'/>
			</interface>""".format(diag=diag_uri, old=old_uri).encode("utf-8")))
            self.import_feed(old_uri, root)

            r = Requirements(top_uri)
            r.os = "Windows"
            r.cpu = "x86_64"
            s = solver.DefaultSolver(self.config)
            s.solve_for(r)
            assert not s.ready, s.selections.selections

            if expected_error != str(s.get_failure_reason()):
                print(s.get_failure_reason())

            self.assertEqual(expected_error, str(s.get_failure_reason()))

            return s
예제 #14
0
    def testArchFor(self):
        s = solver.DefaultSolver(self.config)
        r = Requirements('http://foo/Binary.xml')

        r.cpu = 'i386'
        bin_arch = s.get_arch_for(r)
        self.assertEqual({'i386': 0, None: 1}, bin_arch.machine_ranks)

        r.source = True
        src_arch = s.get_arch_for(r)
        self.assertEqual({'src': 1}, src_arch.machine_ranks)

        child = self.config.iface_cache.get_interface('http://foo/Dep.xml')
        arch = s.get_arch_for(r, child)
        self.assertEqual(arch.machine_ranks, bin_arch.machine_ranks)

        child = self.config.iface_cache.get_interface(r.interface_uri)
        arch = s.get_arch_for(r, child)
        self.assertEqual(arch.machine_ranks, src_arch.machine_ranks)
예제 #15
0
    def testDetails(self):
        iface_cache = self.config.iface_cache
        s = solver.DefaultSolver(self.config)

        foo_binary_uri = 'http://foo/Binary.xml'
        foo = iface_cache.get_interface(foo_binary_uri)
        self.import_feed(foo_binary_uri, 'Binary.xml')
        foo_src = iface_cache.get_interface('http://foo/Source.xml')
        self.import_feed(foo_src.uri, 'Source.xml')
        compiler = iface_cache.get_interface('http://foo/Compiler.xml')
        self.import_feed(compiler.uri, 'Compiler.xml')

        r = Requirements('http://foo/Binary.xml')
        r.source = True
        r.command = 'compile'

        s.record_details = True
        s.solve_for(r)
        assert s.ready, s.get_failure_reason()

        foo_bin_impls = iface_cache.get_feed(foo_binary_uri).implementations
        foo_src_impls = iface_cache.get_feed(foo_src.uri).implementations
        foo_impls = iface_cache.get_feed(foo.uri).implementations
        compiler_impls = iface_cache.get_feed(compiler.uri).implementations

        assert len(s.details) == 2
        self.assertEqual([
            (foo_src_impls['impossible'], None),
            (foo_src_impls['sha1=234'], None),
            (foo_impls['sha1=123'], 'Not source code'),
            (foo_src_impls['old'], None),
        ], sorted(s.details[foo]))
        self.assertEqual([
            (compiler_impls['sha1=999'], None),
            (compiler_impls['sha1=345'], None),
            (compiler_impls['sha1=678'], None),
        ], s.details[compiler])

        def justify(uri, impl, expected):
            iface = iface_cache.get_interface(uri)
            e = s.justify_decision(r, iface, impl)
            self.assertEqual(expected, e)

        self.maxDiff = 1000
        justify(
            foo_binary_uri, foo_bin_impls["sha1=123"],
            'Binary 1.0 cannot be used (regardless of other components): Not source code'
        )
        justify(foo_binary_uri, foo_src_impls["sha1=234"],
                'Binary 1.0 was selected as the preferred version.')
        justify(
            foo_binary_uri, foo_src_impls["old"],
            'Binary 0.1 is ranked lower than 1.0: newer versions are preferred'
        )
        justify(
            foo_binary_uri, foo_src_impls["impossible"],
            "There is no possible selection using Binary 3.\n"
            "Can't find all required implementations:\n"
            "- http://foo/Binary.xml -> 3 (impossible)\n"
            "    User requested implementation 3 (impossible)\n"
            "- http://foo/Compiler.xml -> (problem)\n"
            "    http://foo/Binary.xml 3 requires version < 1.0, 1.0 <= version\n"
            "    No usable implementations satisfy the restrictions:\n"
            "      sha1=999 (5): incompatible with restrictions\n"
            "      sha1=345 (1.0): incompatible with restrictions\n"
            "      sha1=678 (0.1): incompatible with restrictions")
        justify(
            compiler.uri, compiler_impls["sha1=999"],
            '''Compiler 5 is selectable, but using it would produce a less optimal solution overall.\n\nThe changes would be:\n\nhttp://foo/Binary.xml: 1.0 to 0.1'''
        )