def test_WorkbookElement_removeSheet_len_sheets_greater_1_parent_imp_equal(self): _test_el = WorkbookElement() self._remove_patched_function('_getSheets') self._remove_patched_function('_updateModifiedTime') _getSheets = self._init_patch_with_name( '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets', return_value=['sheet1', 'sheet2', 'sheet3'], autospec=True) _getImplementation = self._init_patch_with_name( '_getImplementation', 'xmind.core.Node.getImplementation', return_value='implementation', autospec=True) _removeChild = self._init_patch_with_name( '_removeChild', 'xmind.core.Node.removeChild', autospec=True) _updateModifiedTime = self._init_patch_with_name( '_updateModifiedTime', 'xmind.core.mixin.WorkbookMixinElement.updateModifiedTime', autospec=True) _sheet = Mock() with patch.object(_sheet, 'getParentNode') as _getParentNode: _getParentNode.return_value = 'implementation' _result = _test_el.removeSheet(_sheet) _getSheets.assert_called_once_with(_test_el) _getParentNode.assert_called_once_with() _getImplementation.assert_called_once_with(_test_el) _removeChild.assert_called_once_with(_test_el, _sheet) _updateModifiedTime.assert_called_once_with(_test_el) self.assertIsNone(_result) self._assert_init_methods_called()
def test_WorkbookElement_removeSheet_len_sheets_less_or_equal_1(self): _test_el = WorkbookElement() self._remove_patched_function('_getSheets') self._remove_patched_function('_updateModifiedTime') _getSheets = self._init_patch_with_name( '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets', return_value=[[], ['sheet1']], autospec=True, return_value_as_side_effect=True) _getImplementation = self._init_patch_with_name( '_getImplementation', 'xmind.core.Node.getImplementation', return_value='implementation', autospec=True) _sheet = Mock() with patch.object(_sheet, 'getParentNode') as _getParentNode: _getParentNode.return_value = 'not equal' _result1 = _test_el.removeSheet(_sheet) self.assertIsNone(_result1) _result2 = _test_el.removeSheet(_sheet) self.assertIsNone(_result2) self.assertListEqual(_getSheets.call_args_list, [call(_test_el)]*2) _getParentNode.assert_not_called() _getImplementation.assert_not_called() self._assert_init_methods_called()
def test_WorkbookElement_removeSheet_sheets_is_none(self): _test_el = WorkbookElement() self._remove_patched_function('_getSheets') self._remove_patched_function('_updateModifiedTime') _getSheets = self._init_patch_with_name( '_getSheets', 'xmind.core.workbook.WorkbookElement.getSheets', return_value=None, autospec=True) with self.assertRaises(Exception) as _ex: _result = _test_el.removeSheet('sheet') _getSheets.assert_called_once_with(_test_el) self.assertTrue(_ex.exception.args[0].find( "object of type 'NoneType' has no len()") != -1) self._assert_init_methods_called()