Skip to content

Commit 77e58ca

Browse files
author
Richard Jones
committed
Unit tests and a few fixes.
1 parent 8ac2971 commit 77e58ca

File tree

6 files changed

+103
-62
lines changed

6 files changed

+103
-62
lines changed

TODO.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ pending hyperdb: range searching of values (dates in particular)
1010
- filter specifies {property: (comparison function, value)}
1111
comparison functions: lt, le, eq, ge, gt. eq and
1212
[value, value, ...] implies "in"
13-
active hyperdb: add tests for Number and Boolean
14-
- htmltemplate
15-
- schema
16-
- db
1713
pending hyperdb: make creator, creation and activity available pre-commit
1814
pending instance: including much simpler upgrade path and the use of
1915
non-Python configuration files (ConfigParser)

roundup/backends/back_anydbm.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.50 2002-07-18 11:50:58 richard Exp $
18+
#$Id: back_anydbm.py,v 1.51 2002-07-18 23:07:08 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -732,27 +732,15 @@ def create(self, **propvalues):
732732

733733
elif value is not None and isinstance(prop, Number):
734734
try:
735-
int(value)
735+
float(value)
736736
except ValueError:
737-
try:
738-
float(value)
739-
except ValueError:
740-
raise TypeError, 'new property "%s" not numeric'%key
737+
raise TypeError, 'new property "%s" not numeric'%key
741738

742739
elif value is not None and isinstance(prop, Boolean):
743-
if isinstance(value, type('')):
744-
s = value.lower()
745-
if s in ('0', 'false', 'no'):
746-
value = 0
747-
elif s in ('1', 'true', 'yes'):
748-
value = 1
749-
else:
750-
raise TypeError, 'new property "%s" not boolean'%key
751-
else:
752-
try:
753-
int(value)
754-
except TypeError:
755-
raise TypeError, 'new property "%s" not boolean'%key
740+
try:
741+
int(value)
742+
except ValueError:
743+
raise TypeError, 'new property "%s" not boolean'%key
756744

757745
# make sure there's data where there needs to be
758746
for key, prop in self.properties.items():
@@ -1037,30 +1025,15 @@ class or a KeyError is raised.
10371025

10381026
elif value is not None and isinstance(prop, Number):
10391027
try:
1040-
int(value)
1028+
float(value)
10411029
except ValueError:
1042-
try:
1043-
float(value)
1044-
except ValueError:
1045-
raise TypeError, 'new property "%s" not '\
1046-
'numeric'%propname
1030+
raise TypeError, 'new property "%s" not numeric'%propname
10471031

10481032
elif value is not None and isinstance(prop, Boolean):
1049-
if isinstance(value, type('')):
1050-
s = value.lower()
1051-
if s in ('0', 'false', 'no'):
1052-
value = 0
1053-
elif s in ('1', 'true', 'yes'):
1054-
value = 1
1055-
else:
1056-
raise TypeError, 'new property "%s" not '\
1057-
'boolean'%propname
1058-
else:
1059-
try:
1060-
int(value)
1061-
except ValueError:
1062-
raise TypeError, 'new property "%s" not '\
1063-
'boolean'%propname
1033+
try:
1034+
int(value)
1035+
except ValueError:
1036+
raise TypeError, 'new property "%s" not boolean'%propname
10641037

10651038
node[propname] = value
10661039

@@ -1703,6 +1676,9 @@ def __init__(self, db, classname, **properties):
17031676

17041677
#
17051678
#$Log: not supported by cvs2svn $
1679+
#Revision 1.50 2002/07/18 11:50:58 richard
1680+
#added tests for number type too
1681+
#
17061682
#Revision 1.49 2002/07/18 11:41:10 richard
17071683
#added tests for boolean type, and fixes to anydbm backend
17081684
#

roundup/date.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.22 2002-07-14 06:05:50 richard Exp $
18+
# $Id: date.py,v 1.23 2002-07-18 23:07:08 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -190,6 +190,8 @@ def __cmp__(self, other):
190190
if other is None:
191191
return 1
192192
for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
193+
if not hasattr(other, attr):
194+
return 1
193195
r = cmp(getattr(self, attr), getattr(other, attr))
194196
if r: return r
195197
return 0
@@ -304,6 +306,8 @@ def __cmp__(self, other):
304306
if other is None:
305307
return 1
306308
for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
309+
if not hasattr(other, attr):
310+
return 1
307311
r = cmp(getattr(self, attr), getattr(other, attr))
308312
if r: return r
309313
return 0
@@ -438,6 +442,9 @@ def test():
438442

