Ejemplo n.º 1
0
    def tttest_Bringup_voicecode_user_switching(self):
    
        user, dummy = natlink.getCurrentUser()
        if user == 'VoiceCode':
            mes = ['active user is: %s'% user, '',
                   'Cannot test voicecode_user_switching to VoiceCode again', '', 
                   'Please start test with another user being active.']
            actions.Message(mes)
            self.fail("start test with a user profile NOT being VoiceCode")
            

        preserveApps = ['emacs']  #ther adepps are killed after the test
        apps = ['voicecode', 'notepad']
        if not self.doTestBringupApplications(apps, preserveApps, prompt="test_Bringup_voicecode_user_switching"):
            print('test_Bringup_voicecode_user_switching skipped halfway')
            return
        newUser, dummy = natlink.getCurrentUser()
        self.assert_equal('VoiceCode', newUser, "user name should be switched to 'VoiceCode'")
        if user == newUser:
            mes = ['cannot test voicecode user coming from another user',
                   'start test from another user as "VoiceCode"']
            actions.Message(mes)

        natlink.openUser(user)
        newUser, dummy = natlink.getCurrentUser()
        self.assert_equal(user, newUser, "user name should be switched to '%s'\n"
                          "in order to be able to test the user switching part of this test"% user)
        self.doTestBringupApplications(apps, preserveApps, prompt=0)
        newUser, dummy = natlink.getCurrentUser()
        self.assert_equal('VoiceCode', newUser, "user name should be switched to 'VoiceCode', also the second time of testing")
Ejemplo n.º 2
0
    def dumpResult(self, testResult, filesToSkip=None):
        """dump into txt file "testresult" in unimacro_test folder

        slightly different version in voice coder (test_defs.py)
        """
        alert = len(self.activeTests) > 0
        testResultFile = os.path.join(self.testFolder, "testresult.txt")
        f = open(testResultFile, 'w')
        if testResult.wasSuccessful():
            if alert:
                mes = "all succesful: %s" % self.activeTests
                actions.Message(mes, "Unimacro Tests succesful")
            else:
                mes = "test passed: %s" % self.activeTests[0]
                self.DisplayMessage(mes)
            f.write(mes + '\n' * 2)
            f.close()
            return
        f.write("results of tests: %s\n" % self.activeTests)
        f.write('\n--------------- errors -----------------\n')
        for case, tb in testResult.errors:
            f.write('\n---------- %s --------\n' % case)
            cleanTb = utilsqh.cleanTraceback(tb, filesToSkip)
            f.write(cleanTb)
        f.write('\n--------------- failures -----------------\n')
        for case, tb in testResult.failures:
            f.write('\n---------- %s --------\n' % case)
            cleanTb = utilsqh.cleanTraceback(tb, filesToSkip)
            f.write(cleanTb)

        f.close()
        mes = "there were errors with testing unimacro: %s\n\nPlease consult the outputfile: %s"% \
              (self.activeTests, testResultFile)
        actions.Message(mes, "Unimacro Tests failure", alert=alert)
        self.openFileDefault(testResultFile, mode="edit", name='test result')
Ejemplo n.º 3
0
    def offInfo(self, grammar):
        """gives a nice message that the grammar is switched off

        Gives also information on how to switch on.

        """
        name = grammar.getName()
        try:
            t = {
                'nld': [
                    'Grammatica "%s" is uitgeschakeld' % name, '',
                    '"Schakel in %s" om te activeren' % name
                ]
            }[self.language]
            # title = {'nld': 'Grammatica %s'% name}[self.language]
        except KeyError:
            t = [
                'Grammar "%s" is switched off' % name,
                '"Switch On Grammar %s" to activate' % name
            ]
            # title = 'Grammar %s'% name
        if natbj.loadedMessageGrammar:
            t = ';  '.join(t)
            self.DisplayMessage(t)
        else:
            t = t.replace('; ', '\n')
            actions.Message(t)
Ejemplo n.º 4
0
    def test_Should_give_a_message(self):
        mes = "Do you want to do the Message Box tests?"
        result = actions.YesNo(mes, "Starting the MessageTest (Message Box)")
        if not result:
            print('Message Box tests (MessageTest) skipped')
            return


