def test_empty_initialization(self): exposed_objects = ExposedObjectCollection(named_objects={}) self.assertEqual(set(exposed_objects), {":api", "get_objects"}) self.assertEqual(len(exposed_objects.get_objects()), 0) self.assertEqual(exposed_objects["get_objects"](), exposed_objects.get_objects())
def test_nested_collections(self): obj = DummyObject() exposed_objects = ExposedObjectCollection( {"container": ExposedObjectCollection({"test": obj})}) exposed_objects["container.test.getTest"](454, 43) obj.getTest.assert_called_once_with(454, 43)
def test_empty_initialization(self): exposed_objects = ExposedObjectCollection(named_objects={}) self.assertEqual(set(exposed_objects), {':api', 'get_objects'}) self.assertEqual(len(exposed_objects.get_objects()), 0) self.assertEqual(exposed_objects['get_objects'](), exposed_objects.get_objects())
def test_nested_collections(self): obj = TestObject() exposed_objects = ExposedObjectCollection( {'container': ExposedObjectCollection({'test': obj})}) exposed_objects['container.test.getTest'](454, 43) obj.getTest.assert_called_once_with(454, 43)
def test_remove_object(self): exposed_objects = ExposedObjectCollection({}) own_functions_count = len(exposed_objects) obj = DummyObject() exposed_objects.add_object(obj, "testObject") self.assertListEqual(exposed_objects.get_objects(), ["testObject"]) assertRaisesNothing(self, exposed_objects.remove_object, "testObject") self.assertEqual(len(exposed_objects), own_functions_count) self.assertRaises(RuntimeError, exposed_objects.remove_object, "does_not_exist")
def test_api(self): exposed_objects = ExposedObjectCollection(named_objects={}) api = exposed_objects[":api"]() self.assertTrue("class" in api) self.assertEqual(api["class"], "ExposedObjectCollection") self.assertTrue("methods" in api) self.assertEqual(set(api["methods"]), {"get_objects", ":api"})
def test_api(self): exposed_objects = ExposedObjectCollection(named_objects={}) api = exposed_objects[':api']() self.assertTrue('class' in api) self.assertEqual(api['class'], 'ExposedObjectCollection') self.assertTrue('methods' in api) self.assertEqual(set(api['methods']), {'get_objects', ':api'})
def test_add_exposed_object(self): exposed_objects = ExposedObjectCollection({}) obj = DummyObject() assertRaisesNothing(self, exposed_objects.add_object, ExposedObject(obj, ('setTest', 'getTest')), 'testObject') exposed_objects['testObject.getTest'](41, 11) obj.getTest.assert_called_once_with(41, 11)
def test_add_exposed_object(self): exposed_objects = ExposedObjectCollection({}) obj = DummyObject() assertRaisesNothing( self, exposed_objects.add_object, ExposedObject(obj, ("setTest", "getTest")), "testObject", ) exposed_objects["testObject.getTest"](41, 11) obj.getTest.assert_called_once_with(41, 11)
def test_add_plain_object(self): exposed_objects = ExposedObjectCollection({}) obj = DummyObject() assertRaisesNothing(self, exposed_objects.add_object, obj, "testObject") # There should be :api, get_objects, testObject:api, testObject.a:get, testObject.a:set, # testObject.b:get, testObject.b:set, testObject.getTest, testObject.setTest self.assertEqual(len(exposed_objects), 9) exposed_objects["testObject.getTest"](34, 55) obj.getTest.assert_called_once_with(34, 55)
def test_duplicate_name_raises(self): exposed_objects = ExposedObjectCollection({}) exposed_objects.add_object(DummyObject(), "testObject") self.assertRaises(RuntimeError, exposed_objects.add_object, DummyObject(), "testObject")