def test_extra_nonexistant_attributes(self): expected_extra_dict = {"nonexistant": ""} xpcom = XpcomConversionTests._mock_xpcom_object() ret = vb_xpcom_to_attribute_dict( xpcom, extra_attributes=expected_extra_dict.keys()) self.assertDictEqual(ret, expected_extra_dict)
def test_extra_nonexistant_attribute_with_default(self): expected_extras = [("nonexistant", list)] expected_extra_dict = {"nonexistant": []} xpcom = XpcomConversionTests._mock_xpcom_object() ret = vb_xpcom_to_attribute_dict(xpcom, extra_attributes=expected_extras) self.assertDictEqual(ret, expected_extra_dict)
def test_override_attributes(self): expected_dict = {"herp": "derp", "lol": "rofl", "something": 12345} xpc = XpcomConversionTests._mock_xpcom_object(attributes=expected_dict) ret = vb_xpcom_to_attribute_dict(xpc, attributes=expected_dict.keys()) self.assertDictEqual(ret, expected_dict)
def test_imachine_object_default(self): interface = "IMachine" imachine = XpcomConversionTests._mock_xpcom_object(interface) ret = vb_xpcom_to_attribute_dict(imachine, interface_name=interface) expected_attributes = XPCOM_ATTRIBUTES[interface] self.assertIsNotNone(expected_attributes, "%s is unknown") for key in ret.keys(): self.assertIn(key, expected_attributes)
def test_extra_attributes(self): interface = "IMachine" expected_extras = { "extra": "extra", } expected_machine = dict([(attribute, attribute) for attribute in XPCOM_ATTRIBUTES[interface]]) expected_machine.update(expected_extras) imachine = XpcomConversionTests._mock_xpcom_object(interface, attributes=expected_machine) ret = vb_xpcom_to_attribute_dict( imachine, interface_name=interface, extra_attributes=expected_extras.keys() ) self.assertDictEqual(ret, expected_machine) ret_keys = ret.keys() for key in expected_extras.keys(): self.assertIn(key, ret_keys)
def test_unknown_object(self): xpcom = XpcomConversionTests._mock_xpcom_object() ret = vb_xpcom_to_attribute_dict(xpcom) self.assertDictEqual(ret, dict())