Permalink
Browse files

Merge pull request #4 from koelie/master

default argument order fix
  • Loading branch information...
2 parents fda3e0e + 2991754 commit ea6a8f3a9125fbd1fd63abe96ec94b3540d22acc @joshmarshall committed Jan 24, 2014
Showing with 16 additions and 7 deletions.
  1. +14 −2 tests/json.py
  2. +2 −5 tornadorpc/utils.py
View
@@ -4,8 +4,9 @@
import unittest
class TestJSONHandler(TestHandler, JSONRPCHandler):
- pass
-
+ def testOrder(self, a=1, b=2, c=3):
+ return {'a': a, 'b': b, 'c': c}
+
class JSONRPCTests(RPCTests, unittest.TestCase):
port = 8003
handler = TestJSONHandler
@@ -18,3 +19,14 @@ def test_private(self):
client = self.get_client()
self.assertRaises(jsonrpclib.ProtocolError, client.private)
+ def test_order(self):
+ client = self.get_client()
+ self.assertEqual(client.testOrder(),
+ {'a': 1, 'b': 2, 'c': 3})
+ self.assertEqual(client.testOrder(a=10),
+ {'a': 10, 'b': 2, 'c': 3})
+ self.assertEqual(client.testOrder(c=10),
+ {'a': 1, 'b': 2, 'c': 10})
+ self.assertEqual(client.testOrder(a=10,b=11,c=12),
+ {'a': 10, 'b': 11, 'c': 12})
+
View
@@ -49,11 +49,8 @@ def getcallargs(func, *positional, **named):
else:
extra_args.append(value)
if defaults:
- reverse_args = args[:]
- reverse_args.reverse()
- for i in range(len(defaults)):
- arg_key = reverse_args[i]
- final_kwargs.setdefault(arg_key, defaults[i])
+ for kwarg, default in zip(args[-len(defaults):], defaults):
+ final_kwargs.setdefault(kwarg, default)
for arg in args:
if arg not in final_kwargs:
raise TypeError("Not all arguments supplied. (%s)", arg)

0 comments on commit ea6a8f3

Please sign in to comment.