home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2421 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.8 KB  |  117 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from setuptools import Command
  5. from distutils.errors import DistutilsOptionError
  6. import sys
  7. from pkg_resources import *
  8. from unittest import TestLoader, main
  9.  
  10. class ScanningLoader(TestLoader):
  11.     
  12.     def loadTestsFromModule(self, module):
  13.         tests = []
  14.         if module.__name__ != 'setuptools.tests.doctest':
  15.             tests.append(TestLoader.loadTestsFromModule(self, module))
  16.         
  17.         if hasattr(module, 'additional_tests'):
  18.             tests.append(module.additional_tests())
  19.         
  20.         if hasattr(module, '__path__'):
  21.             for file in resource_listdir(module.__name__, ''):
  22.                 if file.endswith('.py') and file != '__init__.py':
  23.                     submodule = module.__name__ + '.' + file[:-3]
  24.                 elif resource_exists(module.__name__, file + '/__init__.py'):
  25.                     submodule = module.__name__ + '.' + file
  26.                 
  27.                 tests.append(self.loadTestsFromName(submodule))
  28.             
  29.         
  30.         if len(tests) != 1:
  31.             return self.suiteClass(tests)
  32.         return tests[0]
  33.  
  34.  
  35.  
  36. class test(Command):
  37.     description = 'run unit tests after in-place build'
  38.     user_options = [
  39.         ('test-module=', 'm', "Run 'test_suite' in specified module"),
  40.         ('test-suite=', 's', "Test suite to run (e.g. 'some_module.test_suite')")]
  41.     
  42.     def initialize_options(self):
  43.         self.test_suite = None
  44.         self.test_module = None
  45.         self.test_loader = None
  46.  
  47.     
  48.     def finalize_options(self):
  49.         if self.test_suite is None:
  50.             if self.test_module is None:
  51.                 self.test_suite = self.distribution.test_suite
  52.             else:
  53.                 self.test_suite = self.test_module + '.test_suite'
  54.         elif self.test_module:
  55.             raise DistutilsOptionError('You may specify a module or a suite, but not both')
  56.         
  57.         self.test_args = [
  58.             self.test_suite]
  59.         if self.verbose:
  60.             self.test_args.insert(0, '--verbose')
  61.         
  62.         if self.test_loader is None:
  63.             self.test_loader = getattr(self.distribution, 'test_loader', None)
  64.         
  65.         if self.test_loader is None:
  66.             self.test_loader = 'setuptools.command.test:ScanningLoader'
  67.         
  68.  
  69.     
  70.     def with_project_on_sys_path(self, func):
  71.         self.run_command('egg_info')
  72.         self.reinitialize_command('build_ext', inplace = 1)
  73.         self.run_command('build_ext')
  74.         ei_cmd = self.get_finalized_command('egg_info')
  75.         old_path = sys.path[:]
  76.         old_modules = sys.modules.copy()
  77.         
  78.         try:
  79.             sys.path.insert(0, normalize_path(ei_cmd.egg_base))
  80.             working_set.__init__()
  81.             add_activation_listener((lambda dist: dist.activate()))
  82.             require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
  83.             func()
  84.         finally:
  85.             sys.path[:] = old_path
  86.             sys.modules.clear()
  87.             sys.modules.update(old_modules)
  88.             working_set.__init__()
  89.  
  90.  
  91.     
  92.     def run(self):
  93.         if self.distribution.install_requires:
  94.             self.distribution.fetch_build_eggs(self.distribution.install_requires)
  95.         
  96.         if self.distribution.tests_require:
  97.             self.distribution.fetch_build_eggs(self.distribution.tests_require)
  98.         
  99.         if self.test_suite:
  100.             cmd = ' '.join(self.test_args)
  101.             if self.dry_run:
  102.                 self.announce('skipping "unittest %s" (dry run)' % cmd)
  103.             else:
  104.                 self.announce('running "unittest %s"' % cmd)
  105.                 self.with_project_on_sys_path(self.run_tests)
  106.         
  107.  
  108.     
  109.     def run_tests(self):
  110.         import unittest
  111.         loader_ep = EntryPoint.parse('x=' + self.test_loader)
  112.         loader_class = loader_ep.load(require = False)
  113.         unittest.main(None, None, [
  114.             unittest.__file__] + self.test_args, testLoader = loader_class())
  115.  
  116.  
  117.