basetest.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 » basetest.py
#!/usr/bin/env python
import sys, tempfile, os, shutil, StringIO
import unittest
import logging
import warnings

# It's OK to test deprecated features
warnings.filterwarnings("ignore", category = DeprecationWarning)

# Catch silly mistakes...
os.environ['HOME'] = '/home/idontexist'
os.environ['LANGUAGE'] = 'C'

sys.path.insert(0, '..')
from zeroinstall.injector import qdom
from zeroinstall.injector import iface_cache,download,distro
from zeroinstall.zerostore import Store;Store._add_with_helper=lambda*unused:False
from zeroinstall import support,helpers
from zeroinstall.support import basedir

dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg')

empty_feed = qdom.parse(StringIO.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
<name>Empty</name>
<summary>just for testing</summary>
</interface>"""))

mydir = os.path.dirname(__file__)

# Catch us trying to run the GUI and return a dummy string instead
old_execvp = os.execvp
def test_execvp(prog, args):
  if prog.endswith('/0launch-gui'):
    prog = os.path.join(mydir, 'test-gui')
  return old_execvp(prog, args)

os.execvp = test_execvp

class BaseTest(unittest.TestCase):
  def setUp(self):
    self.config_home = tempfile.mktemp()
    self.cache_home = tempfile.mktemp()
    self.cache_system = tempfile.mktemp()
    self.gnupg_home = tempfile.mktemp()
    os.environ['GNUPGHOME'] = self.gnupg_home
    os.environ['XDG_CONFIG_HOME'] = self.config_home
    os.environ['XDG_CONFIG_DIRS'] = ''
    os.environ['XDG_CACHE_HOME'] = self.cache_home
    os.environ['XDG_CACHE_DIRS'] = self.cache_system
    reload(basedir)
    assert basedir.xdg_config_home == self.config_home
    iface_cache.iface_cache.__init__()

    os.mkdir(self.config_home, 0700)
    os.mkdir(self.cache_home, 0700)
    os.mkdir(self.cache_system, 0500)
    os.mkdir(self.gnupg_home, 0700)

    if os.environ.has_key('DISPLAY'):
      del os.environ['DISPLAY']

    logging.getLogger().setLevel(logging.WARN)

    download._downloads = {}

    self.old_path = os.environ['PATH']
    os.environ['PATH'] = dpkgdir + ':' + self.old_path

    distro._host_distribution = distro.DebianDistribution(dpkgdir + '/status',
                      dpkgdir + '/pkgcache.bin')
  
  def tearDown(self):
    shutil.rmtree(self.config_home)
    support.ro_rmtree(self.cache_home)
    shutil.rmtree(self.cache_system)
    shutil.rmtree(self.gnupg_home)

    os.environ['PATH'] = self.old_path
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.