home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import os
- import string
- import re
- import pythoncom
- import win32com.client as win32com
- from util import CheckClean, TestCase, CapturingFunctionTestCase, TestLoader
- import win32com.test.util as win32com
- import traceback
- import getopt
- import unittest
- verbosity = 1
-
- try:
- this_file = __file__
- except NameError:
- this_file = sys.argv[0]
-
-
- def GenerateAndRunOldStyle():
- import GenTestScripts
- GenTestScripts.GenerateAll()
-
- try:
- pass
- finally:
- GenTestScripts.CleanAll()
-
-
-
- def CleanGenerated():
- import win32com
- import shutil
- if os.path.isdir(win32com.__gen_path__):
- if verbosity > 1:
- print 'Deleting files from %s' % win32com.__gen_path__
-
- shutil.rmtree(win32com.__gen_path__)
-
- import win32com.client.gencache as win32com
- win32com.client.gencache.__init__()
-
-
- def RemoveRefCountOutput(data):
- while None:
- last_line_pos = data.rfind('\n')
- if not re.match('\\[\\d+ refs\\]', data[last_line_pos + 1:]):
- break
-
- if last_line_pos < 0:
- return ''
- data = data[:last_line_pos]
- continue
- return data
-
-
- def ExecuteSilentlyIfOK(cmd, testcase):
- f = os.popen(cmd)
- data = f.read().strip()
- rc = f.close()
- if rc:
- print data
- testcase.fail("Executing '%s' failed (%d)" % (cmd, rc))
-
- return RemoveRefCountOutput(data)
-
-
- class PyCOMTest(TestCase):
- no_leak_tests = True
-
- def testit(self):
- fname = os.path.join(os.path.dirname(this_file), 'testPyComTest.py')
- cmd = '%s "%s" -q 2>&1' % (sys.executable, fname)
- data = ExecuteSilentlyIfOK(cmd, self)
-
-
-
- class PippoTest(TestCase):
-
- def testit(self):
- python = sys.executable
- fname = os.path.join(os.path.dirname(this_file), 'testPippo.py')
- cmd = '%s "%s" 2>&1' % (python, fname)
- ExecuteSilentlyIfOK(cmd, self)
-
-
- unittest_modules = [
- 'testIterators testvbscript_regexp testStorage \n testStreams testWMI policySemantics testShell testROT\n testAXScript testxslt testDictionary testCollections\n testServers errorSemantics.test testvb testArrays\n testClipboard testMarshal\n '.split(),
- 'testMSOffice.TestAll testMSOfficeEvents.test testAccess.test\n testExplorer.TestAll testExchange.test\n '.split(),
- 'testmakepy.TestAll\n '.split()]
- output_checked_programs = [
- [
- ('cscript.exe /nologo //E:vbscript testInterp.vbs', 'VBScript test worked OK'),
- ('cscript.exe /nologo //E:vbscript testDictionary.vbs', 'VBScript has successfully tested Python.Dictionary')],
- [],
- []]
- custom_test_cases = [
- [
- PyCOMTest,
- PippoTest],
- [],
- []]
-
- def get_test_mod_and_func(test_name, import_failures):
- if test_name.find('.') > 0:
- (mod_name, func_name) = test_name.split('.')
- else:
- mod_name = test_name
- func_name = None
-
- try:
- mod = __import__(mod_name)
- except:
- import_failures.append((mod_name, sys.exc_info()[:2]))
- return (None, None)
-
- if func_name is None:
- func = None
- else:
- func = getattr(mod, func_name)
- return (mod, func)
-
-
- def make_test_suite(test_level = 1):
- suite = unittest.TestSuite()
- import_failures = []
- loader = TestLoader()
- for i in range(testLevel):
- for mod_name in unittest_modules[i]:
- (mod, func) = get_test_mod_and_func(mod_name, import_failures)
- if mod is None:
- continue
-
- if func is not None:
- test = win32com.test.util.CapturingFunctionTestCase(func, description = mod_name)
- elif hasattr(mod, 'suite'):
- test = mod.suite()
- else:
- test = loader.loadTestsFromModule(mod)
- suite.addTest(test)
-
- for cmd, output in output_checked_programs[i]:
- suite.addTest(win32com.test.util.ShellTestCase(cmd, output))
-
- for test_class in custom_test_cases[i]:
- suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(test_class))
-
-
- return (suite, import_failures)
-
-
- def usage(why):
- print why
- print
- print 'win32com test suite'
- print 'usage: testall [-v] test_level'
- print ' where test_level is an integer 1-3. Level 1 tests are quick,'
- print ' level 2 tests invoke Word, IE etc, level 3 take ages!'
- sys.exit(1)
-
- if __name__ == '__main__':
-
- try:
- (opts, args) = getopt.getopt(sys.argv[1:], 'v')
- except getopt.error:
- why = None
- usage(why)
-
- for opt, val in opts:
- if opt == '-v':
- verbosity += 1
- continue
-
- testLevel = 1
- test_names = []
- for arg in args:
-
- try:
- testLevel = int(arg)
- if testLevel < 0 or testLevel > 3:
- raise ValueError, 'Only levels 1-3 are supported'
- testLevel > 3
- continue
- except ValueError:
- test_names.append(arg)
- continue
-
-
-
- if test_names:
- usage('Test names are not supported yet')
-
- CleanGenerated()
- (suite, import_failures) = make_test_suite(testLevel)
- if verbosity:
- if hasattr(sys, 'gettotalrefcount'):
- print 'This is a debug build - memory leak tests will also be run.'
- print 'These tests may take *many* minutes to run - be patient!'
- print '(running from python.exe will avoid these leak tests)'
-
- print 'Executing level %d tests - %d test cases will be run' % (testLevel, suite.countTestCases())
- if verbosity == 1 and suite.countTestCases() < 70:
- print '|' * suite.countTestCases()
-
-
- testRunner = unittest.TextTestRunner(verbosity = verbosity)
- testResult = testRunner.run(suite)
- if import_failures:
- testResult.stream.writeln('*** The following test modules could not be imported ***')
- for exc_type, exc_val in import_failures:
- desc = testResult._exc_info_to_string((exc_type, exc_val, None))
- testResult.stream.write('%s: %s' % (mod_name, desc))
-
- testResult.stream.writeln('*** %d test(s) could not be run ***' % len(import_failures))
-
- if not testResult.wasSuccessful():
- print '********************', '- unittest tests FAILED'
-
- CheckClean()
- pythoncom.CoUninitialize()
- CleanGenerated()
-
-