testsolver.py :  » Installer » Zero-Install » zeroinstall-injector-0.47 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Installer » Zero Install 
Zero Install » zeroinstall injector 0.47 » tests » testsolver.py
#!/usr/bin/env python
from basetest import BaseTest
import sys, os
import unittest

sys.path.insert(0, '..')
from zeroinstall.zerostore import Stores
from zeroinstall.injector import solver,reader,arch,model
from zeroinstall.injector.iface_cache import iface_cache

import logging
logger = logging.getLogger()
#logger.setLevel(logging.DEBUG)

class TestSolver(BaseTest):
  def testSimple(self):
    s = solver.DefaultSolver(model.network_full, iface_cache, Stores())

    foo = iface_cache.get_interface('http://foo/Binary.xml')
    reader.update(foo, 'Binary.xml')
    foo_src = iface_cache.get_interface('http://foo/Source.xml')
    reader.update(foo_src, 'Source.xml')
    compiler = iface_cache.get_interface('http://foo/Compiler.xml')
    reader.update(compiler, '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))
    assert s.ready
    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
  
  def testDetails(self):
    s = solver.DefaultSolver(model.network_full, iface_cache, Stores())

    foo = iface_cache.get_interface('http://foo/Binary.xml')
    reader.update(foo, 'Binary.xml')
    foo_src = iface_cache.get_interface('http://foo/Source.xml')
    reader.update(foo_src, 'Source.xml')
    compiler = iface_cache.get_interface('http://foo/Compiler.xml')
    reader.update(compiler, 'Compiler.xml')

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

    assert len(s.details) == 2
    self.assertEquals([(foo_src._main_feed.implementations['sha1=234'], None),
           (foo._main_feed.implementations['sha1=123'], 'Unsupported machine type')],
           sorted(s.details[foo]))
    assert s.details[compiler] == [(compiler._main_feed.implementations['sha1=345'], None)]

  def testRecursive(self):
    s = solver.DefaultSolver(model.network_full, iface_cache, Stores())

    foo = iface_cache.get_interface('http://foo/Recursive.xml')
    reader.update(foo, '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

    assert len(s.details) == 1
    assert s.details[foo] == [(foo._main_feed.implementations['sha1=abc'], None)]
    
  def testMultiArch(self):
    s = solver.DefaultSolver(model.network_full, iface_cache, Stores())

    foo = iface_cache.get_interface('http://foo/MultiArch.xml')
    reader.update(foo, 'MultiArch.xml')
    lib = iface_cache.get_interface('http://foo/MultiArchLib.xml')
    reader.update(lib, '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'

  def testArch(self):
    host_arch = arch.get_host_architecture()
    host_arch2 = arch.get_architecture(None, None)
    self.assertEquals(host_arch.os_ranks, host_arch2.os_ranks)
    self.assertEquals(host_arch.machine_ranks, host_arch2.machine_ranks)

    other = arch.get_architecture('FooBar', 'i486')
    self.assertEquals(2, len(other.os_ranks))

    assert 'FooBar' in other.os_ranks
    assert None in other.os_ranks
    assert 'i486' in other.machine_ranks
    assert 'ppc' not in other.machine_ranks
  
  def testRanking(self):
    s = solver.DefaultSolver(model.network_full, iface_cache, Stores())
    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.assertEquals([
      '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)

if __name__ == '__main__':
  unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.