def test_basic(self): backend = MockBackend() server = Server(backend, 'tcp://127.0.0.1:31338') client = Client('tcp://127.0.0.1:31338') try: server.start() # This test is screwy. If simplejson is installed, it will convert # all strings to str objects. Without it, you get unicode objects. # We require simplejson so assume it's gonna be str. self.assertEqual(client.foo(4, 'blah'), "foo: 4 'blah'") self.assertEqual( client.bar('hello', 'world', **dict(a=12, b='blah')), "bar: ('hello', 'world') {'a': 12, 'b': 'blah'}") with self.assertRaisesRegexp(ServerError, 'ValueError: sad'): client.failme(42) finally: server.kill()
from __future__ import (absolute_import, division, print_function, unicode_literals) import time from manhattan.client import Client client = Client() def test(f, trials=500): start = time.time() for ii in range(trials): f() end = time.time() elapsed = end - start print("Ran %d trials, %0.2f ms each" % (trials, ((1000. * elapsed) / trials))) def get_results(): client.test_results('Discount Rate for Datrek') def get_tests(): client.tests() if __name__ == '__main__': print("Testing tests list.") test(get_tests)
def test_timeout(self): client = Client('tcp://127.0.0.1:31339', wait=10) with self.assertRaisesRegexp(TimeoutError, 'Timed out after 10 ms waiting'): client.foo()