summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1a003d2)
raw | patch | inline | side by side (parent: 1a003d2)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Thu, 18 Jul 2002 11:50:58 +0000 (11:50 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Thu, 18 Jul 2002 11:50:58 +0000 (11:50 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@899 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/backends/back_anydbm.py | patch | blob | history | |
test/test_db.py | patch | blob | history |
index 84474ccfa422420982e7bab6156e493e0ef14fca..fa550fdc84b5dd9a3c6f1b0db62a1378c775d8bd 100644 (file)
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-#$Id: back_anydbm.py,v 1.49 2002-07-18 11:41:10 richard Exp $
+#$Id: back_anydbm.py,v 1.50 2002-07-18 11:50:58 richard Exp $
'''
This module defines a backend that saves the hyperdatabase in a database
chosen by anydbm. It is guaranteed to always be available in python
if value is not None and not isinstance(value, date.Interval):
raise TypeError, 'new property "%s" not an Interval'%key
- elif isinstance(prop, Number):
+ elif value is not None and isinstance(prop, Number):
try:
int(value)
- except TypeError:
- raise TypeError, 'new property "%s" not numeric' % propname
+ except ValueError:
+ try:
+ float(value)
+ except ValueError:
+ raise TypeError, 'new property "%s" not numeric'%key
- elif isinstance(prop, Boolean):
- try:
- int(value)
- except TypeError:
- raise TypeError, 'new property "%s" is not boolean' % propname
+ elif value is not None and isinstance(prop, Boolean):
+ if isinstance(value, type('')):
+ s = value.lower()
+ if s in ('0', 'false', 'no'):
+ value = 0
+ elif s in ('1', 'true', 'yes'):
+ value = 1
+ else:
+ raise TypeError, 'new property "%s" not boolean'%key
+ else:
+ try:
+ int(value)
+ except TypeError:
+ raise TypeError, 'new property "%s" not boolean'%key
# make sure there's data where there needs to be
for key, prop in self.properties.items():
propvalues[propname] = value
elif value is not None and isinstance(prop, Number):
- # TODO: should we store floats too?
try:
int(value)
- except TypeError:
- raise TypeError, 'new property "%s" not numeric' % propname
+ except ValueError:
+ try:
+ float(value)
+ except ValueError:
+ raise TypeError, 'new property "%s" not '\
+ 'numeric'%propname
elif value is not None and isinstance(prop, Boolean):
if isinstance(value, type('')):
else:
try:
int(value)
- except TypeError:
+ except ValueError:
raise TypeError, 'new property "%s" not '\
'boolean'%propname
#
#$Log: not supported by cvs2svn $
+#Revision 1.49 2002/07/18 11:41:10 richard
+#added tests for boolean type, and fixes to anydbm backend
+#
#Revision 1.48 2002/07/18 11:17:31 gmcm
#Add Number and Boolean types to hyperdb.
#Add conversion cases to web, mail & admin interfaces.
diff --git a/test/test_db.py b/test/test_db.py
index c6b4468ee94bc51f38bffd12895ce390d40d49b3..7863bc695f3e3f24daf6413196793e6187b56d08 100644 (file)
--- a/test/test_db.py
+++ b/test/test_db.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: test_db.py,v 1.32 2002-07-18 11:41:10 richard Exp $
+# $Id: test_db.py,v 1.33 2002-07-18 11:50:58 richard Exp $
import unittest, os, shutil, time
self.assertNotEqual(self.db.issue.get('1', "foo"), a)
def testBooleanChange(self):
- self.db.user.create(username='foo', assignable='1')
+ self.db.user.create(username='foo', assignable=1)
a = self.db.user.get('1', 'assignable')
self.db.user.set('1', assignable='false')
self.assertNotEqual(self.db.user.get('1', 'assignable'), a)
self.db.user.set('1', assignable='FaLse')
self.db.user.set('1', assignable='nO')
- self.db.user.set('1', assignable='0')
+ self.db.user.set('1', assignable=0)
self.db.user.set('1', assignable='tRuE')
self.db.user.set('1', assignable='yEs')
- self.db.user.set('1', assignable='1')
+ self.db.user.set('1', assignable=1)
+
+ def testNumberChange(self):
+ self.db.user.create(username='foo', age='1')
+ a = self.db.user.get('1', 'age')
+ self.db.user.set('1', age='3')
+ self.assertNotEqual(self.db.user.get('1', 'age'), a)
+ self.db.user.set('1', age='1.0')
def xtestNewProperty(self):
' make sure a new property is added ok '
self.assertNotEqual(num_files, self.db.numfiles())
self.assertEqual(num_files2, self.db.numfiles())
- def xtestExceptions(self):
+ def testExceptions(self):
# this tests the exceptions that should be raised
ar = self.assertRaises
# invalid multilink index
ar(IndexError, self.db.issue.set, '6', title='foo', status='1',
nosy=['10'])
+ # invalid number value
+ ar(TypeError, self.db.user.create, username='foo', age='a')
+ # invalid boolean value
+ ar(TypeError, self.db.user.create, username='foo', assignable='fubar')
+ self.db.user.create(username='foo')
+ # invalid number value
+ ar(TypeError, self.db.user.set, '3', username='foo', age='a')
+ # invalid boolean value
+ ar(TypeError, self.db.user.set, '3', username='foo', assignable='fubar')
def xtestJournals(self):
self.db.issue.addprop(fixer=Link("user", do_journal='yes'))
#
# $Log: not supported by cvs2svn $
+# Revision 1.32 2002/07/18 11:41:10 richard
+# added tests for boolean type, and fixes to anydbm backend
+#
# Revision 1.31 2002/07/14 23:17:45 richard
# minor change to make testing easier
#