@@ -188,6 +188,10 @@ def testConfigSave(self):
188188 config .save () # creates .bak file
189189 self .assertTrue (os .access ("config.ini" , os .F_OK ))
190190 self .assertTrue (os .access ("config.bak" , os .F_OK ))
191+ config .save () # trigger delete of old .bak file
192+ # FIXME: this should test to see if a new .bak
193+ # was created. For now verify .bak still exists
194+ self .assertTrue (os .access ("config.bak" , os .F_OK ))
191195
192196 self .assertFalse (os .access ("foo.bar" , os .F_OK ))
193197 self .assertFalse (os .access ("foo.bak" , os .F_OK ))
@@ -243,6 +247,59 @@ def testFloatAndInt_with_update_option(self):
243247 self .assertAlmostEqual (config ['WEB_LOGIN_ATTEMPTS_MIN' ], 3.1415926 ,
244248 places = 6 )
245249
250+ # test removal of .0 on floats that are integers
251+ self .assertEqual (None ,
252+ config ._get_option ('WEB_LOGIN_ATTEMPTS_MIN' ).set ("3.0" ))
253+
254+ self .assertEqual ("3" ,
255+ config ._get_option ('WEB_LOGIN_ATTEMPTS_MIN' )._value2str (3.00 ))
256+
257+
258+ def testOptionAsString (self ):
259+
260+ config = configuration .CoreConfig ()
261+
262+ config ._get_option ('WEB_LOGIN_ATTEMPTS_MIN' ).set ("2552" )
263+
264+ v = config ._get_option ('WEB_LOGIN_ATTEMPTS_MIN' ).__str__ ()
265+ print (v )
266+ self .assertIn ("55" , v )
267+
268+ v = config ._get_option ('WEB_LOGIN_ATTEMPTS_MIN' ).__repr__ ()
269+ print (v )
270+ self .assertIn ("55" , v )
271+
272+ def testBooleanOption (self ):
273+
274+ config = configuration .CoreConfig ()
275+
276+ with self .assertRaises (configuration .OptionValueError ) as cm :
277+ config ._get_option ('INSTANT_REGISTRATION' ).set ("3" )
278+
279+ # test multiple boolean representations
280+ for b in [ "yes" , "1" , "true" , "TRUE" , "tRue" , "on" ,
281+ "oN" , 1 , True ]:
282+ self .assertEqual (None ,
283+ config ._get_option ('INSTANT_REGISTRATION' ).set (b ))
284+ self .assertEqual (1 ,
285+ config ._get_option ('INSTANT_REGISTRATION' ).get ())
286+
287+ for b in ["no" , "0" , "false" , "FALSE" , "fAlse" , "off" ,
288+ "oFf" , 0 , False ]:
289+ self .assertEqual (None ,
290+ config ._get_option ('INSTANT_REGISTRATION' ).set (b ))
291+ self .assertEqual (0 ,
292+ config ._get_option ('INSTANT_REGISTRATION' ).get ())
293+
294+ def testOctalNumberOption (self ):
295+
296+ config = configuration .CoreConfig ()
297+
298+ with self .assertRaises (configuration .OptionValueError ) as cm :
299+ config ._get_option ('UMASK' ).set ("xyzzy" )
300+
301+ print (type (config ._get_option ('UMASK' )))
302+
246303
247304class TrackerConfig (unittest .TestCase ):
248305
@@ -309,8 +366,11 @@ def testNoDBInConfig(self):
309366 self .munge_configini (mods = [ ("backend = " , None ) ])
310367
311368 # this should fail as backend isn't defined.
312- self .assertRaises (configuration .OptionUnsetError , instance .open ,
313- self .dirname )
369+ with self .assertRaises (configuration .OptionUnsetError ) as cm :
370+ instance .open (self .dirname )
371+
372+ self .assertEqual ("RDBMS_BACKEND is not set"
373+ " and has no default" , cm .exception .__str__ ())
314374
315375 def testInvalidIndexerLanguage_w_empty (self ):
316376 """ make sure we have a reasonable error message if
@@ -323,19 +383,17 @@ def testInvalidIndexerLanguage_w_empty(self):
323383 ("indexer_language = " , "NO_LANG" ) ])
324384
325385 config = configuration .CoreConfig ()
326-
327- # Note this should raise OptionValueError, but
328- # the test fot this error occurs too late to have
329- # a valid option still available. So raise ValueError.
330- with self .assertRaises (ValueError ) as cm :
386+
387+ with self .assertRaises (configuration .OptionValueError ) as cm :
331388 config .load (self .dirname )
332389
333390 print (cm .exception )
334- self .assertIn ("ValueError" , repr (cm .exception ))
391+ # test repr. The type is right since it passed assertRaises.
392+ self .assertIn ("OptionValueError" , repr (cm .exception ))
335393 # look for failing language
336- self .assertIn ("NO_LANG" , cm .exception .args [0 ])
394+ self .assertIn ("NO_LANG" , cm .exception .args [1 ])
337395 # look for supported language
338- self .assertIn ("english" , cm .exception .args [0 ])
396+ self .assertIn ("english" , cm .exception .args [2 ])
339397
340398 def testInvalidIndexerLanguage_xapian_missing (self ):
341399 """Using default path for indexers, make import of xapian
@@ -390,7 +448,7 @@ def testInvalidIndexerLanguage_w_xapian(self):
390448 self .munge_configini (mods = [ ("indexer = " , "xapian" ),
391449 ("indexer_language = " , "NO_LANG" ) ])
392450
393- with self .assertRaises (ValueError ) as cm :
451+ with self .assertRaises (configuration . OptionValueError ) as cm :
394452 config .load (self .dirname )
395453 # don't test exception content. Done in
396454 # testInvalidIndexerLanguage_w_empty
@@ -437,6 +495,27 @@ def testLoadConfigNoConfig(self):
437495 print (cm .exception )
438496 self .assertEqual (cm .exception .args [0 ], self .dirname )
439497
498+ def testCopyConfig (self ):
499+
500+ self .munge_configini (mods = [ ("html_version = " , "xhtml" ) ])
501+
502+ config = configuration .CoreConfig ()
503+
504+ # verify config is initalized to defaults
505+ self .assertEqual (config ['HTML_VERSION' ], 'html4' )
506+
507+ # load config
508+ config .load (self .dirname )
509+
510+ # loaded new option
511+ self .assertEqual (config ['HTML_VERSION' ], 'xhtml' )
512+
513+ # copy config
514+ config_copy = config .copy ()
515+
516+ # this should work
517+ self .assertEqual (config_copy ['HTML_VERSION' ], 'xhtml' )
518+
440519 def testInvalidIndexerValue (self ):
441520 """ Mistype native indexer. Verify exception is
442521 generated.
@@ -453,5 +532,12 @@ def testInvalidIndexerValue(self):
453532 # look for failing value
454533 self .assertEqual ("nati" , cm .exception .args [1 ])
455534 # look for supported values
456- self .assertIn ("whoosh" , cm .exception .args [2 ])
535+ self .assertIn ("'whoosh'" , cm .exception .args [2 ])
536+
537+ # verify that args show up in string representaton
538+ string_rep = cm .exception .__str__ ()
539+ print (string_rep )
540+ self .assertIn ("nati" , string_rep )
541+ self .assertIn ("'whoosh'" , string_rep )
542+
457543
0 commit comments