def test2_double(self):
        """Test two converters in the pool."""
        self.addConverter(CONV_NAME)
        inputStr = "abCde"
        convPool = ConvPool(self.userVars, self.msgbox)
        conv_settings1 = ConverterSettings(self.userVars)
        conv_settings1.convName = CONV_NAME
        conv_settings1.forward = False
        SelectSettingsCache.converter = conv_settings1
        # This calls our modified funcSelectConverter() above,
        # which tells the ConvPool what EncConverters actually
        # contains after test1_single().
        dummy_fontChange = convPool.selectConverter(conv_settings1)

        conv_settings1 = ConverterSettings(self.userVars)
        conv_settings1.convName = CONV_NAME
        conv_settings1.forward = True
        sec_call1 = convPool.loadConverter(conv_settings1)
        convertedVal = sec_call1.convert(inputStr)
        self.assertEqual(convertedVal, "ABCDE")

        CONV_NAME2 = "Any-Lower"
        self.addConverter(CONV_NAME2)
        conv_settings2 = ConverterSettings(self.userVars)
        conv_settings2.convName = CONV_NAME2
        with self.assertRaises(KeyError):
            sec_call2 = convPool[CONV_NAME2]
        convPool.loadConverter(conv_settings2)
        sec_call2 = convPool[CONV_NAME2]
        convertedVal = sec_call2.convert(inputStr)
        self.assertEqual(convertedVal, "abcde")
        self.assertEqual(len(convPool._secCallObjs), 2)
        self.assertEqual(sec_call1.convert("f"), "F")
        self.assertEqual(sec_call2.convert("G"), "g")
    def test1_single(self):
        """Test a single converter in the pool."""
        self.addConverter(CONV_NAME)
        inputStr = "abCde"
        convPool = ConvPool(self.userVars, self.msgbox)
        conv_settings = ConverterSettings(self.userVars)
        conv_settings.convName = CONV_NAME
        conv_settings.forward = True
        SelectSettingsCache.converter = conv_settings
        dummy_fontChange = convPool.selectConverter(conv_settings)
        sec_call = convPool[CONV_NAME]
        convertedVal = sec_call.convert(inputStr)
        self.assertEqual(convertedVal, "ABCDE")
        self.assertEqual(len(convPool._secCallObjs), 1)

        conv_settings = ConverterSettings(self.userVars)
        conv_settings.convName = CONV_NAME
        conv_settings.forward = False
        sec_call = convPool.loadConverter(conv_settings)
        convertedVal = sec_call.convert(inputStr)
        self.assertEqual(convertedVal, "abcde")
        self.assertEqual(len(convPool._secCallObjs), 1)

        with self.assertRaises(KeyError):
            sec_call = convPool["doesn't exist"]
Ejemplo n.º 3
0
 def getFormResults(self):
     """
     Reads form fields and stores user vars.
     returns: converter settings
     """
     logger.debug(util.funcName('begin'))
     converter = ConverterSettings(self.userVars)
     converter.loadUserVars()  # for normForm
     converter.convName = self.dlgCtrls.txtConverterName.getText()
     converter.forward = (self.dlgCtrls.chkDirectionReverse.getState() == 0)
     converter.storeUserVars()
     self.sourceCol = self.dlgCtrls.txtSourceCol.getText()
     self.targetCol = self.dlgCtrls.txtTargetCol.getText()
     self.skipFirstRow = bool(self.dlgCtrls.chkSkipRow.getState())
     self.userVars.store("ConvSourceColumn", self.sourceCol)
     self.userVars.store("ConvTargetColumn", self.targetCol)
     self.userVars.store("SkipFirstRow",
                         str(self.dlgCtrls.chkSkipRow.getState()))
     logger.debug(util.funcName('end'))
     return converter