##        for alert,icon in enumerate([16, 32, 48, 64]):
##            mes = '''This is a test message with\n\n\ticon=%s and\n
##                  \talert=%s\n\nplease answer "OK"'''% (icon, alert)
##            actions.Message(mes, "MessageTest", icon=icon, alert=alert)

        actions.Message(
            'This is a the default test message\n\nPlease answer "OK"',
            "MessageTest")

        for alert, icon in enumerate(['information', 'warning', 'critical']):
            if alert:
                mes = '''This is a test message
                         \nicon=%s and
                         \nalert (number of bells ringing)=%s
                         \nPlease answer "OK"''' % (icon, alert)
            else:
                mes = '''This is a test message
                         \n\ticon=%s and
                         \n\tno alert (sound heard)
                         \nPlease answer "OK"''' % icon
            actions.Message(mes, "MessageTest", icon=icon, alert=alert)
        mes = '''Where all of the previous messages correct,
                 \nespecially the icons and the number of alerts?
              '''
        result = actions.YesNo(mes,
                               "Evaluation of MessageTest",
                               icon=icon,
                               alert=alert)
        self.assertEqual(
            True, result,
            "you answered NO to test: %s" % self.squeeze_whitespace(mes))
Ejemplo n.º 5
0
    def gotResults_edit(self, words, fullResults):
        # special case for actions:
        if self.hasCommon(words, 'actions'):
            actions.editActions(comingFrom=self, name="edit actions")
            return
        if self.hasCommon(words, 'spoken forms'):
            actions.Message(
                'Warning: spoken forms lists do NOT refresh automatically.\n\nA restart of NatSpeak is required after you edited the "spokenforms.ini" file'
            )
            spokenforms.editSpokenForms(comingFrom=self,
                                        name="edit spoken forms",
                                        language=self.language)
            return

        grammars = natbj.loadedGrammars
        gramNames = list(grammars.keys())
        gramName = self.hasCommon(words[-1:], gramNames)
        if gramName:
            grammar = grammars[gramName]
            print(f'grammar: {gramName}: {grammar}')
            if self.hasCommon(words, 'grammar'):
                moduleName = grammar.__module__
                print(f'try __module__: {moduleName}')
                if moduleName in sys.modules:
                    module = sys.modules[moduleName]
                else:
                    print(f'not in sys.modules: {moduleName}')
                    return
                filename = module.__file__
                print('open for edit file: ', filename)
                self.openFileDefault(filename,
                                     mode="edit",
                                     name='edit grammar %s' % gramName)
                unimacroutils.setCheckForGrammarChanges(1)
            else:
                # edit the inifile
                try:
                    grammar.switchOn()
                    grammar.editInifile()
                except AttributeError:
                    self.DisplayMessage(
                        'grammar "%s" has no method "editInifile"' % gramName)
                    return
        else:
            print('no grammar name found')
Ejemplo n.º 6
0
 def test_Should_handle_embedded_quotes_and_newlines(self):
     mes = 'Do you want to do the "handle_embedded_quotes_and_newlines" test?'
     result = actions.YesNo(
         mes, 'Starting the handle_embedded_quotes_and_newlines Test')
     if not result:
         print('handle_embedded_quotes_and_newlines (MessageTest) skipped')
         return
     mes1 = 'This has embedded newlines: \n and \\r characters: \r in it:\n' \
           'and embedded quotes: " and \'\n\n\n' \
           'Please answer OK'
     mes2 = 'This has embedded newlines: \n and \\r characters: \r in it:\n' \
           'and embedded quotes: " and \'\n\n\n' \
           'Please answer Yes if there are embedded newlines and quotes in this Dialog and in previous one'
     result = actions.Message(
         mes1, "\"'\n\rhandle_embedded_quotes_and_newlines (MessageTest)")
     result = actions.YesNo(
         mes2,
         "\"\"'\"\r\nhandle_embedded_quotes_and_newlines (MessageTest)")
     self.assertEqual(
         True, result,
         "you answered NO to test: %s" % self.squeeze_whitespace(mes2))
