testdistro.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 » testdistro.py
#!/usr/bin/env python
from basetest import BaseTest,empty_feed
import sys, os, tempfile
from StringIO import StringIO
import unittest

sys.path.insert(0, '..')
from zeroinstall.injector import distro,model,qdom

def parse_impls(impls, test_distro):
  xml = """<?xml version="1.0" ?>
     <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
       <name>Foo</name>
       <summary>Foo</summary>
       <description>Foo</description>
       %s
    </interface>""" % impls
  element = qdom.parse(StringIO(xml))
  return model.ZeroInstallFeed(element, "myfeed.xml", test_distro)

class TestDistro(BaseTest):
  def setUp(self):
    BaseTest.setUp(self)
    self.feed = model.ZeroInstallFeed(empty_feed, local_path = '/empty.xml')

  def tearDown(self):  
    BaseTest.tearDown(self)

  def testCache(self):
    src = tempfile.NamedTemporaryFile()
    try:
      cache = distro.Cache('test-cache', src.name)
      self.assertEquals(None, cache.get("foo"))
      cache.put("foo", "1")
      self.assertEquals("1", cache.get("foo"))
      cache.put("foo", "2")
      self.assertEquals("2", cache.get("foo"))

      # new cache...
      cache = distro.Cache('test-cache', src.name)
      self.assertEquals("2", cache.get("foo"))

      src.write("hi")
      src.flush()

      self.assertEquals("2", cache.get("foo"))

      # new cache...
      cache = distro.Cache('test-cache', src.name)
      self.assertEquals(None, cache.get("foo"))

    finally:
      src.close()

  def factory(self, id):
    impl = model.DistributionImplementation(self.feed, id)
    assert id not in self.feed.implementations
    self.feed.implementations[id] = impl
    return impl

  def testDefault(self):
    host = distro.Distribution()

    host.get_package_info('gimp', self.factory)
    self.assertEquals(self.feed.implementations, {})

  def testDebian(self):
    dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg')
    host = distro.DebianDistribution(
        os.path.join(dpkgdir, 'status'),
        os.path.join(dpkgdir, 'pkgcache.bin'))

    self.assertEquals(2, len(host.versions))

    host.get_package_info('gimp', self.factory)
    self.assertEquals({}, self.feed.implementations)

    host.get_package_info('python-bittorrent', self.factory)
    self.assertEquals(2, len(self.feed.implementations))
    bittorrent_installed = self.feed.implementations['package:deb:python-bittorrent:3.4.2-10']
    bittorrent_uninstalled = self.feed.implementations['package:deb:python-bittorrent:3.4.2-11.1']
    self.assertEquals('3.4.2-10', bittorrent_installed.get_version())
    self.assertTrue(bittorrent_installed.installed)
    self.assertFalse(bittorrent_uninstalled.installed)
    self.assertEquals(None, bittorrent_installed.machine)

    self.feed = model.ZeroInstallFeed(empty_feed, local_path = '/empty.xml')
    host.get_package_info('libxcomposite-dev', self.factory)
    self.assertEquals(1, len(self.feed.implementations))
    libxcomposite = self.feed.implementations['package:deb:libxcomposite-dev:0.3.1-1']
    self.assertEquals('0.3.1-1', libxcomposite.get_version())
    self.assertEquals('i386', libxcomposite.machine)
  
  def testRPM(self):
    rpmdir = os.path.join(os.path.dirname(__file__), 'rpm')
    os.environ['PATH'] = rpmdir + ':' + self.old_path
    rpm = distro.RPMDistribution(os.path.join(rpmdir, 'status'))

    self.assertEquals(2, len(rpm.versions))

    rpm.get_package_info('yast2-update', self.factory)
    self.assertEquals(1, len(self.feed.implementations))
    yast = self.feed.implementations['package:rpm:yast2-update:2.15.23-21:i586']
    self.assertEquals('2.15.23-21', yast.get_version())
    self.assertEquals('*-i586', yast.arch)

    impls = parse_impls("""
        <package-implementation distributions="Debian" package="yast2-mail"/>
        <package-implementation distributions="RPM" package="yast2-update"/>
        """, rpm).implementations
    assert len(impls) == 1, impls
    impl, = impls
    assert impl == 'package:rpm:yast2-update:2.15.23-21:i586'

    impls = parse_impls("""
        <package-implementation distributions="RPM" package="yast2-mail"/>
        <package-implementation distributions="RPM" package="yast2-update"/>
        """, rpm).implementations
    assert len(impls) == 2, impls

    impls = parse_impls("""
        <package-implementation distributions="" package="yast2-mail"/>
        <package-implementation package="yast2-update"/>
        """, rpm).implementations
    assert len(impls) == 2, impls

  def testGentoo(self):
    pkgdir = os.path.join(os.path.dirname(__file__), 'gentoo')
    ebuilds = distro.GentooDistribution(pkgdir)

    ebuilds.get_package_info('media-gfx/gimp', self.factory)
    self.assertEquals({}, self.feed.implementations)

    ebuilds.get_package_info('sys-apps/portage', self.factory)
    self.assertEquals(1, len(self.feed.implementations))
    impl = self.feed.implementations['package:gentoo:sys-apps/portage:2.1.7.16:x86_64']
    self.assertEquals('2.1.7.16', impl.get_version())
    self.assertEquals('x86_64', impl.machine)

    ebuilds.get_package_info('sys-kernel/gentoo-sources', self.factory)
    self.assertEquals(3, len(self.feed.implementations))
    impl = self.feed.implementations['package:gentoo:sys-kernel/gentoo-sources:2.6.30-4:i686']
    self.assertEquals('2.6.30-4', impl.get_version())
    self.assertEquals('i686', impl.machine)
    impl = self.feed.implementations['package:gentoo:sys-kernel/gentoo-sources:2.6.32:x86_64']
    self.assertEquals('2.6.32', impl.get_version())
    self.assertEquals('x86_64', impl.machine)

    ebuilds.get_package_info('app-emulation/emul-linux-x86-baselibs', self.factory)
    self.assertEquals(4, len(self.feed.implementations))
    impl = self.feed.implementations['package:gentoo:app-emulation/emul-linux-x86-baselibs:20100220:i386']
    self.assertEquals('20100220', impl.get_version())
    self.assertEquals('i386', impl.machine)

  def testPorts(self):
    pkgdir = os.path.join(os.path.dirname(__file__), 'ports')
    ports = distro.PortsDistribution(pkgdir)

    ports.get_package_info('zeroinstall-injector', self.factory)
    self.assertEquals(1, len(self.feed.implementations))
    impl = self.feed.implementations['package:ports:zeroinstall-injector:0.41:x86_64']
    self.assertEquals('0.41', impl.get_version())
    self.assertEquals('x86_64', impl.machine)

  def testCleanVersion(self):
    self.assertEquals('1', distro.try_cleanup_distro_version('1:0.3.1-1'))
    self.assertEquals('0.3.1-1', distro.try_cleanup_distro_version('0.3.1-1ubuntu0'))
    self.assertEquals('0.3-post1-rc2', distro.try_cleanup_distro_version('0.3-post1-rc2'))
    self.assertEquals('0.3.1-2', distro.try_cleanup_distro_version('0.3.1-r2-r3'))

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.