source: trunk/test/plugins/mip/test_solver.py @ 1768

Last change on this file since 1768 was 1768, checked in by wehart, 11 years ago

Rework of Coopr to use the new PyUtilib? package decomposition.

NOTE: to use Coopr with this update, we need to work with a new version of coopr_install.

File size: 2.3 KB
Line 
1#
2# Unit Tests for util/misc
3#
4#
5
6import os
7import sys
8from os.path import abspath, dirname
9sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/../..")
10cooprdir = dirname(abspath(__file__))+"/../.."
11currdir = dirname(abspath(__file__))+os.sep
12
13import unittest
14from nose.tools import nottest
15import coopr.plugins.mip
16import coopr.opt
17import coopr
18import pyutilib.services
19import pyutilib.common
20
21
22class TestSolver(coopr.opt.OptSolver):
23
24    def __init__(self, **kwds):
25        kwds['type'] = 'stest_type'
26        coopr.opt.OptSolver.__init__(self,**kwds)
27
28    def enabled(self):
29        return False
30
31   
32class OptSolverDebug(unittest.TestCase):
33
34    def run(self, result=None):
35        self.stest_plugin = coopr.opt.SolverRegistration("stest", TestSolver)
36        unittest.TestCase.run(self,result)
37        self.stest_plugin.deactivate()
38
39    def setUp(self):
40        pyutilib.services.TempfileManager.tempdir = currdir
41
42    def tearDown(self):
43        pyutilib.services.TempfileManager.clear_tempfiles()
44
45
46    def test_solver_init1(self):
47        """
48        Verify the processing of 'type', 'name' and 'doc' options
49        """
50        ans = coopr.opt.SolverFactory("_mock_pico")
51        self.failUnlessEqual(type(ans), coopr.plugins.mip.MockPICO)
52        self.failUnlessEqual(ans._doc, "pico OptSolver")
53
54        ans = coopr.opt.SolverFactory("_mock_pico", doc="My Doc")
55        self.failUnlessEqual(type(ans), coopr.plugins.mip.MockPICO)
56        self.failUnlessEqual(ans._doc, "My Doc")
57
58        ans = coopr.opt.SolverFactory("_mock_pico", name="my name")
59        self.failUnlessEqual(type(ans), coopr.plugins.mip.MockPICO)
60        self.failUnlessEqual(ans._doc, "my name OptSolver (type pico)")
61
62    def test_solver_init2(self):
63        """
64        Verify that options can be passed in.
65        """
66        opt = {}
67        opt['a'] = 1
68        opt['b'] = "two"
69        ans = coopr.opt.SolverFactory("_mock_pico", name="solver_init2", options=opt)
70        self.failUnlessEqual(ans.options['a'], opt['a'])
71        self.failUnlessEqual(ans.options['b'], opt['b'])
72
73    def test_avail(self):
74        ans = coopr.opt.SolverFactory("stest")
75        try:
76            ans.available()
77            self.fail("Expected exception for 'stest' solver, which is disabled")
78        except pyutilib.common.ApplicationError:
79            pass
80
81
82
83if __name__ == "__main__":
84   unittest.main()
85
Note: See TracBrowser for help on using the repository browser.