From ababf3e09acdba33da699f6556c8a3fcd5f5332c Mon Sep 17 00:00:00 2001 From: jlgijsbers Date: Sun, 16 Nov 2003 22:56:46 +0000 Subject: [PATCH] - Add docstring to safeget method. - Remove handling of invalid propname (YAGNI). git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1998 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/hyperdb.py | 8 ++++++-- test/db_test_base.py | 6 +----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py index 6cb47d9..c8ca0a5 100644 --- a/roundup/hyperdb.py +++ b/roundup/hyperdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: hyperdb.py,v 1.94 2003-11-16 20:01:16 jlgijsbers Exp $ +# $Id: hyperdb.py,v 1.95 2003-11-16 22:56:46 jlgijsbers Exp $ """ Hyperdatabase implementation, especially field types. @@ -573,9 +573,13 @@ class Class: raise NotImplementedError def safeget(self, nodeid, propname, default=None): + """Safely get the value of a property on an existing node of this class. + + Return 'default' if the node doesn't exist. + """ try: return self.get(nodeid, propname) - except (KeyError, IndexError): + except IndexError: return default class HyperdbValueError(ValueError): diff --git a/test/db_test_base.py b/test/db_test_base.py index 2435134..d7b65be 100644 --- a/test/db_test_base.py +++ b/test/db_test_base.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: db_test_base.py,v 1.9 2003-11-16 19:59:06 jlgijsbers Exp $ +# $Id: db_test_base.py,v 1.10 2003-11-16 22:56:46 jlgijsbers Exp $ import unittest, os, shutil, errno, imp, sys, time, pprint @@ -801,12 +801,8 @@ class DBTest(MyTestCase): def testSafeGet(self): # existent nodeid, existent property self.assertEqual(self.db.user.safeget('1', 'username'), 'admin') - # existent nodeid, nonexistent property - self.assertEqual(self.db.user.safeget('1', 'nonexistent'), None) # nonexistent nodeid, existent property self.assertEqual(self.db.user.safeget('999', 'username'), None) - # nonexistent nodeid, nonexistent property - self.assertEqual(self.db.user.safeget('999', 'nonexistent'), None) # different default self.assertEqual(self.db.issue.safeget('999', 'nosy', []), []) -- 2.30.2