Changeset 2422


Ignore:
Timestamp:
Mar 11, 2010 6:01:09 PM (9 years ago)
Author:
wehart
Message:

Rework of unit tests to (a) import pyutilib.th as 'unittest' and
(b) employ test skipping.

Location:
coopr.pyomo/trunk/coopr/pyomo/tests
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/tests/examples/test_amplbook2.py

    r1768 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1211
    1312from coopr.pyomo import *
    14 import pyutilib.th
     13import pyutilib.th as unittest
    1514import glob
    1615
    17 class TestAmplbook2(pyutilib.th.TestCase): pass
     16class TestAmplbook2(unittest.TestCase): pass
    1817
    1918#
  • coopr.pyomo/trunk/coopr/pyomo/tests/examples/test_pyomo.py

    r2330 r2422  
    1313import pyutilib.services
    1414import pyutilib.subprocess
    15 import pyutilib.th
     15import pyutilib.th as unittest
    1616import coopr.pyomo.scripting.pyomo as main
    1717import StringIO
     
    2323    executable=sys.executable
    2424
    25 class Test(pyutilib.th.TestCase):
    2625
    27     def run(self, result=None):
    28         """
    29         Run the tests if GLPK is available
    30         """
    31         if pyutilib.services.registered_executable("glpsol") is None:
    32             return
    33         pyutilib.th.TestCase.run(self, result)
     26@unittest.skipIf(pyutilib.services.registered_executable("glpsol") is None, "The 'glpsol' executable is not available")
     27class Test(unittest.TestCase):
    3428
    3529    def pyomo(self, cmd, **kwds):
  • coopr.pyomo/trunk/coopr/pyomo/tests/examples/test_tutorials.py

    r1813 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1413from coopr.pyomo import *
    1514import pyutilib.misc
    16 import pyutilib.th
     15import pyutilib.th as unittest
    1716
    1817try:
     
    2221  _win32com=False #pragma:nocover
    2322
    24 class PyomoTutorials(pyutilib.th.TestCase):
     23class PyomoTutorials(unittest.TestCase):
    2524
    2625    def setUp(self):
     
    3433        self.failUnlessFileEqualsBaseline(currdir+"data.log", tutorial_dir+"data.out")
    3534
     35    @unittest.skipIf(not _win32com, "Cannot import 'win32com'")
    3636    def test_excel(self):
    37         if not _win32com:
    38            return
    3937        pyutilib.misc.run_file(tutorial_dir+"excel.py", logfile=currdir+"excel.log", execdir=tutorial_dir)
    4038        self.failUnlessFileEqualsBaseline(currdir+"excel.log", tutorial_dir+"excel.out")
  • coopr.pyomo/trunk/coopr/pyomo/tests/expr/test_canonical.py

    r2359 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1312from coopr.opt import *
    1413#from coopr.pyomo.base.var import _VarElement
    15 import pyutilib.th
     14import pyutilib.th as unittest
    1615import pyutilib.services
    1716from coopr.pyomo.preprocess.simple_preprocessor import SimplePreprocessor
     
    2726
    2827
    29 class TestBase(pyutilib.th.TestCase):
     28class TestBase(unittest.TestCase):
    3029
    3130    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_con.py

    r1994 r2422  
    66#
    77
    8 import unittest
    98import os
    109import sys
     
    1716from coopr.opt import *
    1817from coopr.pyomo.base.var import _VarElement
    19 import pyutilib.th
     18import pyutilib.th as unittest
    2019import pyutilib.services
    2120
    22 class PyomoModel(pyutilib.th.TestCase):
     21class PyomoModel(unittest.TestCase):
    2322
    2423    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_concrete.py

    r2359 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1211from coopr.pyomo import *
    1312from coopr.opt import *
    14 import pyutilib.th
     13import pyutilib.th as unittest
    1514import pyutilib.services
    1615
    17 class Test(pyutilib.th.TestCase):
     16@unittest.skipIf(not pyutilib.services.registered_executable("glpsol"), "The 'glpsol' executable is not available")
     17class Test(unittest.TestCase):
    1818
    1919    def test_blending(self):
    2020        """ The blending example from the PuLP documentation """
    21         if not pyutilib.services.registered_executable("glpsol"):
    22             return
    2321        model = Model()
    2422        model.concrete_mode()
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_expr.py

    r2050 r2422  
    66#
    77
    8 import unittest
    98import os
    109import sys
     
    1312currdir = dirname(abspath(__file__))+os.sep
    1413
    15 import pyutilib.th
     14import pyutilib.th as unittest
    1615from coopr.pyomo import *
    1716from nose.tools import nottest
    1817
    19 class PyomoModel(pyutilib.th.TestCase):
     18class PyomoModel(unittest.TestCase):
    2019
    2120    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_misc.py

    r1768 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1110
    1211from coopr.pyomo import *
    13 import pyutilib.th
     12import pyutilib.th as unittest
    1413
    1514def rule1(model):
     
    1817    return (1,model.x+model.y[1]+i,2)
    1918
    20 class PyomoModel(pyutilib.th.TestCase):
     19class PyomoModel(unittest.TestCase):
    2120
    2221    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_model.py

    r2053 r2422  
    55#
    66
    7 import unittest
    87import os
    98import sys
     
    1615from coopr.opt import *
    1716from coopr.pyomo.base.var import _VarElement
    18 import pyutilib.th
     17import pyutilib.th as unittest
    1918import pyutilib.services
    2019
    21 class PyomoModel(pyutilib.th.TestCase):
     20class PyomoModel(unittest.TestCase):
    2221
    2322    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_modeldata.py

    r2309 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1211import coopr
    1312import pyutilib.common
     13import pyutilib.th as unittest
    1414
    1515currdir=dirname(abspath(__file__))+os.sep
     
    2525
    2626
     27@unittest.skipIf(not _win32com, "Cannot import 'win32com'")
    2728class PyomoTableData(unittest.TestCase):
    28 
    29     def run(self, result=None):
    30         """ Disable the tests if win32com is not available """
    31         if not _win32com:
    32            return
    33         unittest.TestCase.run(self,result)
    3429
    3530    def setUp(self):
     
    4136    def test_read_set(self):
    4237        td = DataManagerFactory('xls')
    43         td.initialize(currdir+"Book1.xls", range="TheRange", format='set', set="X")
     38        td.initialize(currdir+"Book1.xls", range="TheRange", format='set', set="X")
    4439        try:
    4540           td.open()
     
    5247    def test_read_param1(self):
    5348        td = DataManagerFactory('xls')
    54         td.initialize(currdir+"Book1.xls", range="TheRange", index=['aa'], param=['bb','cc','dd'])
     49        td.initialize(currdir+"Book1.xls", range="TheRange", index=['aa'], param=['bb','cc','dd'])
    5550        try:
    5651          td.open()
     
    6358    def test_read_param2(self):
    6459        td = DataManagerFactory('xls')
    65         td.initialize(currdir+"Book1.xls",range="TheRange", index_name="X", index=['aa'], param=['bb','cc','dd'])
     60        td.initialize(currdir+"Book1.xls",range="TheRange", index_name="X", index=['aa'], param=['bb','cc','dd'])
    6661        try:
    6762          td.open()
     
    7469    def test_read_param3(self):
    7570        td = DataManagerFactory('xls')
    76         td.initialize(currdir+"Book1.xls",range="TheRange", index_name="X", index=['aa','bb','cc'], param=["dd"], param_name={'dd':'a'})
     71        td.initialize(currdir+"Book1.xls",range="TheRange", index_name="X", index=['aa','bb','cc'], param=["dd"], param_name={'dd':'a'})
    7772        try:
    7873          td.open()
     
    8580    def test_read_param4(self):
    8681        td = DataManagerFactory('xls')
    87         td.initialize(currdir+"Book1.xls",range="TheRange", index_name="X", index=['aa','bb'], param=['cc','dd'], param_name={'cc':'a', 'dd':'b'})
     82        td.initialize(currdir+"Book1.xls",range="TheRange", index_name="X", index=['aa','bb'], param=['cc','dd'], param_name={'cc':'a', 'dd':'b'})
    8883        try:
    8984          td.open()
     
    9691    def test_read_array1(self):
    9792        td = DataManagerFactory('xls')
    98         td.initialize(currdir+"Book1.xls",range="TheRange", param="X", format="array")
     93        td.initialize(currdir+"Book1.xls",range="TheRange", param="X", format="array")
    9994        try:
    10095          td.open()
     
    107102    def test_read_array2(self):
    108103        td = DataManagerFactory('xls')
    109         td.initialize(currdir+"Book1.xls",range="TheRange",param="X",format="transposed_array")
     104        td.initialize(currdir+"Book1.xls",range="TheRange",param="X",format="transposed_array")
    110105        try:
    111106          td.open()
     
    118113    def test_error1(self):
    119114        td = DataManagerFactory('xls')
    120         td.initialize("bad")
     115        td.initialize("bad")
    121116        try:
    122117            td.open()
     
    136131        td = DataManagerFactory('txt')
    137132        try:
    138             td.initialize(currdir+"display.txt")
     133            td.initialize(currdir+"display.txt")
    139134            td.open()
    140135            self.fail("Expected IOError because of bad file type")
     
    145140        td = DataManagerFactory('txt')
    146141        try:
    147             td.initialize(filename=currdir+"dummy")
     142            td.initialize(filename=currdir+"dummy")
    148143            td.open()
    149144            self.fail("Expected IOError because of bad file type")
     
    153148    def test_error5(self):
    154149        td = DataManagerFactory('tab')
    155         td.initialize(example_dir+"D.tab", param="D", format="foo")
     150        td.initialize(example_dir+"D.tab", param="D", format="foo")
    156151        td.open()
    157152        try:
     
    718713
    719714
     715@unittest.skipIf(not _win32com, "Cannot import 'win32com'")
    720716class TestSpreadsheet(unittest.TestCase):
    721 
    722     def run(self, result=None):
    723         """ Disable the tests if win32com is not available """
    724         if not _win32com:
    725            return
    726         unittest.TestCase.run(self,result)
    727717
    728718    def test_tableA1(self):
     
    740730        """Importing a single column of data"""
    741731        pyutilib.misc.setup_redirect(currdir+'importA2.dat')
    742         print "import "+os.path.abspath(tutorial_dir+'excel.xls')+" range=Atable ;"
     732        print "import "+os.path.abspath(tutorial_dir+'excel.xls')+" range=Atable ;"
    743733        pyutilib.misc.reset_redirect()
    744734        model=Model()
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_obj.py

    r1994 r2422  
    66#
    77
    8 import unittest
    98import os
    109import sys
     
    1716from coopr.opt import *
    1817from coopr.pyomo.base.var import _VarElement
    19 import pyutilib.th
     18import pyutilib.th as unittest
    2019import pyutilib.services
    2120
    22 class PyomoModel(pyutilib.th.TestCase):
     21class PyomoModel(unittest.TestCase):
    2322
    2423    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_preprocess.py

    r2359 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    109currdir = dirname(abspath(__file__))+os.sep
    1110
    12 import pyutilib.th
     11import pyutilib.th as unittest
    1312from coopr.pyomo import *
    1413from nose.tools import nottest
    1514
    1615
    17 class TestPreprocess(pyutilib.th.TestCase):
     16class TestPreprocess(unittest.TestCase):
    1817
    1918    def test_label1(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_transform.py

    r2201 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    1211from coopr.pyomo import *
    1312from coopr.opt import *
    14 import pyutilib.th
     13import pyutilib.th as unittest
    1514import pyutilib.services
    1615from pyutilib.component.core import Plugin
    1716
    18 class Test(pyutilib.th.TestCase):
     17class Test(unittest.TestCase):
    1918
    2019    def setUp(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_util.py

    r1768 r2422  
    33#
    44
    5 import unittest
    65import os
    76import sys
     
    109currdir = dirname(abspath(__file__))+os.sep
    1110
    12 import pyutilib.th
     11import pyutilib.th as unittest
    1312from coopr.pyomo import *
    1413from nose.tools import nottest
     
    1615
    1716
    18 class TestNumericValue(pyutilib.th.TestCase):
     17class TestNumericValue(unittest.TestCase):
    1918
    2019    def test_expr1(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_var.py

    r1994 r2422  
    66#
    77
    8 import unittest
    98import os
    109import sys
     
    1716from coopr.opt import *
    1817from coopr.pyomo.base.var import _VarElement
    19 import pyutilib.th
     18import pyutilib.th as unittest
    2019import pyutilib.services
    2120
    22 class PyomoModel(pyutilib.th.TestCase):
     21class PyomoModel(unittest.TestCase):
    2322
    2423    def setUp(self):
Note: See TracChangeset for help on using the changeset viewer.