source: trunk/test/core/base/test_solver.py @ 1657

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

Removing coopr.opt-depricated, and
renaming coopr.core to coopr.opt.

Unfortunately, plugins are still not being properly loaded, so
some of the tests are failing.

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.opt
16import coopr
17import pyutilib
18
19
20class TestSolver(coopr.opt.OptSolver):
21
22    def __init__(self, **kwds):
23        kwds['type'] = 'stest_type'
24        kwds['doc'] = 'TestSolver Documentation'
25        coopr.opt.OptSolver.__init__(self,**kwds)
26
27    def enabled(self):
28        return False
29
30   
31class OptSolverDebug(unittest.TestCase):
32
33    def run(self, result=None):
34        self.stest_plugin = coopr.opt.SolverRegistration("stest", TestSolver)
35        unittest.TestCase.run(self,result)
36        self.stest_plugin.deactivate()
37
38    def setUp(self):
39        pyutilib.TempfileManager.tempdir = currdir
40
41    def tearDown(self):
42        pyutilib.TempfileManager.clear_tempfiles()
43
44
45    def test_solver_init1(self):
46        """
47        Verify the processing of 'type', 'name' and 'doc' options
48        """
49        ans = coopr.opt.SolverFactory("stest")
50        self.failUnlessEqual(type(ans), TestSolver)
51        self.failUnlessEqual(ans._doc, "TestSolver Documentation")
52
53        ans = coopr.opt.SolverFactory("stest", doc="My Doc")
54        self.failUnlessEqual(type(ans), TestSolver)
55        self.failUnlessEqual(ans._doc, "TestSolver Documentation")
56
57        ans = coopr.opt.SolverFactory("stest", name="my name")
58        self.failUnlessEqual(type(ans), TestSolver)
59        self.failUnlessEqual(ans._doc, "TestSolver Documentation")
60
61    def test_solver_init2(self):
62        """
63        Verify that options can be passed in.
64        """
65        opt = {}
66        opt['a'] = 1
67        opt['b'] = "two"
68        ans = coopr.opt.SolverFactory("stest", name="solver_init2", options=opt)
69        self.failUnlessEqual(ans.options['a'], opt['a'])
70        self.failUnlessEqual(ans.options['b'], opt['b'])
71
72    def test_avail(self):
73        ans = coopr.opt.SolverFactory("stest")
74        try:
75            ans.available()
76            self.fail("Expected exception for 'stest' solver, which is disabled")
77        except pyutilib.ApplicationError:
78            pass
79
80
81
82if __name__ == "__main__":
83   unittest.main()
84
Note: See TracBrowser for help on using the repository browser.