Exemplo n.º 1
0
    def openTestFile(self, filePath, app=None, waitingTime=0.05):
        """open a file in its default window, for testing clipboard.
        
        waitingTime could be needed larger eg for word documents...
        
        Return the handle
        """
        natlinkutilsqh.rememberWindow()
        # app = r"C:\Program Files (x86)\Frescobaldi\frescobaldi.exe"
        # app = r"C:\Program Files (x86)\ActiveState Komodo IDE 11\komodo.exe"
        print 'opening %s (app: %s) sleeptime: %s' % (filePath, app,
                                                      waitingTime)
        result = actions.UnimacroBringUp(app=app, filepath=filePath)
        natlinkutilsqh.waitForNewWindow(debug=True, waitingTime=waitingTime)
        # time.sleep(2)
        fileName = os.path.split(filePath)[-1]
        if not natlinkutilsqh.waitForWindowTitle(fileName,
                                                 waitingTime=waitingTime):
            print 'could not fileName in window title: %s' % fileName
            natlinkutilsqh.returnToWindow()
            return

        curmod = natlinkutilsqh.getCurrentModuleSafe(
        )  # try a few times if it fails first
        print 'opened %s: %s' % (curmod[2], filePath)
        natlinkutilsqh.returnToWindow()
        return curmod[2]
    def test_Should_BringUp_DragonPad(self):

        actions.UnimacroBringUp("dragonpad")
        self.assert_mod_partoftitle('natspeak', 'DragonPad',
                                    " when bringing up DragonPad")
        natut.playString("this should last 2 seconds")
        time.sleep(2)
        actions.do_KW()
    def startEditProgram(self, prog=None):
        global nsHandle
        prog = prog or "dragonpad"
        hndle = actions.UnimacroBringUp(prog)
        if not hndle: return   # wrong
        if prog == 'emacs':
            self.emacsHndle = hndle
            return hndle
	elif prog == 'winword':
	    self.word_handle =hndle
	    return hndle
        else:
            nsHandle = hndle
            return hndle
    def doTestBringupApplications(self, apps, preserveApps, prompt=1):
        """do the testing of bringing up and destroying applications

        switching is done several times, also after killing the window.
        switching with UnimacroBringUp several times is fast and comes back
        to the same window, if not killed in between.

        In these tests the different combinations are checked.        

        """
        destroyApps = [a for a in apps if a not in preserveApps]
        if prompt:
            mes = [
                "Do you want to do the Bringup applications tests?", "",
                'using %s' % apps,
                'keeping open: %s' % preserveApps,
                'destroying after testing: %s' % destroyApps
            ]
            if type(prompt) == types.StringType:
                mes.insert(0, prompt + '\n\n')
            result = actions.YesNo(mes,
                                   "Starting the Bringup applicationsTest ")
            if not result:
                print 'Bringup applications test skipped'
                return

        appString = ', '.join(apps)

        # these should correspond with "name" in [bringup app] section of actions.ini
        # call for edit actions to inspect these:
        expectedMods = dict(zip(apps, apps))
        expectedMods.update(specialMods)

        # bring them up:
        for app in apps:
            result = actions.UnimacroBringUp(app)
            if result:
                self.assert_mod(
                    expectedMods[app],
                    " (round 1) when bringing up %s (%s)" % (app, appString))
            else:
                self.fail(
                    " (round 1) did not get result from switching to app: %s (%s)"
                    % (app, appString))

        # and do it again:
        for app in apps:
            result = actions.UnimacroBringUp(app)
            if result:
                self.assert_mod(
                    expectedMods[app],
                    " (round 2) when bringing up %s (%s)" % (app, appString))
            else:
                self.fail(
                    " (round 2) did not get result from switching to app: %s (%s)"
                    % (app, appString))

            result = actions.UnimacroBringUp(app)
            if result:
                self.assert_mod(
                    expectedMods[app],
                    " (round 2, double!) when bringing up %s (%s)" %
                    (app, appString))
            else:
                self.fail(
                    " (round 2, double!) did not get result from switching to app: %s (%s)"
                    % (app, appString))
        # do it in reverse order, kill the window, except for pythonwin and uedit32 (preserveApps):
        apps.reverse()
        for app in apps:
            result = actions.UnimacroBringUp(app)
            if result:
                self.assert_mod(
                    expectedMods[app],
                    " (round 3) when bringing up %s (%s)" % (app, appString))
            else:
                self.fail(
                    " (round 3, revers order) did not get result from switching to app: %s (%s)"
                    % (app, appString))
            if app not in preserveApps:
                actions.do_KW()
                self.failIf_mod(
                    app, "(round 3) kill window did not succeed for app\n\n"
                    "(THIS MAY BE A TEST ARTEFACT OR A FAILURE OF THE KW (KillWindow) ACTION: %s (%s)"
                    % (app, appString))

        # again reverse order, bringup again and kill the window, except for pythonwin and uedit32:
        for app in apps:
            result = actions.UnimacroBringUp(app)
            if result:
                self.assert_mod(
                    expectedMods[app],
                    " (round 4, after killing previous app)) when bringing up %s (%s)"
                    % (app, appString))
            else:
                self.fail(
                    " (round 4, after killing previous app)) did not get result from switching to app: %s (%s)"
                    % (app, appString))
            if app not in preserveApps:
                actions.do_KW()
                self.failIf_mod(
                    app,
                    "(round 4, after killing previous app)) kill window did not succeed for app: %s (%s)"
                    % (app, appString))
        return 1


# no main statement, run from command in _unimacrotest.py.