|
41 | 41 | config.init_logging() |
42 | 42 | config.options['FOO'] = "value" |
43 | 43 |
|
| 44 | +# for TrackerConfig test class |
| 45 | +from roundup import instance |
| 46 | +from . import db_test_base |
| 47 | + |
44 | 48 | class ConfigTest(unittest.TestCase): |
45 | 49 |
|
46 | 50 | def test_badConfigKeyword(self): |
@@ -237,3 +241,46 @@ def testFloatAndInt_with_update_option(self): |
237 | 241 |
|
238 | 242 | self.assertAlmostEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], 3.1415926, |
239 | 243 | places=6) |
| 244 | + |
| 245 | + |
| 246 | +class TrackerConfig(unittest.TestCase): |
| 247 | + """ Arguably this should be tested in test_instance since it is triggered |
| 248 | + by instance.open. But it raises an error in the configuration module |
| 249 | + with a missing required param in config.ini.""" |
| 250 | + |
| 251 | + backend = 'anydbm' |
| 252 | + |
| 253 | + def setUp(self): |
| 254 | + self.dirname = '_test_instance' |
| 255 | + # set up and open a tracker |
| 256 | + self.instance = db_test_base.setupTracker(self.dirname, self.backend) |
| 257 | + |
| 258 | + # open the database |
| 259 | + self.db = self.instance.open('admin') |
| 260 | + |
| 261 | + self.db.commit() |
| 262 | + self.db.close() |
| 263 | + |
| 264 | + def tearDown(self): |
| 265 | + if self.db: |
| 266 | + self.db.close() |
| 267 | + try: |
| 268 | + shutil.rmtree(self.dirname) |
| 269 | + except OSError as error: |
| 270 | + if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 271 | + |
| 272 | + |
| 273 | + def testNoDBInConfig(self): |
| 274 | + # comment out the backend key in config.ini |
| 275 | + import fileinput |
| 276 | + for line in fileinput.input(os.path.join(self.dirname, "config.ini"), |
| 277 | + inplace=True): |
| 278 | + if line.startswith("backend = "): |
| 279 | + continue |
| 280 | + print(line) |
| 281 | + |
| 282 | + # this should fail as backend isn't defined. |
| 283 | + self.assertRaises(configuration.OptionUnsetError, instance.open, |
| 284 | + self.dirname) |
| 285 | + |
| 286 | + |
0 commit comments