Changeset 2271


Ignore:
Timestamp:
Feb 5, 2010 6:20:01 PM (9 years ago)
Author:
jwatson
Message:

Making unit tests for PySP compatible with coverage utilities. Farmer examples work, SIZES3 doesn't for some reason.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/tests/unit/test_ph.py

    r2270 r2271  
    55import os
    66import sys
     7import string
    78from os.path import abspath, dirname
    89sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/../..")
     
    2223import coopr.pysp
    2324import coopr.plugins.mip
     25import coopr.pysp.phinit
    2426
    2527def filter_time(line):
     
    5456           return
    5557       
    56         pyutilib.misc.setup_redirect(curr_dir+"test_quadratic_farmer.out")
    57         print "RUNNING QUADRATIC FARMER TEST"
    58         pyutilib.misc.reset_redirect()
     58        pyutilib.misc.setup_redirect(curr_dir+"farmer_quadratic.out")
     59
    5960        farmer_examples_dir = pysp_examples_dir + os.sep + "farmer"
    6061        model_dir = farmer_examples_dir + os.sep + "models"
    6162        instance_dir = farmer_examples_dir + os.sep + "scenariodata"       
    62         pyutilib.subprocess.run(coopr_bin_dir+"runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir,outfile=curr_dir+os.sep+"farmer_quadratic.out")
    63         # if the test passes, the first argument is deleted.
     63        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
     64        args = string.split(argstring)
     65        sys.argv = args
     66        coopr.pysp.phinit.run()
     67        pyutilib.misc.reset_redirect()       
    6468        self.failUnlessFileEqualsBaseline(curr_dir+"farmer_quadratic.out",curr_dir+"farmer_quadratic.baseline", filter=filter_time)
    6569
     
    6973           return       
    7074
    71         pyutilib.misc.setup_redirect(curr_dir+"test_linearized_farmer.out")
    72         print "RUNNING LINEARIZED FARMER TEST"
    73         pyutilib.misc.reset_redirect()
     75        pyutilib.misc.setup_redirect(curr_dir+"farmer_linearized.out")
    7476        farmer_examples_dir = pysp_examples_dir + os.sep + "farmer"
    7577        model_dir = farmer_examples_dir + os.sep + "models"
    7678        instance_dir = farmer_examples_dir + os.sep + "scenariodata"       
    77         pyutilib.subprocess.run(coopr_bin_dir+"runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10",outfile=curr_dir+os.sep+"farmer_linearized.out")
    78         # if the test passes, the first argument is deleted.
     79        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
     80        args = string.split(argstring)
     81        sys.argv = args
     82        coopr.pysp.phinit.run()       
     83        pyutilib.misc.reset_redirect()       
    7984        self.failUnlessFileEqualsBaseline(curr_dir+"farmer_linearized.out",curr_dir+"farmer_linearized.baseline", filter=filter_time)
    8085
     
    8489           return
    8590       
    86         pyutilib.misc.setup_redirect(curr_dir+"test_quadratic_sizes3.out")
    87         print "RUNNING QUADRATIC SIZES3 TEST"
    88         pyutilib.misc.reset_redirect()
     91        pyutilib.misc.setup_redirect(curr_dir+"sizes3_quadratic.out")
     92
    8993        sizes_example_dir = pysp_examples_dir + os.sep + "sizes"
    9094        model_dir = sizes_example_dir + os.sep + "models"
    9195        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
    92         pyutilib.subprocess.run(coopr_bin_dir+"runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+
    93                                 " --max-iterations=200"+
    94                                 " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+
    95                                 " --scenario-solver-options=\"mip_tolerances_integrality=1e-7\""+
    96                                 " --enable-ww-extensions"+
    97                                 " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+
    98                                 " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes",
    99                                 outfile=curr_dir+os.sep+"sizes3_quadratic.out")
    100         # if the test passes, the first argument is deleted.
     96        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
     97                    " --max-iterations=200"+ \
     98                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
     99                    " --scenario-solver-options=\"mip_tolerances_integrality=1e-7\""+ \
     100                    " --enable-ww-extensions"+ \
     101                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
     102                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"
     103        print "ARGSTRING=",argstring
     104        args = string.split(argstring)
     105        print "ARGS=",args
     106        sys.argv = args
     107        coopr.pysp.phinit.run()               
     108        pyutilib.misc.reset_redirect()
     109        print args
    101110        self.failUnlessFileEqualsBaseline(curr_dir+"sizes3_quadratic.out",curr_dir+"sizes3_quadratic.baseline", filter=filter_time)       
    102111
Note: See TracChangeset for help on using the changeset viewer.