gedit test utf8 procedural api.py :  » Test » dogtail » dogtail-0.7.0 » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Test » dogtail 
dogtail » dogtail 0.7.0 » examples » gedit-test-utf8-procedural-api.py
#!/usr/bin/env python
# Dogtail demo script

from dogtail.config import config
#config.debugSleep = True
#config.debugSearching = True
#config.debugTranslation = True

import dogtail.tc
from dogtail.procedural import *
from dogtail.utils import screenshot

# These next two lines get us translations for free. To see the script run
# translated, run it like this:
#  LANG=ja_JP.UTF-8 ./gedit-test-utf8-procedural-api.py
# You might also want to set config.debugTranslation and
# config.debugSearching to True, just for fun.
import dogtail.i18n
dogtail.i18n.loadTranslationsFromPackageMoFiles('gedit')

from os import environ,path,remove

# Load our persistent Dogtail objects
TestString = dogtail.tc.TCString()

# Remove the output file, if it's still there from a previous run
if path.isfile(path.join(path.expandvars("$HOME"), "Desktop", "UTF8demo.txt")):
    remove(path.join(path.expandvars("$HOME"), "Desktop", "UTF8demo.txt"))

# Start gedit.
run('gedit')

# Set focus on gedit
focus.application('gedit')

# Focus gedit's text buffer.
focus.text()

# Load the UTF-8 demo file. Use codecs.open() instead of open().
from codecs import open
from sys import path
utfdemo = open(path[0] + '/data/UTF-8-demo.txt')

# Load the UTF-8 demo file into the text buffer.
focus.widget.text = utfdemo.read()

# Take a screenshot of the window
screenshot()

# Click gedit's Save button.
click.button('Save')

# Focus gedit's Save As... dialog
try:
    # This string changed somewhere around gedit 2.13.2.
    # This is the new string
    focus.dialog(u'Save As\u2026')
except FocusError:
    # Fall back to the old string.
    focus.dialog('Save as...')

# click the Browse for other folders widget
focus.widget('Browse for other folders')
if not focus.widget.checked: click()

# Click the Desktop widget
click('Desktop', roleName = 'table cell')

# We want to save to the file name 'UTF8demo.txt'.
focus.text()
focus.widget.text = 'UTF8demo.txt'

# Click the Save button.
click('Save')

# Let's quit now.
click('File')
click('Quit')

# We have driven gedit now lets check to see if the saved file is the same as
# the baseline file

# Read in the "gold" file
import codecs
try:
    # When reading the file, we have to make sure and tell codecs.open() which
    # encoding we're using, otherwise python gets confused later.
    gold = open(path[0] + '/data/UTF-8-demo.txt', encoding='utf-8').readlines()
except IOError:
    print "File open failed"

# Read the test file for comparison
filepath = environ['HOME'] + '/Desktop/UTF8demo.txt'
# When reading the file, we have to make sure and tell codecs.open() which
# encoding we're using, otherwise python gets confused later.
testfile = open(filepath, encoding='utf-8').readlines()

# We now have the original and saved files as lists. Let's compare them line
# by line to see if they are the same
i = 0
for baseline in gold:
    label = "line test " + str(i + 1)
    TestString.compare(label, baseline, testfile[i], encoding='utf-8')
    i = i + 1
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.