summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Kulisz <marcin@bashton.com>2014-06-19 08:11:09 +0100
committerMarcin Kulisz <marcin@bashton.com>2014-06-19 08:11:09 +0100
commite51f8f21b6533a4c10eb741fc7f8dcf9e525643a (patch)
tree5342fc7a5cd9154977d88316c1537528cf9fcbd5
parentea5f5aad1522e3b6d455ac858868621994fbc83a (diff)
parent225fa0dda5c112596694108531281854259cd577 (diff)
Merge tag 'upstream/1.0.19'
Upstream version 1.0.19
-rw-r--r--CHANGELOG5
-rw-r--r--PKG-INFO2
-rw-r--r--README5
-rw-r--r--fysom/__init__.py6
-rw-r--r--setup.cfg3
-rwxr-xr-xsetup.py2
-rw-r--r--test/test_state.py21
7 files changed, 36 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e235f37..649ef92 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,10 @@
Changelog for fysom
--------------------
+
+* v1.0.19
+ The `trigger` method now accepts any positional arguments and keyword arguments, and passes them to the underlying event method. Pull request by
+ [@poundifdef](https://github.com/poundifdef).
+
* v1.0.18
From now on, a changelog will be included. Furthermore, all PyPI releases will be GPG signed.
diff --git a/PKG-INFO b/PKG-INFO
index beb5f70..5b2aacd 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: fysom
-Version: 1.0.18
+Version: 1.0.19
Summary: pYthOn Finite State Machine
Home-page: https://github.com/mriehl/fysom
Author: Mansour Behabadi, Jake Gordon, Maximilien Riehl, Stefano
diff --git a/README b/README
index 4a1fe6b..ed65737 100644
--- a/README
+++ b/README
@@ -185,7 +185,8 @@ Dynamically generated event names
Sometimes you have to compute the name of an event you want to trigger on the
fly. Instead of relying on `getattr` you can use the `trigger` method, which takes
-a string (the event name) as a parameter.
+a string (the event name) as a parameter, followed by any arguments/keyword
+arguments you want to pass to the event method.
This is also arguably better if you're not sure if the event exists at all
(FysomError vs. AttributeError, see below).
@@ -200,7 +201,7 @@ This is also arguably better if you're not sure if the event exists at all
{'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'} ] })
- fsm.trigger('warn') # equivalent to fsm.warn()
+ fsm.trigger('warn', msg="danger") # equivalent to fsm.warn(msg="danger")
fsm.trigger('unknown') # FysomError, event does not exist
fsm.unknown() # AttributeError, event does not exist
diff --git a/fysom/__init__.py b/fysom/__init__.py
index 91a9f0d..d43b6d9 100644
--- a/fysom/__init__.py
+++ b/fysom/__init__.py
@@ -31,7 +31,7 @@ __author__ = 'Mansour Behabadi'
__copyright__ = 'Copyright 2011, Mansour Behabadi and Jake Gordon'
__credits__ = ['Mansour Behabadi', 'Jake Gordon']
__license__ = 'MIT'
-__version__ = '1.0.18'
+__version__ = '1.0.19'
__maintainer__ = 'Mansour Behabadi'
__email__ = 'mansour@oxplot.com'
@@ -250,7 +250,7 @@ class Fysom(object):
except NameError:
return isinstance(object, str)
- def trigger(self, event):
+ def trigger(self, event, *args, **kwargs):
'''
Triggers the given event.
The event can be triggered by calling the event handler directly, for ex: fsm.eat()
@@ -260,4 +260,4 @@ class Fysom(object):
if not hasattr(self, event):
raise FysomError(
"There isn't any event registered as %s" % event)
- return getattr(self, event)()
+ return getattr(self, event)(*args, **kwargs)
diff --git a/setup.cfg b/setup.cfg
index 05297de..5a96a72 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -4,7 +4,8 @@ requires = python >= 2.6
release = 1
[egg_info]
-tag_svn_revision = 0
+egg_base = /tmp
tag_build =
tag_date = 0
+tag_svn_revision = 0
diff --git a/setup.py b/setup.py
index f7d430d..c10f0de 100755
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ from setuptools import setup
if __name__ == '__main__':
setup(
name = 'fysom',
- version = '1.0.18',
+ version = '1.0.19',
description = '''pYthOn Finite State Machine''',
long_description = '''''',
author = "Mansour Behabadi, Jake Gordon, Maximilien Riehl, Stefano",
diff --git a/test/test_state.py b/test/test_state.py
index 084051c..671b5f1 100644
--- a/test/test_state.py
+++ b/test/test_state.py
@@ -33,6 +33,7 @@ from fysom import Fysom, FysomError
class FysomStateTests(unittest.TestCase):
+
def setUp(self):
self.fsm = Fysom({
'initial': 'green',
@@ -74,3 +75,23 @@ class FysomStateTests(unittest.TestCase):
make_callable = lambda: self.fsm.trigger("unknowevent")
self.assertRaises(FysomError, make_callable)
self.assertEqual(self.fsm.current, "blue", "The initial state isn't the expected state.")
+
+ def test_trigger_should_trigger_the_event_handler_with_args(self):
+ self.assertEqual(self.fsm.current, "green", "The initial state isn't the expected state.")
+
+ def onblue(event):
+ self.assertEqual(event.args, ("any-positional-argument",))
+ self.fsm.onblue = onblue
+
+ self.fsm.trigger("warm", "any-positional-argument")
+ self.assertEqual(self.fsm.current, "blue", "The initial state isn't the expected state.")
+
+ def test_trigger_should_trigger_the_event_handler_with_kwargs(self):
+ self.assertEqual(self.fsm.current, "green", "The initial state isn't the expected state.")
+
+ def onblue(event):
+ self.assertEqual(event.keyword_argument, "any-value")
+ self.fsm.onblue = onblue
+
+ self.fsm.trigger("warm", keyword_argument="any-value")
+ self.assertEqual(self.fsm.current, "blue", "The initial state isn't the expected state.")