Ejemplo n.º 7
0
    def gotResults_show(self, words, fullResults):
        # special case for actions:
        if self.hasCommon(words, 'actions'):
            actions.showActions(comingFrom=self, name="show actions")
            return
        if self.hasCommon(words, 'spoken forms'):
            spokenforms.showSpokenForms(comingFrom=self,
                                        name="show spoken forms",
                                        language=self.language)
            return
        Exclusive = 0
        if natbj.exclusiveGrammars:
            print('exclusive grammars (+ control) are: %s' %
                  ' '.join(list(natbj.exclusiveGrammars.keys())))
            self.gotResults_showexclusive(words, fullResults)
            return

        grammars = natbj.loadedGrammars
        gramNames = list(grammars.keys())
        print(f'_control, gramNames: {gramNames}')
        gramName = self.hasCommon(words, gramNames)
        if gramName:
            grammar = grammars[gramName]
            if not grammar.isActive:
                # off, show message:
                self.offInfo(grammar)
                return
            if not self.hasCommon(words, 'grammar'):
                grammar.showInifile()
                return

        # now show the grammar in the browser application:
        if gramName:
            name = [gramName]
        else:
            name = words[1:-1]

        All = 1
        if len(name) > 0:
            All = self.hasCommon(words, 'all')
            if All:
                All = 1
        Active = self.hasCommon(words, 'active')
        if Active:
            All = 0
        elif All:
            All = 1

        if len(name) > 0:
            Start = (' '.join(name), [])
        else:
            Start = ()
        # fix state at this moment (in case of Active grammars popup)
        self.BrowsePrepare(Start, All, Exclusive)
        if Active:
            #print 'collect and show active, non-active and non-Unimacro grammars'
            activeGrammars, inactiveGrammars, switchedOffGrammars = [], [], []
            otherGrammars = natlinkmain.loadedFiles.keys()

            print(f'loadedGrammars (natbj): {natbj.loadedGrammars}')
            print(
                f'all active grammars (natlinkmain): {natlinkmain.loadedFiles}'
            )
            allGramNames = self.getUnimacroGrammarNames()
            self.setList('gramnames', allGramNames)
            print(
                f'for being sure, set all active grammars in list "gramnames": "{allGramNames}"'
            )

            for g in natbj.loadedGrammars:
                gram = natbj.loadedGrammars[g]
                result = getattr(gram, 'isActive')
                modName = gram.__module__
                #print 'gram: %s, modName: %s, result: %s'% (gram, modName, result)
                if result:
                    activeGrammars.append(g)
                    if modName in otherGrammars:
                        otherGrammars.remove(modName)
                    else:
                        print('cannot remove from otherGrammars: %s' % modName)
                elif result == 0:
                    maySwitchOn = gram.mayBeSwitchedOn
                    if maySwitchOn:
                        inactiveGrammars.append(g)
                    else:
                        switchedOffGrammars.append(g)
                    #print 'gram: %s, name: %s'% (gram, modName)
                    if modName in otherGrammars:
                        otherGrammars.remove(modName)
                    else:
                        print('cannot remove from otherGrammars: %s' % modName)
            if not activeGrammars:
                msg = 'No Unimacro grammars are active'
            elif activeGrammars == [self.name]:
                msg = 'No grammars are active (apart from "%s")' % self.name
            elif inactiveGrammars or switchedOffGrammars:
                msg = 'Active Unimacro grammars:\n' + ', '.join(activeGrammars)
            else:
                msg = 'All Unimacro grammars are active:\n' + ', '.join(
                    activeGrammars)

            if inactiveGrammars:
                inactive = 'Inactive (but "Switched on") grammars:\n' + ', '.join(
                    inactiveGrammars)
                msg += '\n\n' + inactive

            if switchedOffGrammars:
                switchedoff = '"Switched off" grammars:\n' + ', '.join(
                    switchedOffGrammars)
                msg += '\n\n' + switchedoff

            if otherGrammars:
                other = 'Other grammars (outside Unimacro):\n' + ', '.join(
                    otherGrammars)
                msg = msg + '\n\n' + other
            if activeGrammars and activeGrammars != [self.name]:
                msg = msg + '\n\n' + "Show details of active Unimacro grammars?"
                if not actions.YesNo(msg,
                                     "Active grammars",
                                     icon="information",
                                     defaultToSecondButton=1):
                    return
            else:
                msg = msg + '\n\n' + 'Activate with\n\t"switch on <grammar name>" or \n\t"switch on all grammars".'
                actions.Message(msg,
                                "No active Unimacro grammars",
                                icon="information")
                return

        self.BrowseShow()