Mercurial > hg > configuration
diff tests/unit.py @ 115:56db0b2b90af
fix casting
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 04 Jul 2012 09:54:37 -0700 (2012-07-04) |
parents | a2184db43fe2 |
children | 9d19ed8fd883 |
line wrap: on
line diff
--- a/tests/unit.py Thu Jun 28 14:54:29 2012 -0700 +++ b/tests/unit.py Wed Jul 04 09:54:37 2012 -0700 @@ -5,6 +5,7 @@ """ import configuration +import datetime import os import sys import tempfile @@ -184,5 +185,23 @@ self.assertEqual(example.config['preferences'], default_prefs) os.remove(tf) + def test_typecast(self): + """casting example""" + + def todate(string): + return datetime.datetime.strptime(string, "%Y%m%d") + + # make an example class + class TypecastExample(configuration.Configuration): + options = {'datestring': {'type': todate}} + example = TypecastExample() + + # parse a date string + example({'datestring': "20120704"}) + + # ensure it works correctly + expected = datetime.datetime(2012, 7, 4, 0, 0) + self.assertEqual(example.config['datestring'], expected) + if __name__ == '__main__': unittest.main()