Example #1
0
 def test_getAttribute_node_hasAttribute(self):
     """Tests getAttribute method"""
     _node = MagicMock()
     _node.getAttribute.return_value = 12
     _node.hasAttribute.return_value = True
     _element = Element(_node)
     self.assertEqual(_element.getAttribute('t1'), 12)
     _node.getAttribute.assert_called_once_with('t1')
     _node.hasAttribute.assert_called_once_with('t1')
Example #2
0
 def test_getAttribute_node_hasNoAttribute(self):
     """Tests getAttribute method when node has attribute"""
     _get_local_name = self._init_patch_with_name(
         "_get_local_name", "xmind.core.Element.getLocalName", return_value='t1', autospec=True)
     _node = MagicMock()
     _node.getAttribute.return_value = 12
     _node.hasAttribute.return_value = False
     _element = Element(_node)
     self.assertEqual(_element.getAttribute('t1'), None)
     _node.getAttribute.assert_not_called()
     _node.hasAttribute.assert_called_once_with('t1')
     _get_local_name.assert_called_once_with(_element, 't1')
Example #3
0
    def test_getAttribute_node_hasNoAttribute_localName_differs(self):
        """Tests getAttribute method when node has no attribute and localName differs from attribute name"""
        _get_local_name = self._init_patch_with_name(
            "_get_local_name", "xmind.core.Element.getLocalName", return_value='t2', autospec=True)
        _node = MagicMock()
        _node.getAttribute.return_value = 12
        _node.hasAttribute.side_effect = [False, True]
        _element = Element(_node)
        with patch.object(Element, 'getAttribute', wraps=_element.getAttribute) as _mock:
            self.assertEqual(_element.getAttribute('t1'), 12)

        self.assertEqual(_mock.call_count, 2)
        self.assertListEqual(_mock.call_args_list, [call('t1'), call('t2')])
        _node.getAttribute.assert_called_once_with('t2')
        self.assertEqual(_node.hasAttribute.call_count, 2)
        self.assertListEqual(_node.hasAttribute.call_args_list, [
                             call('t1'), call('t2')])
        _get_local_name.assert_called_once_with(_element, 't1')