Changeset bbd97e5 in sasview


Ignore:
Timestamp:
Apr 3, 2014 8:59:01 PM (11 years ago)
Author:
pkienzle
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
eea06fe
Parents:
27b7acc
Message:

Allow tests to be run without installing sasview

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • run.py

    r2f2d9d0 rbbd97e5  
    1515import imp 
    1616from glob import glob 
     17from contextlib import contextmanager 
     18from os.path import abspath, dirname, join as joinpath 
    1719 
    18 # find the directories for the source and build 
    19 from distutils.util import get_platform 
    20 root = os.path.abspath(os.path.dirname(__file__)) 
    21 platform = '%s-%s'%(get_platform(),sys.version[:3]) 
    22 build_path = os.path.join(root, 'build','lib.'+platform) 
    23  
    24 # Make sure that we have a private version of mplconfig 
    25 mplconfig = os.path.join(os.getcwd(), '.mplconfig') 
    26 os.environ['MPLCONFIGDIR'] = mplconfig 
    27 if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
    28 #import matplotlib 
    29 #matplotlib.use('Agg') 
    30 #print matplotlib.__file__ 
    31 #import pylab; pylab.hold(False) 
    3220 
    3321def addpath(path): 
     
    3624    environment variable for subprocesses. 
    3725    """ 
    38     path = os.path.abspath(path) 
     26    path = abspath(path) 
    3927    if 'PYTHONPATH' in os.environ: 
    4028        PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH'] 
     
    4432    sys.path.insert(0, path) 
    4533 
    46 from contextlib import contextmanager 
    4734@contextmanager 
    4835def cd(path): 
     
    5744def import_package(modname, path): 
    5845    """Import a package into a particular point in the python namespace""" 
    59     mod = imp.load_source(modname, os.path.abspath(os.path.join(path,'__init__.py'))) 
     46    mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 
    6047    sys.modules[modname] = mod 
    61     mod.__path__ = [os.path.abspath(path)] 
     48    mod.__path__ = [abspath(path)] 
    6249    return mod 
    6350 
     
    6552    """Import a DLL from the build directory""" 
    6653    # build_path comes from context 
    67     path = glob(os.path.join(build_path, *modname.split('.'))+'.*')[0] 
     54    path = glob(joinpath(build_path, *modname.split('.'))+'.*')[0] 
    6855    #print "importing", modname, "from", path 
    6956    return imp.load_dynamic(modname, path) 
    7057 
     58def prepare(): 
     59    # Don't create *.pyc files 
     60    sys.dont_write_bytecode = True 
    7161 
    72 # Don't create *.pyc files 
    73 sys.dont_write_bytecode = True 
     62    # Debug numpy warnings 
     63    #import numpy; numpy.seterr(all='raise') 
    7464 
    75 # Debug numpy warnings 
    76 #import numpy; numpy.seterr(all='raise') 
     65    # find the directories for the source and build 
     66    from distutils.util import get_platform 
     67    root = abspath(dirname(__file__)) 
     68    platform = '%s-%s'%(get_platform(),sys.version[:3]) 
     69    build_path = joinpath(root, 'build','lib.'+platform) 
    7770 
    78 # add periodictable to the path 
    79 try: import periodictable 
    80 except: addpath(os.path.join(root, '..','periodictable')) 
     71    # Make sure that we have a private version of mplconfig 
     72    mplconfig = joinpath(abspath(dirname(__file__)), '.mplconfig') 
     73    os.environ['MPLCONFIGDIR'] = mplconfig 
     74    if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
     75    #import matplotlib 
     76    #matplotlib.use('Agg') 
     77    #print matplotlib.__file__ 
     78    #import pylab; pylab.hold(False) 
     79    # add periodictable to the path 
     80    try: import periodictable 
     81    except: addpath(joinpath(root, '..','periodictable')) 
    8182 
    82 # select wx version 
    83 #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython')) 
     83    # select wx version 
     84    #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython')) 
    8485 
    85 # Build project if the build directory does not already exist. 
    86 if not os.path.exists(build_path): 
    87     import subprocess 
    88     with cd(root): 
    89         subprocess.call((sys.executable, "setup.py", "build"), shell=False) 
     86    # Build project if the build directory does not already exist. 
     87    if not os.path.exists(build_path): 
     88        import subprocess 
     89        with cd(root): 
     90            subprocess.call((sys.executable, "setup.py", "build"), shell=False) 
    9091 
    91 # Put the source trees on the path 
    92 addpath(os.path.join(root, 'src')) 
    93 addpath(os.path.join(root, 'park-1.2.1')) 
     92    # Put the source trees on the path 
     93    addpath(joinpath(root, 'src')) 
     94    addpath(joinpath(root, 'park-1.2.1')) 
    9495 
    95 # Import the sansview package from root/sansview as sans.sansview.  It would 
    96 # be better to just store the package in src/sans/sansview. 
    97 import sans 
    98 sans.sansview = import_package('sans.sansview', os.path.join(root,'sansview')) 
     96    # Import the sansview package from root/sansview as sans.sansview.  It would 
     97    # be better to just store the package in src/sans/sansview. 
     98    import sans 
     99    sans.sansview = import_package('sans.sansview', joinpath(root,'sansview')) 
    99100 
    100 # The sans.models package Compiled Model files should be pulled in from the build directory even though 
    101 # the source is stored in src/sans/models. 
     101    # The sans.models package Compiled Model files should be pulled in from the build directory even though 
     102    # the source is stored in src/sans/models. 
    102103 
    103 # Compiled modules need to be pulled from the build directory. 
    104 # Some packages are not where they are needed, so load them explicitly. 
    105 import sans.pr 
    106 sans.pr.core = import_package('sans.pr.core', 
    107                               os.path.join(build_path, 'sans', 'pr', 'core')) 
    108 #import_dll('park._modeling') 
     104    # Compiled modules need to be pulled from the build directory. 
     105    # Some packages are not where they are needed, so load them explicitly. 
     106    import sans.pr 
     107    sans.pr.core = import_package('sans.pr.core', 
     108                                  joinpath(build_path, 'sans', 'pr', 'core')) 
     109    #import_dll('park._modeling') 
    109110 
    110 #park = import_package('park',os.path.join(build_path,'park')) 
     111    #park = import_package('park',os.path.join(build_path,'park')) 
    111112 
    112 # Pull the entire sans.models package from the build directory since it contains 
    113 # a mixture of autogenerated python and C.  Any changes in models will require 
    114 # a rebuild with setup.py build 
    115 sans.models = import_package('sans.models', os.path.join(build_path, 'sans', 'models')) 
     113    # Pull the entire sans.models package from the build directory since it contains 
     114    # a mixture of autogenerated python and C.  Any changes in models will require 
     115    # a rebuild with setup.py build 
     116    sans.models = import_package('sans.models', joinpath(build_path, 'sans', 'models')) 
    116117 
    117 sys.path.append(build_path) 
     118    sys.path.append(build_path) 
    118119 
    119 #print "\n".join(sys.path) 
    120 #from sans.models import SphereModel 
     120    #print "\n".join(sys.path) 
     121    #from sans.models import SphereModel 
    121122 
    122 # Won't need freeze support when running from the source tree 
    123 #import multiprocessing 
    124 #multiprocessing.freeze_support() 
    125  
    126 # start sasview 
    127 from sans.sansview.sansview import SasView 
    128 SasView() 
     123if __name__ == "__main__": 
     124    # start sasview 
     125    #import multiprocessing 
     126    #multiprocessing.freeze_support() 
     127    prepare() 
     128    from sans.sansview.sansview import SasView 
     129    SasView() 
  • test/utest_sansview.py

    r21b7a49 rbbd97e5  
    88    print "xmlrunner needs to be installed to run these tests" 
    99    print "Try easy_install unittest-xml-reporting" 
     10    sys.exit(1) 
    1011 
    1112# Check whether we have matplotlib installed 
     
    2122    SKIPPED_DIRS.append("sansguiframe") 
    2223 
    23 COMMAND_SEP = ';' 
    24 if os.name == 'nt': 
    25     COMMAND_SEP = '&' 
     24#COMMAND_SEP = ';' 
     25#if os.name == 'nt': 
     26#    COMMAND_SEP = '&' 
    2627 
    2728def run_tests(): 
     29    test_root = os.path.abspath(os.path.dirname(__file__)) 
     30    run_one_py = os.path.join(test_root, 'run_one.py') 
    2831    passed = 0 
    2932    failed = 0 
     
    3235    n_failures = 0 
    3336     
    34     for d in os.listdir(os.getcwd()): 
     37    for d in os.listdir(test_root): 
    3538         
    3639        # Check for modules to be skipped 
     
    3942         
    4043        # Go through modules looking for unit tests 
    41         module_dir = os.path.join(os.getcwd(),d,"test") 
     44        module_dir = os.path.join(test_root, d, "test") 
    4245        if os.path.isdir(module_dir): 
    4346            for f in os.listdir(module_dir): 
     
    4548                if os.path.isfile(file_path) and f.startswith("utest_") and f.endswith(".py"): 
    4649                    module_name,_ = os.path.splitext(f) 
    47                     code = "cd %s%s%s -c \"import sys;import xmlrunner;import unittest;sys.path.insert(0, '%s');" % (module_dir, COMMAND_SEP, sys.executable, module_dir) 
    48                     code += "from %s import *;" % module_name 
    49                     code += "unittest.main(testRunner=xmlrunner.XMLTestRunner(output='logs'))\"" 
     50                    code = '"%s" %s %s'%(sys.executable, run_one_py, file_path) 
    5051                    proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) 
    5152                    std_out, std_err = proc.communicate() 
     53                    #print std_out 
     54                    #sys.exit() 
    5255                    has_failed = True 
    5356                    m = re.search("Ran ([0-9]+) test", std_out) 
Note: See TracChangeset for help on using the changeset viewer.