예제 #1
0
 def __init__(self, unoObjs):
     self.unoObjs = unoObjs
     self.userVars = uservars.UserVars(uservars.Prefix.GRAMMAR,
                                       unoObjs.document, logger)
     self.msgbox = MessageBox(unoObjs)
     self.fileItems = fileitemlist.FileItemList(fileitemlist.LingExFileItem,
                                                self.userVars)
     self.selectedIndex = -1  # position in listboxFiles
     self.dlgCtrls = None
     self.evtHandler = None
     self.dlgClose = None
예제 #2
0
    def test4_uservars(self):
        USERVAR_PREFIX = 'LTbc_'  # LinguisticTools Bulk Conversion vars
        userVars = UserVars(USERVAR_PREFIX, self.unoObjs.document, logger)
        itemlist = fileitemlist.FileItemList(fileitemlist.BulkFileItem,
                                             userVars)
        add_new_item(itemlist, "a.txt")
        add_new_item(itemlist, "b.txt")
        add_new_item(itemlist, "c.txt")
        mock_store = mock.Mock()
        #mock_store.return_value = None
        with mock.patch.object(userVars, 'store', mock_store):
            itemlist.storeUserVars()
        expected = [
            mock.call("infile_count", "3"),
            mock.call("infile00_path", "a.txt"),
            mock.call("infile01_path", "b.txt"),
            mock.call("infile02_path", "c.txt"),
        ]
        logger.debug(mock_store.call_args_list)
        self.assertEqual(mock_store.call_args_list, expected)

        def mock_get_side_effect(varname):
            values = {
                "infile_count": "3",
                "infile00_path": "a.txt",
                "infile01_path": "b.txt",
                "infile02_path": "c.txt",
            }
            return values[varname]

        itemlist = fileitemlist.FileItemList(fileitemlist.BulkFileItem,
                                             userVars)
        mock_get = mock.Mock()
        mock_get.side_effect = mock_get_side_effect
        with mock.patch.object(userVars, 'get', mock_get):
            itemlist.loadUserVars()
        self.assertEqual(len(itemlist), 3)
        self.assertEqual(itemlist.getItemTextList(),
                         ["a.txt", "b.txt", "c.txt"])
 def create_blank_wordlist(self):
     columnOrder = ColumnOrder(self.userVars)
     fileItemList = fileitemlist.FileItemList(fileitemlist.WordListFileItem,
                                              self.userVars)
     wordList = WordList(self.unoObjs, fileItemList, columnOrder,
                         self.userVars)
     punct = ""
     try:
         wordList.generateList(punct, 'NFD')
     except testutil.MsgSentException as exc:
         self.assertTrue(exc.msg.startswith("Made list"))
     else:
         self.fail("Expected error message.")
예제 #4
0
 def test2_empty_list(self):
     USERVAR_PREFIX = 'LTbc_'  # LinguisticTools Bulk Conversion vars
     userVars = UserVars(USERVAR_PREFIX, self.unoObjs.document, logger)
     itemlist = fileitemlist.FileItemList(fileitemlist.BulkFileItem,
                                          userVars)
     self.assertEqual(len(itemlist), 0)
     with self.assertRaises(IndexError):
         dummy = itemlist[0]
     self.assertEqual(itemlist.getItemTextList(), [])
     itemlist.sortItems()
     item = itemlist.makeNewItem()
     item.filepath = "a.txt"
     with self.assertRaises(exceptions.ChoiceProblem) as cm:
         itemlist.updateItem(0, item)
     self.assertEqual(cm.exception.msg, "Please select a file in the list.")
예제 #5
0
 def test2_empty_list(self):
     userVars = UserVars(Prefix.BULK_CONVERSION, self.unoObjs.document,
                         logger)
     itemlist = fileitemlist.FileItemList(fileitemlist.BulkFileItem,
                                          userVars)
     self.assertEqual(len(itemlist), 0)
     with self.assertRaises(IndexError):
         dummy = itemlist[0]
     self.assertEqual(itemlist.getItemTextList(), [])
     itemlist.sortItems()
     item = itemlist.makeNewItem()
     item.filepath = "a.txt"
     with self.assertRaises(exceptions.ChoiceProblem) as cm:
         itemlist.updateItem(0, item)
     self.assertEqual(cm.exception.msg, "Please select a file in the list.")
