Пример #1
0
    def test_WorkbookElement_addSheet_index_goes_if(self):
        _test_el = WorkbookElement()
        self._remove_patched_function('_getSheets')
        self._remove_patched_function('_appendChild')
        self._remove_patched_function('_updateModifiedTime')

        _getSheets = self._init_patch_with_name(
            '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets',
            return_value=['sheet1', 'sheet2', 'sheet3'], autospec=True)
        _appendChild = self._init_patch_with_name(
            '_appendChild', 'xmind.core.Node.appendChild', autospec=True)
        _insertBefore = self._init_patch_with_name(
            '_insertBefore', 'xmind.core.Node.insertBefore', autospec=True)
        _updateModifiedTime = self._init_patch_with_name(
            '_updateModifiedTime', 'xmind.core.mixin.WorkbookMixinElement.updateModifiedTime', autospec=True)

        _result1 = _test_el.addSheet('sheet')
        _result2 = _test_el.addSheet('sheet', -1)
        _result3 = _test_el.addSheet('sheet', 3)
        _result4 = _test_el.addSheet('sheet', 4)

        self.assertListEqual(_getSheets.call_args_list, [call(_test_el)]*4)
        self.assertListEqual(_appendChild.call_args_list,
                             [call(_test_el, 'sheet')]*4)
        _insertBefore.assert_not_called()
        self.assertEqual(_updateModifiedTime.call_count, 4)
        self._assert_init_methods_called()
Пример #2
0
    def test_WorkbookElement_addSheet_index_is_within_len_sheets(self):
        _test_el = WorkbookElement()
        self._remove_patched_function('_getSheets')
        self._remove_patched_function('_appendChild')
        self._remove_patched_function('_updateModifiedTime')

        _getSheets = self._init_patch_with_name(
            '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets',
            return_value=['sheet1', 'sheet2', 'sheet3'], autospec=True)
        _appendChild = self._init_patch_with_name(
            '_appendChild', 'xmind.core.Node.appendChild', autospec=True)
        _insertBefore = self._init_patch_with_name(
            '_insertBefore', 'xmind.core.Node.insertBefore', autospec=True)
        _updateModifiedTime = self._init_patch_with_name(
            '_updateModifiedTime', 'xmind.core.mixin.WorkbookMixinElement.updateModifiedTime', autospec=True)

        _result = _test_el.addSheet('sheet', 0)

        _getSheets.assert_called_once_with(_test_el)
        _appendChild.assert_not_called()
        _insertBefore.assert_called_once_with(_test_el, 'sheet', 'sheet1')
        _updateModifiedTime.assert_called_once_with(_test_el)
        self._assert_init_methods_called()