[eog] tests: allow tests to use translations
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] tests: allow tests to use translations
- Date: Thu, 24 Jul 2014 14:46:00 +0000 (UTC)
commit 2284141dfc691d1f3fb5bf3b204100714a25ff86
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Thu Jul 24 16:42:34 2014 +0200
tests: allow tests to use translations
Instead of looking for specified string first try to translate it to current language (set via
LANG env)
tests/common_steps.py | 42 +++++++++++++++++++++++-----
tests/steps/steps.py | 73 +++++++++++++++++++++++++++++++++---------------
2 files changed, 84 insertions(+), 31 deletions(-)
---
diff --git a/tests/common_steps.py b/tests/common_steps.py
index 3fdffe9..a0f6fb6 100644
--- a/tests/common_steps.py
+++ b/tests/common_steps.py
@@ -5,7 +5,7 @@ if isA11yEnabled() is False:
from time import time, sleep
from functools import wraps
-from os import strerror, errno, kill, system, path, getcwd
+from os import strerror, errno, kill, system, path, getcwd, environ
from signal import signal, alarm, SIGALRM, SIGKILL
from subprocess import Popen
from behave import step
@@ -15,6 +15,7 @@ from dogtail.rawinput import keyCombo, absoluteMotion, pressKey
from dogtail.tree import root
from dogtail.utils import run
from dogtail.predicate import GenericPredicate
+from dogtail import i18n
import pyatspi
@@ -206,7 +207,7 @@ def select_folder_in_dialog(context, name):
@step(u'file select dialog with name "{name}" is displayed')
def has_files_select_dialog_with_name(context, name):
- context.app.dialog = context.app.child(name=name,
+ context.app.dialog = context.app.child(name=translate(name),
roleName='file chooser')
@@ -215,31 +216,56 @@ def has_files_select_dialog(context):
context.execute_steps(
u'Then file select dialog with name "Select Files" is displayed')
+
@step(u'In file select dialog select "{name}"')
def select_file_in_dialog(context, name):
# Find an appropriate button to click
# It will be either 'Home' or 'File System'
- home_folder = context.app.dialog.findChild(GenericPredicate(name='Home'),
+ home_folder = context.app.dialog.findChild(GenericPredicate(name=translate('Home')),
retry=False,
requireResult=False)
if home_folder:
home_folder.click()
else:
- context.app.dialog.childNamed('File System').click()
- location_button = context.app.dialog.child('Enter Location')
+ context.app.dialog.childNamed(translate('File System')).click()
+ location_button = context.app.dialog.child(translate('Enter Location'))
if not pyatspi.STATE_SELECTED in location_button.getState().getStates():
location_button.click()
- context.app.dialog.childLabelled('Location:').set_text_contents(name)
+ location_text = context.app.dialog.child(roleName='text')
+ location_text.set_text_contents(name)
sleep(0.2)
- context.app.dialog.childLabelled('Location:').grab_focus()
+ location_text.grab_focus()
keyCombo('<Enter>')
assert wait_until(lambda x: x.dead, context.app.dialog), "Dialog was not closed"
@step(u'In file save dialog save file to "{path}" clicking "{button}"')
def file_save_to_path(context, path, button):
- context.app.dialog.childLabelled('Name:').set_text_contents(path)
+ context.app.dialog.childLabelled(translate('Name:')).set_text_contents(path)
context.app.dialog.childNamed(button).click()
assert wait_until(lambda x: x.dead, context.app.dialog), "Dialog was not closed"
+
+
+ step(u'Set locale to "{locale}"')
+def set_locale_to(context, locale):
+ environ['LANG'] = locale
+ i18n.translationDbs = []
+ i18n.loadTranslationsFromPackageMoFiles('eog')
+ i18n.loadTranslationsFromPackageMoFiles('gtk30')
+
+ context.current_locale = locale
+ context.screenshot_counter = 0
+
+
+def translate(string):
+ translation = i18n.translate(string)
+ if translation == []:
+ translation = string
+ else:
+ if len(translation) > 1:
+ print("Options for '%s'" % string)
+ print(translation)
+ translation = translation[-1].decode('utf-8')
+ return translation
diff --git a/tests/steps/steps.py b/tests/steps/steps.py
index 9010c5d..452b832 100644
--- a/tests/steps/steps.py
+++ b/tests/steps/steps.py
@@ -1,31 +1,33 @@
# -*- coding: UTF-8 -*-
from behave import step, then
-from dogtail.tree import root
-from dogtail.rawinput import typeText
from common_steps import *
from time import sleep
from dogtail.rawinput import keyCombo
from subprocess import Popen, PIPE
+from dogtail import i18n
@step(u'Open About dialog')
def open_about_dialog(context):
- context.app.menu('Help').click()
- context.app.menu('Help').menuItem('About').click()
- context.about_dialog = context.app.dialog('About Image Viewer')
+ context.app.menu(translate('Help')).click()
+ context.app.menu(translate('Help')).menuItem(translate('About')).click()
+ context.about_dialog = context.app.dialog(translate('About Image Viewer'))
+
@then(u'Website link to wiki is displayed')
def website_link_to_wiki_is_displayed(context):
- assert context.about_dialog.child('Website').showing
+ assert context.about_dialog.child(translate('Website')).showing
+
@then(u'GPL 2.0 link is displayed')
def gpl_license_link_is_displayed(context):
- assert context.about_dialog.child("Image Viewer").showing, "App name is not displayed"
- assert context.about_dialog.child("The GNOME image viewer.").showing, "App description is not
displayed"
- assert context.about_dialog.child("Website").showing, "Website link is not displayed"
- assert context.about_dialog.child(roleName='radio button', name="About").checked, "About tab is not
selected"
- assert not context.about_dialog.child(roleName='radio button', name="Credits").checked, "Credits tab
is selected"
+ assert context.about_dialog.child(translate("Image Viewer")).showing, "App name is not displayed"
+ assert context.about_dialog.child(translate("The GNOME image viewer.")).showing, "App description is not
displayed"
+ assert context.about_dialog.child(translate("Website")).showing, "Website link is not displayed"
+ assert context.about_dialog.child(roleName='radio button', name=translate("About")).checked, "About tab
is not selected"
+ assert not context.about_dialog.child(roleName='radio button', name=translate("Credits")).checked,
"Credits tab is selected"
+
@step(u'Open "{filename}" via menu')
def open_file_via_menu(context, filename):
@@ -36,16 +38,17 @@ def open_file_via_menu(context, filename):
""" % filename)
sleep(0.5)
+
@then(u'image size is {width:d}x{height:d}')
def image_size_is(context, width, height):
for attempt in xrange(0, 10):
- width_text = context.app.child(roleName='page tab list').child('Width:').parent.children[-1].text
+ width_text = context.app.child(roleName='page tab
list').child(translate('Width:')).parent.children[-1].text
if width_text == '':
sleep(0.5)
continue
else:
break
- height_text = context.app.child(roleName='page tab list').child('Height:').parent.children[-1].text
+ height_text = context.app.child(roleName='page tab
list').child(translate('Height:')).parent.children[-1].text
try:
actual_width = int(width_text.split(' ')[0])
actual_height = int(height_text.split(' ')[0])
@@ -54,9 +57,17 @@ def image_size_is(context, width, height):
assert actual_width == width
assert actual_height == height
+
@step(u'Rotate the image clockwise')
def rotate_image_clockwise(context):
- context.app.child(roleName='tool bar').child('Right').click()
+ context.app.child(roleName='tool bar').child(translate('Right')).click()
+
+
+ step(u'Open context menu for current image')
+def open_context_menu(context):
+ context.app.child(roleName='drawing area').click(button=3)
+ sleep(0.1)
+
@step(u'Select "{item}" from context menu')
def select_item_from_context_menu(context, item):
@@ -64,6 +75,7 @@ def select_item_from_context_menu(context, item):
sleep(0.1)
context.app.child(roleName='window').menuItem(item).click()
+
@then(u'sidepanel is {state:w}')
def sidepanel_displayed(context, state):
sleep(0.5)
@@ -71,9 +83,11 @@ def sidepanel_displayed(context, state):
actual = context.app.child(roleName='page tab list').showing
assert actual == (state == 'displayed')
+
def app_is_not_fullscreen(context):
import ipdb; ipdb.set_trace()
+
@then(u'application is {negative:w} fullscreen anymore')
@then(u'application is displayed fullscreen')
def app_displayed_fullscreen(context, negative=None):
@@ -81,13 +95,16 @@ def app_displayed_fullscreen(context, negative=None):
actual = not context.app.child(roleName='menu bar').showing
assert actual == (negative is None)
+
@step(u'Wait a second')
def wait_a_second(context):
sleep(1)
+
@step(u'Click "Hide" in wallpaper popup')
def hide_wallapper_popup(context):
- context.app.button('Hide').click()
+ context.app.button(translate('Hide')).click()
+
@then(u'wallpaper is set to "{filename}"')
def wallpaper_is_set_to(context, filename):
@@ -95,37 +112,47 @@ def wallpaper_is_set_to(context, filename):
actual_filename = wallpaper_path.split('/')[-1].split("'")[0]
assert filename == actual_filename
+
@then(u'"{filename}" file exists')
def file_exists(context, filename):
assert os.path.isfile(os.path.expanduser(filename))
+
@then(u'image type is "{mimetype}"')
def image_type_is(context, mimetype):
- imagetype = context.app.child(roleName='page tab list').child('Type:').parent.children[-1].text
+ imagetype = context.app.child(roleName='page tab
list').child(translate('Type:')).parent.children[-1].text
assert imagetype == mimetype
+
@step(u'Select "{menu}" menu')
def select_menuitem(context, menu):
menu_item = menu.split(' -> ')
# First level menu
- current = context.app.menu(menu_item[0])
+ current = context.app.menu(translate(menu_item[0]))
current.click()
if len(menu_item) == 1:
return
# Intermediate menus - point them but don't click
for item in menu_item[1:-1]:
- current = context.app.menu(item)
+ current = context.app.menu(translate(item))
current.point()
# Last level menu item
- current.menuItem(menu_item[-1]).click()
+ current.menuItem(translate(menu_item[-1])).click()
+
+
+ step(u'Select and close "{menu}" menu')
+def select_menuitem_and_close_it(context, menu):
+ context.execute_steps('* Select "%s" menu' % menu)
+ keyCombo("<Esc>")
+
@step(u'Open "Image -> Save As" menu')
def open_save_as_menu(context):
- context.app.menu("Image").click()
- context.app.menu("Image").findChildren(lambda x: 'Save As' in x.name)[0].click()
+ context.app.menu(translate("Image")).click()
+ context.app.menu(translate("Image")).findChildren(lambda x: 'Save As' in x.name)[0].click()
+
@step(u'Select "{name}" window')
def select_name_window(context, name):
- context.app = context.app.child(roleName='frame', name=name)
+ context.app = context.app.child(roleName='frame', name=translate(name))
context.app.grab_focus()
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]