added __str__

This commit is contained in:
Thom Nichols 2010-06-07 13:58:15 -04:00
parent 47f1fb1690
commit 9464736551
2 changed files with 9 additions and 2 deletions

View File

@ -164,6 +164,10 @@ class StateMachine(object):
''' '''
return self.__current_state == state return self.__current_state == state
def __str__(self):
return "".join(( "StateMachine(", ','.join(self.__states), "): ", self.__current_state ))
class _StateCtx: class _StateCtx:

View File

@ -20,10 +20,13 @@ class testStateMachine(unittest.TestCase):
# self.failIf(s.two) # self.failIf(s.two)
self.failIf(s['two']) self.failIf(s['two'])
try: try:
s.booga s['booga']
self.fail('s.booga is an invalid state and should throw an exception!') self.fail('s.booga is an invalid state and should throw an exception!')
except: pass #expected exception except: pass #expected exception
# just make sure __str__ works, no reason to test its exact value:
print str(s)
def testTransitions(self): def testTransitions(self):
"Test ensure transitions occur correctly in a single thread" "Test ensure transitions occur correctly in a single thread"