439443
#
440444
# $Log: not supported by cvs2svn $
445+
# Revision 1.22 2002/07/14 06:05:50 richard
446+
# . fixed the date module so that Date(". - 2d") works
447+
#
441448
# Revision 1.21 2002/05/15 06:32:46 richard
442449
# . reverting to dates for intervals > 2 months sucks
443450
#

roundup/htmltemplate.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: htmltemplate.py,v 1.101 2002-07-18 11:17:30 gmcm Exp $
18+
# $Id: htmltemplate.py,v 1.102 2002-07-18 23:07:08 richard Exp $
1919

2020
__doc__ = """
2121
Template engine.
@@ -386,11 +386,13 @@ def do_link(self, property=None, is_download=0, showid=0):
386386

387387
# get the value
388388
value = self.determine_value(property)
389-
if not value:
389+
if value in ('', None, []):
390390
return _('[no %(propname)s]')%{'propname':property.capitalize()}
391391

392392
propclass = self.properties[property]
393-
if isinstance(propclass, hyperdb.Link):
393+
if isinstance(propclass, hyperdb.Boolean):
394+
value = value and "Yes" or "No"
395+
elif isinstance(propclass, hyperdb.Link):
394396
linkname = propclass.classname
395397
linkcl = self.db.classes[linkname]
396398
k = linkcl.labelprop(1)
@@ -407,7 +409,7 @@ def do_link(self, property=None, is_download=0, showid=0):
407409
linkvalue, title, label)
408410
else:
409411
return '<a href="%s%s"%s>%s</a>'%(linkname, value, title, label)
410-
if isinstance(propclass, hyperdb.Multilink):
412+
elif isinstance(propclass, hyperdb.Multilink):
411413
linkname = propclass.classname
412414
linkcl = self.db.classes[linkname]
413415
k = linkcl.labelprop(1)
@@ -1362,6 +1364,11 @@ def render(self, form):
13621364

13631365
#
13641366
# $Log: not supported by cvs2svn $
1367+
# Revision 1.101 2002/07/18 11:17:30 gmcm
1368+
# Add Number and Boolean types to hyperdb.
1369+
# Add conversion cases to web, mail & admin interfaces.
1370+
# Add storage/serialization cases to back_anydbm & back_metakit.
1371+
#
13651372
# Revision 1.100 2002/07/18 07:01:54 richard
13661373
# minor bugfix
13671374
#

test/test_db.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.34 2002-07-18 11:52:00 richard Exp $
18+
# $Id: test_db.py,v 1.35 2002-07-18 23:07:08 richard Exp $
1919

2020
import unittest, os, shutil, time
2121

@@ -112,14 +112,11 @@ def testIntervalChange(self):
112112

113113
def testBooleanChange(self):
114114
self.db.user.create(username='foo', assignable=1)
115+
self.db.user.create(username='foo', assignable=0)
115116
a = self.db.user.get('1', 'assignable')
116-
self.db.user.set('1', assignable='false')
117+
self.db.user.set('1', assignable=0)
117118
self.assertNotEqual(self.db.user.get('1', 'assignable'), a)
118-
self.db.user.set('1', assignable='FaLse')
119-
self.db.user.set('1', assignable='nO')
120119
self.db.user.set('1', assignable=0)
121-
self.db.user.set('1', assignable='tRuE')
122-
self.db.user.set('1', assignable='yEs')
123120
self.db.user.set('1', assignable=1)
124121

125122
def testNumberChange(self):
@@ -265,12 +262,12 @@ def testExceptions(self):
265262
# invalid number value
266263
ar(TypeError, self.db.user.create, username='foo', age='a')
267264
# invalid boolean value
268-
ar(TypeError, self.db.user.create, username='foo', assignable='fubar')
265+
ar(TypeError, self.db.user.create, username='foo', assignable='true')
269266
self.db.user.create(username='foo')
270267
# invalid number value
271268
ar(TypeError, self.db.user.set, '3', username='foo', age='a')
272269
# invalid boolean value
273-
ar(TypeError, self.db.user.set, '3', username='foo', assignable='fubar')
270+
ar(TypeError, self.db.user.set, '3', username='foo', assignable='true')
274271

275272
def testJournals(self):
276273
self.db.issue.addprop(fixer=Link("user", do_journal='yes'))
@@ -562,6 +559,9 @@ def suite():
562559

563560
#
564561
# $Log: not supported by cvs2svn $
562+
# Revision 1.34 2002/07/18 11:52:00 richard
563+
# oops
564+
#
565565
# Revision 1.33 2002/07/18 11:50:58 richard
566566
# added tests for number type too
567567
#

0 commit comments

Comments
 (0)