Beispiel #1
0
class ComplexTest(unittest.TestCase):
	def setUp(self):
		address = ('localhost', random.randint(2000, 20000))
		self.server = ThreadedRemotingServer(address)
		self.server.start()
		self.client = RemotingClient(address)

	def tearDown(self):
		del self.client
		if self.server.isAlive():
			self.server.stop()
		del self.server

	def test_invalid_fetch(self):
		self.server.export(20, remote_name = 'remote-1')
		self.assertRaises(KeyError, self.client.fetch, 'remote-2')

	def test_invalid_handle(self):
		self.assertRaises(AssertionError, self.client.handle, 'invalid-handle-id-type')
		handle = self.client.handle(uuid.uuid4())
		self.assertRaises(KeyError, int, handle)
		self.assertRaises(KeyError, getattr, handle, 'attribute_name')

	def test_browse(self):
		exports = set(['qwe', 'asd', 'zxc'])
		base = 1
		for name in exports:
			self.server.export(base, remote_name = name)
		server_exports = self.server.browse()
		remote_exports = self.client.browse()
		self.assertEqual(server_exports, exports)
		self.assertEqual(remote_exports, exports)

	def test_attach(self):
		base = 1500
		remote_name = 'obj'
		second_name = 'second'
		self.server.export(base, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		self.client.attach(remote_object, second_name)
		second_remote = self.client.fetch(second_name)
		self.assertEqual(int(second_remote), int(base))
		self.assertEqual(int(remote_object), int(second_remote))

	def test_store_attach_browse(self):
		exports = set(['qwe', 'asd', 'zxc'])
		base = 12033
		remote_object = self.client.store(base)
		for name in exports:
			self.client.attach(remote_object, name)
		remote_exports = self.client.browse()
		self.assertEqual(remote_exports, exports)

	def test_get_item(self):
		item_name = 'a'
		base = {item_name: 20}
		remote_name = 'obj'
		self.server.export(base, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object[item_name]
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertEqual(int(base[item_name]), int(result))
		self.assertIs(result.__class__, RemoteHandle)

	def test_set_item(self):
		item_name = 'a'
		changed = 30
		base = {item_name: 20}
		remote_name = 'obj'
		self.server.export(base, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		remote_object[item_name] = changed
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertEqual(base[item_name], changed)

	def test_attribute(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.value # Meat
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertEqual(local_object.value, int(result))
		self.assertIs(result.__class__, RemoteHandle)

	def test_set_attribute(self):
		base = 20
		modified = 30
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		remote_object.value = modified  # Meat
		remote_object_2 = self.client.fetch(remote_name)
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertIs(remote_object_2.__class__, RemoteHandle)
		self.assertEqual(local_object.value, int(remote_object.value))
		self.assertEqual(int(remote_object_2.value), int(remote_object.value))

	def test_attribute_remote_handle(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		attribute_name = self.client.store('value')
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.__getattr__(attribute_name)
			# getattr(remote_object, attribute_name) requires attribute_name to be string
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertIs(result.__class__, RemoteHandle)
		self.assertEqual(local_object.value, int(result))

	def test_method(self):
		base = 20
		addition = 30
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		self.assertIs(remote_object.__class__, RemoteHandle)
		result = remote_object.method(addition) # Meat
		self.assertIs(result.__class__, RemoteHandle)
		self.assertEqual(local_object.get_value(), int(result))

	def test_method_invalid_execution(self):
		base = 20
		addition = 30
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		self.assertRaises(TypeError, remote_object.method, addition, addition)
			# this will run remote_object.method(addition, addition) which will fail

	def test_method_remote_handle(self):
		base = 20
		addition = self.client.store(30)
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.method(addition) # Meat
		self.assertEqual(local_object.get_value(), int(result))
		self.assertEqual(result, local_object.get_value())

	def test_equality(self):
		value = 20
		first = self.client.store(value)
		second = self.client.store(value)
		self.assertEqual(first, second)

	def test_evaluation(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.get_value() # Meat
		self.assertEqual(int(result), base)
		self.assertEqual(str(result), str(base))
		self.assertEqual(unicode(result), unicode(base))

	def test_remote_object_creation(self):
		base = 20
		remote_name = 'obj'
		self.server.export(TestClass, remote_name = remote_name)
		remote_class = self.client.fetch(remote_name)
		remote_object = remote_class(base) # Meat
		self.assertEqual(base, int(remote_object.value))

	def test_store(self):
		base = 30
		remote_object = self.client.store(base)
		self.assertEqual(int(remote_object), base)

	def test_store_list(self):
		base = [30, 40]
		remote_object = self.client.store(base)
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertEqual(list(remote_object), base)
		self.assertEqual(len(remote_object), len(base))
		self.assertIs(remote_object[0].__class__, RemoteHandle)

	def test_store_list_of_handles(self):
		remote_name = 'obj'
		self.server.export(TestClass, remote_name = remote_name)
		remote_class = self.client.fetch(remote_name)
		base = [remote_class(30), remote_class(40)]
		remote_object = self.client.store(base)
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertEqual(list(remote_object), base)

	def test_method_list(self):
		base = [30]
		addition = [40]
		remote_name = 'obj'
		self.server.export(TestClass, remote_name = remote_name)
		remote_class = self.client.fetch(remote_name)
		self.assertIs(remote_class.__class__, RemoteHandle)
		remote_object = remote_class(base)
		self.assertIs(remote_object.__class__, RemoteHandle)
		result = remote_object.method(addition)
		self.assertEqual(list(result), base + addition)

	def test_store_dict(self):
		base = {"qwe": 30, "asd": 40}
		remote_object = self.client.store(base)
		from remoteable.client import RemoteHandle
		self.assertEqual(remote_object, base)
		self.assertEqual(remote_object['qwe'], base['qwe'])
		self.assertEqual(remote_object.keys(), base.keys())
		self.assertIs(remote_object.__class__, RemoteHandle)
		self.assertIs(remote_object['qwe'].__class__, RemoteHandle)

	def test_releasing(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		#del remote_object
		remote_object.__del__()
		self.assertRaises(KeyError, remote_object)
Beispiel #2
0
	def setUp(self):
		address = ('localhost', random.randint(2000, 20000))
		self.server = ThreadedRemotingServer(address)
		self.server.start()
		self.client = RemotingClient(address)
Beispiel #3
0
class Test(unittest.TestCase):
	def setUp(self):
		address = ('localhost', random.randint(2000, 20000))
		self.server = ThreadedRemotingServer(address)
		self.server.start()
		self.client = RemotingClient(address)

	def tearDown(self):
		if self.server.isAlive():
			self.server.stop()

	def test_attribute(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.value # Meat
		self.assertEqual(local_object.value, int(result))

	def test_set_attribute(self):
		base = 20
		modified = 30
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		remote_object.value = modified  # Meat
		remote_object_2 = self.client.fetch(remote_name)
		self.assertEqual(local_object.value, int(remote_object.value))
		self.assertEqual(int(remote_object_2.value), int(remote_object.value))

	def test_attribute_remote_handle(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		attribute_name = self.client.store('value')
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.__getattr__(attribute_name)
			# getattr(remote_object, attribute_name) requires attribute_name to be string
		self.assertEqual(local_object.value, int(result))

	def test_method(self):
		base = 20
		addition = 30
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.method(addition) # Meat
		self.assertEqual(local_object.get_value(), int(result))

	def test_method_remote_handle(self):
		base = 20
		addition = self.client.store(30)
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.method(addition) # Meat
		self.assertEqual(local_object.get_value(), int(result))
		self.assertEqual(result, local_object.get_value())

	def test_equality(self):
		value = 20
		first = self.client.store(value)
		second = self.client.store(value)
		self.assertEqual(first, second)

	def test_evaluation(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		result = remote_object.get_value() # Meat
		self.assertEqual(int(result), base)
		self.assertEqual(str(result), str(base))

	def test_store(self):
		base = 30
		remote_object = self.client.store(base)
		self.assertEqual(int(remote_object), base)

	def test_store_list(self):
		base = [30, 40]
		remote_object = self.client.store(base)
		self.assertEqual(list(remote_object), base)

	def test_store_dict(self):
		base = {"qwe": 30, "asd": 40}
		remote_object = self.client.store(base)
		self.assertEqual(dict(**remote_object), base)

	def test_releasing(self):
		base = 20
		remote_name = 'obj'
		local_object = TestClass(base)
		self.server.export(local_object, remote_name = remote_name)
		remote_object = self.client.fetch(remote_name)
		#del remote_object
		remote_object.__del__()
		self.assertRaises(KeyError, remote_object)