Skip to content

Commit c6137c3

Browse files
committed
Test case where backend is missing from config.ini.
1 parent 2ab6f76 commit c6137c3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/test_config.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
config.init_logging()
4242
config.options['FOO'] = "value"
4343

44+
# for TrackerConfig test class
45+
from roundup import instance
46+
from . import db_test_base
47+
4448
class ConfigTest(unittest.TestCase):
4549

4650
def test_badConfigKeyword(self):
@@ -237,3 +241,46 @@ def testFloatAndInt_with_update_option(self):
237241

238242
self.assertAlmostEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], 3.1415926,
239243
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

Comments
 (0)