From 3ada0ff89c00054a7966d071de235bae6defe460 Mon Sep 17 00:00:00 2001 From: hsoft Date: Thu, 18 Jun 2009 18:13:45 +0000 Subject: [PATCH] [#38 state:fixed] Removed those LookupErrors. They were useless anyway. --HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%4071 --- py/directories.py | 23 ++++++++--------------- py/tests/directories_test.py | 3 ++- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/py/directories.py b/py/directories.py index 17342c02..7aa04c42 100644 --- a/py/directories.py +++ b/py/directories.py @@ -107,11 +107,7 @@ class Directories(object): def GetState(self, path): """Returns the state of 'path' (One of the STATE_* const.) - - Raises LookupError if 'path' is not in self. """ - if path not in self: - raise LookupError("The path '%s' is not in the directory list." % str(path)) try: return self.states[path] except KeyError: @@ -163,16 +159,13 @@ class Directories(object): doc.writexml(fp,'\t','\t','\n',encoding='utf-8') def SetState(self,path,state): - try: - if self.GetState(path) == state: + if self.GetState(path) == state: + return + # we don't want to needlessly fill self.states. if GetState returns the same thing + # without an explicit entry, remove that entry + if path in self.states: + del self.states[path] + if self.GetState(path) == state: # no need for an entry return - # we don't want to needlessly fill self.states. if GetState returns the same thing - # without an explicit entry, remove that entry - if path in self.states: - del self.states[path] - if self.GetState(path) == state: # no need for an entry - return - self.states[path] = state - except LookupError: - pass + self.states[path] = state diff --git a/py/tests/directories_test.py b/py/tests/directories_test.py index 40247218..80120295 100644 --- a/py/tests/directories_test.py +++ b/py/tests/directories_test.py @@ -93,9 +93,10 @@ class TCDirectories(TestCase): self.assertEqual(STATE_REFERENCE,d.states[p]) def test_GetState_with_path_not_there(self): + # When the path's not there, just return STATE_NORMAL d = Directories() d.add_path(testpath + 'utils') - self.assertRaises(LookupError,d.GetState,testpath) + eq_(d.GetState(testpath), STATE_NORMAL) def test_states_remain_when_larger_directory_eat_smaller_ones(self): d = Directories()