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

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

        _result1 = _test_el.moveSheet(2, -1)
        self.assertIsNone(_result1)

        _result2 = _test_el.moveSheet(2, 4)
        self.assertIsNone(_result2)

        _result3 = _test_el.moveSheet(2, 5)
        self.assertIsNone(_result3)

        self.assertListEqual(_getSheets.call_args_list, [call(_test_el)]*3)
        self.assertListEqual(_removeChild.call_args_list, [
                             call(_test_el, 'sheet3')] * 3)
        self.assertListEqual(_appendChild.call_args_list, [
                             call(_test_el, 'sheet3')] * 3)
        self.assertListEqual(_updateModifiedTime.call_args_list, [
                             call(_test_el)] * 3)
        self._assert_init_methods_called()
Пример #2
0
    def test_WorkbookElement_moveSheet_prev_true_origin_less_target_target_not_equal_sheet(self):
        _test_el = WorkbookElement()
        self._remove_patched_function('_getSheets')
        self._remove_patched_function('_updateModifiedTime')
        self._remove_patched_function('_appendChild')

        _getSheets = self._init_patch_with_name(
            '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets',
            return_value=['sheet1', 'sheet2', 'sheet_equal', 'sheet4', 'sheet_not_equal'], autospec=True)
        _removeChild = self._init_patch_with_name(
            '_removeChild', 'xmind.core.Node.removeChild', 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.moveSheet(2, 3)

        _getSheets.assert_called_once_with(_test_el)
        _removeChild.assert_called_once_with(_test_el, 'sheet_equal')
        _insertBefore.assert_called_once_with(
            _test_el, 'sheet_equal', 'sheet_not_equal')
        _appendChild.assert_not_called()
        _updateModifiedTime.assert_called_once_with(_test_el)
        self.assertIsNone(_result)
        self._assert_init_methods_called()
Пример #3
0
    def test_WorkbookElement_moveSheet_origin_index_equal_target_index(self):
        _test_el = WorkbookElement()
        self._remove_patched_function('_getSheets')

        with patch.object(_test_el, 'getSheets') as _getSheets:
            _getSheets.return_value = ['sheet1', 'sheet2', 'sheet3']

            _result = _test_el.moveSheet(2, 2)

        _getSheets.assert_not_called()
        self.assertIsNone(_result)
        self._assert_init_methods_called()
Пример #4
0
    def test_WorkbookElement_moveSheet_origin_index_not_less_0(self):
        _test_el = WorkbookElement()
        self._remove_patched_function('_getSheets')

        _getSheets = self._init_patch_with_name(
            '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets', autospec=True)
        _getSheets.side_effect = Exception('test exception')

        with self.assertRaises(Exception) as _ex:
            _result = _test_el.moveSheet(0, 1)

        _getSheets.assert_called_once_with(_test_el)
        self.assertTrue(_ex.exception.args[0].find('test exception') == 0)
        self._assert_init_methods_called()
Пример #5
0
    def test_WorkbookElement_moveSheet_origin_index_equal_len_sheets(self):
        _test_el = WorkbookElement()
        self._remove_patched_function('_getSheets')
        self._remove_patched_function('_updateModifiedTime')

        _updateModifiedTime = self._init_patch_with_name(
            '_updateModifiedTime', 'xmind.core.mixin.WorkbookMixinElement.updateModifiedTime', autospec=True)
        with patch.object(_test_el, 'getSheets') as _getSheets:
            _getSheets.return_value = ['sheet1', 'sheet2', 'sheet3']

            _result = _test_el.moveSheet(3, 1)

        _getSheets.assert_called_once_with()
        self.assertIsNone(_result)
        _updateModifiedTime.assert_not_called()
        self._assert_init_methods_called()