예제 #6
0
 def test3_add_items(self):
     USERVAR_PREFIX = 'LTbc_'  # LinguisticTools Bulk Conversion vars
     userVars = UserVars(USERVAR_PREFIX, self.unoObjs.document, logger)
     itemlist = fileitemlist.FileItemList(fileitemlist.BulkFileItem,
                                          userVars)
     item = add_new_item(itemlist, "a.txt")
     self.assertEqual(len(itemlist), 1)
     itemdup = itemlist.makeNewItem()
     itemdup.filepath = item.filepath
     with self.assertRaises(exceptions.ChoiceProblem) as cm:
         itemlist.addItem(itemdup)
     self.assertEqual(cm.exception.msg, "File is already in the list.")
     self.assertEqual(len(itemlist), 1)
     itemlist.addItem(itemdup, allowDuplicates=True)
     self.assertEqual(len(itemlist), 2)
     add_new_item(itemlist, "b.txt")
     self.assertEqual(len(itemlist), 3)
     item = itemlist.makeNewItem()
     item.filepath = "a.txt"
     self.assertTrue(itemlist.alreadyContains(item))
     item = itemlist.makeNewItem()
     item.filepath = "b.txt"
     self.assertTrue(itemlist.alreadyContains(item, excludeItemPos=1))
     self.assertFalse(itemlist.alreadyContains(item, excludeItemPos=2))
     add_new_item(itemlist, "d.txt")
     add_new_item(itemlist, "c.txt")
     self.assertEqual(len(itemlist), 5)
     self.assertEqual(itemlist[-2].filepath, "c.txt")
     self.assertEqual(itemlist[-1].filepath, "d.txt")
     item = itemlist.makeNewItem()
     item.filepath = "e.txt"
     itemlist.updateItem(-1, item)
     self.assertEqual(len(itemlist), 5)
     self.assertEqual(itemlist[-1].filepath, "e.txt")
     itemlist.deleteItem(-1)
     self.assertEqual(len(itemlist), 4)
     self.assertEqual(itemlist[-1].filepath, "c.txt")
    def test1_paragraphStyles(self):
        dataSets = [
            [("Heading 1", ), (
                "My",
                "big",
            ), ("Now", "now", "will")],
            [("Heading 1", "Caption", "Preformatted Text"),
             ("My", "big", "Now", "now", "will"), ()],
        ]
        for dataSet in dataSets:
            styleNames, expectedStrings, notExpectedStrings = dataSet
            fileItem = fileitemlist.WordListFileItem(self.userVars)
            fileItem.filetype = 'writerdoc'
            fileItem.filepath = FILEPATH
            for styleName in styleNames:
                whatToGrab = WhatToGrab(None)
                whatToGrab.grabType = WhatToGrab.PARASTYLE
                whatToGrab.whichOne = styleName
                fileItem.thingsToGrab.append(whatToGrab)
            columnOrder = ColumnOrder(self.userVars)
            fileItemList = fileitemlist.FileItemList(
                fileitemlist.WordListFileItem, self.userVars)
            fileItemList.addItem(fileItem)
            wordList = WordList(self.unoObjs, fileItemList, columnOrder,
                                self.userVars)
            try:
                wordList.generateList(". ?", 'NFD')
            except testutil.MsgSentException as exc:
                self.assertTrue(exc.msg.startswith("Made list"), msg=exc.msg)
            else:
                self.fail("Expected error message.")

            stringList = getColumnStringList(self.unoObjs)
            for testString in expectedStrings:
                self.assertIn(testString, stringList, msg=repr(styleNames))
            for testString in notExpectedStrings:
                self.assertNotIn(testString, stringList, msg=repr(styleNames))