comparison tests/test.py @ 55:143adebe4caa

install package in a virtualenv and make sure importing is sane
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 01 Mar 2012 15:28:34 -0800
parents 486a4640fc31
children 2e60fb704454
comparison
equal deleted inserted replaced
54:73e6956c670a 55:143adebe4caa
7 import doctest 7 import doctest
8 import os 8 import os
9 import shutil 9 import shutil
10 import sys 10 import sys
11 import tempfile 11 import tempfile
12 import virtualenv
12 from optparse import OptionParser 13 from optparse import OptionParser
14
15 def create_virtualenv(path):
16 """create a virtualenv and return the path to the python interpreter therein"""
17 virtualenv.create_environment(path)
18 for python in (('bin', 'python'), ('Scripts', 'python.exe')):
19 python = os.path.join(path, *python)
20 if os.path.exists(python):
21 return python
22 raise Exception("Python binary not found in %s" % path)
13 23
14 def run_tests(raise_on_error=False, report_first=False): 24 def run_tests(raise_on_error=False, report_first=False):
15 25
16 # add results here 26 # add results here
17 results = {} 27 results = {}
18 28
19 # doctest arguments 29 # doctest arguments
20 directory = os.path.dirname(os.path.abspath(__file__)) 30 directory = os.path.dirname(os.path.abspath(__file__))
21 extraglobs = {'here': directory} 31 extraglobs = {'here': directory, 'create_virtualenv': create_virtualenv}
22 doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error) 32 doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error)
23 if report_first: 33 if report_first:
24 doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE 34 doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE
25 35
26 # gather tests 36 # gather tests