Repository: jubatus/jubatus-python-client

Issue:
no type validation for constructor arguments
Currently argument types are validated, but constructor arguments are not.
For example, the following code:

```
c = jubatus.Classifier("localhost", 9199, 0)  # it should be ("localhost", 9199, "") to work
c.get_status()
```

raises "TypeMismatch (error 2)" on RPC call, which is difficult to understand.

Discussion:

Patch:
diff --git a/jubatus/common/client.py b/jubatus/common/client.py
index d599319..9cd91a8 100644
--- a/jubatus/common/client.py
+++ b/jubatus/common/client.py
@@ -54,6 +54,10 @@ class ClientBase(object):
       (`unpack_encoding=None`)
     """
     def __init__(self, host, port, name, timeout=10):
+        check_types(host, string_types)
+        check_types(port, int_types)
+        check_types(name, string_types)
+        check_types(timeout, int_types)
         address = msgpackrpc.Address(host, port)
         self.client = msgpackrpc.Client(address, timeout=timeout, pack_encoding='utf-8', unpack_encoding=None)
         self.jubatus_client = Client(self.client, name)
@@ -65,6 +69,7 @@ class ClientBase(object):
         return self.jubatus_client.name
 
     def set_name(self, name):
+        check_types(name, string_types)
         self.jubatus_client.name = name
 
     def save(self, id):


Test patch:
diff --git a/test/jubatus_test/common/test_client.py b/test/jubatus_test/common/test_client.py
index 0e929f8..065b538 100644
--- a/test/jubatus_test/common/test_client.py
+++ b/test/jubatus_test/common/test_client.py
@@ -67,5 +67,22 @@ class ClientTest(unittest.TestCase):
         self.assertEqual("test", c.call("test", [], AnyType(), []))
         self.assertRaises(TypeError, c.call, "test", [1], AnyType(), [])
 
+class ClientBaseTest(unittest.TestCase):
+    def test_constructor(self):
+        self.assertIsInstance(jubatus.common.ClientBase("127.0.0.1", 9199, "cluster", 10), jubatus.common.ClientBase)
+
+        # invalid host
+        self.assertRaises(TypeError, jubatus.common.ClientBase, 127001, 9199, "cluster", 10)
+
+        # invalid port
+        self.assertRaises(TypeError, jubatus.common.ClientBase, "127.0.0.1", "9199", "cluster", 10)
+
+        # invalid name
+        self.assertRaises(TypeError, jubatus.common.ClientBase, "127.0.0.1", 9199, 10, 10)
+
+        # invalid timeout
+        self.assertRaises(TypeError, jubatus.common.ClientBase, "127.0.0.1", 9199, "cluster", "test")
+        self.assertRaises(TypeError, jubatus.common.ClientBase, "127.0.0.1", 9199, "cluster", 1.5)
+
 if __name__ == '__main__':
     unittest.main()