コード例 #1
0
    def test_WorkbookElement_getSheet_is_sheets_ownerbook_none(self):
        _test_el = WorkbookElement()
        self._assert_init_methods_called()

        self._remove_patched_function('_getSheets')

        _getChildNodesByTagName = self._init_patch_with_name(
            '_getChildNodesByTagName', 'xmind.core.Node.getChildNodesByTagName', return_value=[11, 12, 13], autospec=True)
        _getOwnerWorkbook = self._init_patch_with_name(
            '_getOwnerWorkbook', 'xmind.core.mixin.WorkbookMixinElement.getOwnerWorkbook',
            return_value=None, autospec=True)

        with patch('xmind.core.workbook.SheetElement') as _sheet_element_constructor:
            _sheet_element_constructor.side_effect = ['a', 'b', 'c']

            _sheets = _test_el.getSheets()

        self._assert_init_methods_called()
        _getChildNodesByTagName.assert_called_once_with(_test_el, TAG_SHEET)
        _getOwnerWorkbook.assert_called_once_with(_test_el)
        self.assertListEqual([
            call(11, None),
            call(12, None),
            call(13, None)], _sheet_element_constructor.call_args_list)
        self.assertListEqual(_sheets, ['a', 'b', 'c'])
コード例 #2
0
    def test_WorkbookElement_getSheet_sheets_is_none(self):
        _test_el = WorkbookElement()
        self._assert_init_methods_called()

        self._remove_patched_function('_getSheets')

        _getChildNodesByTagName = self._init_patch_with_name(
            '_getChildNodesByTagName', 'xmind.core.Node.getChildNodesByTagName', return_value=None, autospec=True)
        _getOwnerWorkbook = self._init_patch_with_name(
            '_getOwnerWorkbook', 'xmind.core.mixin.WorkbookMixinElement.getOwnerWorkbook',
            return_value=self._owner_workbook, autospec=True)

        with self.assertRaises(Exception) as _ex:
            _test_el.getSheets()

        _getChildNodesByTagName.assert_called_once_with(_test_el, TAG_SHEET)
        _getOwnerWorkbook.assert_called_once_with(_test_el)
        self.assertTrue(_ex.exception.args[0].find(
            "'NoneType' object is not iterable") != -1)