Merge lp:~jibel/mago/simple-scan into lp:~mago-contributors/mago/mago-1.0

Proposed by Jean-Baptiste Lallement
Status: Merged
Merged at revision: 136
Proposed branch: lp:~jibel/mago/simple-scan
Merge into: lp:~mago-contributors/mago/mago-1.0
Diff against target: 278 lines (+248/-0)
5 files modified
mago/application/simple_scan.py (+154/-0)
mago/test_suite/simple_scan.py (+20/-0)
simple_scan/README (+19/-0)
simple_scan/simple_scan.py (+32/-0)
simple_scan/simple_scan.xml (+23/-0)
To merge this branch: bzr merge lp:~jibel/mago/simple-scan
Reviewer Review Type Date Requested Status
Nagappan Alagappan Approve
Review via email: mp+40056@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nagappan Alagappan (nagappan) wrote :

In Line # 144, I would just do, waittillguinotexist() as the default timeout is 30 seconds, also we can remove the rest of condition over there.

Thanks

review: Approve
lp:~jibel/mago/simple-scan updated
137. By Jean-Baptiste Lallement

* mago/application/simple_scan.py: rely on default timout in waittillguinotexist() in close()
* Add README

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Thanks for reviewing, I've applied the change you suggested.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'mago/application/simple_scan.py'
2--- mago/application/simple_scan.py 1970-01-01 00:00:00 +0000
3+++ mago/application/simple_scan.py 2010-11-08 09:14:42 +0000
4@@ -0,0 +1,154 @@
5+PACKAGE = "mago"
6+
7+#-*- coding:utf-8 -*-
8+"""
9+This is the "simple_scan" module.
10+
11+This module provides a wrapper for LDTP to make writing Simple_scan tests easier.
12+"""
13+import ooldtp
14+import ldtp
15+import os
16+from .main import Application
17+from ..gconfwrapper import GConf
18+from ..cmd import globals
19+import time
20+import gettext
21+
22+gettext.install (True)
23+gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
24+gettext.textdomain (PACKAGE)
25+t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
26+_ = t.gettext
27+
28+
29+class Simple_scan(Application):
30+ """
31+ simple_scan manages the Simple_scan application.
32+ """
33+
34+ LAUNCHER = 'simple-scan'
35+ LAUNCHER_ARGS = ['test']
36+ WINDOW = 'frmSimpleScan'
37+
38+ BTNCHANGESCANNER = _('btnChangeScanner')
39+ BTNCLOSE = _('btnClose')
40+ BTNNEW = _('btnNew')
41+ BTNROTATELEFT = _('btnRotateLeft')
42+ BTNROTATERIGHT = _('btnRotateRight')
43+ BTNSAVE = _('btnSave')
44+ BTNSCAN = _('btnScan')
45+ BTNSTOP = _('btnStop')
46+ BTNQUITWITHOUTSAVING = _('btnQuitwithoutSaving')
47+
48+ DLGSAVEAS = _('dlgSaveAs...')
49+ DLGWARNING = _('dlgWarning')
50+
51+ MNUABOUT = _('mnuAbout')
52+ MNUALLPAGESFROMFEEDER = _('mnuAllPagesFromFeeder')
53+ MNUCONTENTS = _('mnuContents')
54+ MNUDELETE = _('mnuDelete')
55+ MNUEMAIL = _('mnuEmail')
56+ MNUGETHELPONLINE = _('mnuGetHelpOnline')
57+ MNUMOVELEFT = _('mnuMoveLeft')
58+ MNUMOVERIGHT = _('mnuMoveRight')
59+ MNUNEW = _('mnuNew')
60+ MNUPREFERENCES = _('mnuPreferences')
61+ MNUPRINT = _('mnuPrint')
62+ MNUQUIT = _('mnuQuit')
63+ MNUREPORTAPROBLEM = _('mnuReportaProblem')
64+ MNUROTATECROP = _('mnuRotateCrop')
65+ MNUROTATELEFT = _('mnuRotateLeft')
66+ MNUROTATERIGHT = _('mnuRotateRight')
67+ MNUSAVE = _('mnuSave')
68+ MNUSAVEAS = _('mnuSaveAs')
69+ MNUSINGLEPAGE = _('mnuSinglePage')
70+ MNUSTOPSCAN = _('mnuStopScan')
71+ MNUPHOTO = _('mnuPhoto')
72+ MNUTEXT = _('mnuText')
73+ MNUTRANSLATETHISAPPLICATION = _('mnuTranslateThisApplication')
74+
75+ TXTNAME = _('txtName')
76+
77+ def __init__(self):
78+ Application.__init__(self)
79+ self.main_window = ooldtp.context(self.WINDOW)
80+
81+ def scan(self, scan_type = "text"):
82+ if not Application.is_opened(self):
83+ Application.open(self)
84+
85+ scan_type = scan_type.lower()
86+
87+ if scan_type == 'text' :
88+ self.main_window.click(self.MNUTEXT)
89+ elif scan_type == 'photo':
90+ self.main_window.click(self.MNUPHOTO)
91+ else:
92+ # Unknown type
93+ raise AssertionError("'%': Unknown type\n", scan_type)
94+
95+ rc = self.main_window.click(self.BTNSCAN)
96+ ldtp.wait(20)
97+ return 0
98+
99+ def save(self, filename):
100+ """
101+ It tries to save the current opened buffer to the filename passed as
102+ parameter.
103+
104+ TODO: It does not manage the overwrite dialog yet.
105+
106+ @type filename: string
107+ @param filename: The name of the file to save the buffer to.
108+ """
109+ Application.save(self, self.MNUSAVE)
110+ ooldtp.context(self.name)
111+
112+ ldtp.waittillguiexist(self.DLGSAVEAS)
113+ save_dialog = ooldtp.context(self.DLGSAVEAS)
114+
115+ save_dlg_txt_filename = save_dialog.getchild(self.TXTNAME)
116+ ldtp.wait(2)
117+ save_dlg_txt_filename.settextvalue(filename)
118+
119+ save_dlg_btn_save = save_dialog.getchild(self.BTNSAVE)
120+
121+ save_dlg_btn_save.click()
122+
123+ ldtp.waittillguinotexist(self.DLGSAVEAS)
124+ ldtp.wait(1)
125+
126+ def close(self, save=False, filename=''):
127+ """
128+ Given a gedit window, it tries to close the application.
129+ By default, it closes without saving. This behaviour can be changed to save (or save as) on close.
130+
131+ @type save: boolean
132+ @param save: If True, the edited file will be saved on close.
133+
134+ @type filename: string
135+ @param filename: The file name to save the buffer to
136+ """
137+ # Exit using the Quit menu
138+ app = ooldtp.context(self.name)
139+ quit_menu = app.getchild(self.MNUQUIT)
140+ quit_menu.selectmenuitem()
141+
142+ question_dialog = None
143+ count = 0
144+ while not app.waittillguinotexist():
145+ try:
146+ question_dialog = ooldtp.context(self.DLGWARNING)
147+ except:
148+ pass
149+ else:
150+ break
151+
152+ # If the text has changed, the save dialog will appear
153+ if question_dialog:
154+ question_dlg_btn_close = question_dialog.getchild(self.BTNQUITWITHOUTSAVING)
155+ question_dlg_btn_close.click()
156+
157+ app.waittillguinotexist(guiTimeOut=20)
158+
159
160=== added file 'mago/test_suite/simple_scan.py'
161--- mago/test_suite/simple_scan.py 1970-01-01 00:00:00 +0000
162+++ mago/test_suite/simple_scan.py 2010-11-08 09:14:42 +0000
163@@ -0,0 +1,20 @@
164+"""
165+This module contains the definition of the test suite for Simple_scan testing.
166+"""
167+import ldtp, ooldtp
168+from .main import SingleApplicationTestSuite
169+from ..application.simple_scan import Application, Simple_scan
170+
171+class Simple_scanTestSuite(SingleApplicationTestSuite):
172+ """
173+ Default test suite for Simple_scan
174+ """
175+ APPLICATION_FACTORY = Simple_scan
176+ def setup(self):
177+ self.application.open()
178+
179+ def teardown(self):
180+ self.application.close()
181+
182+ def cleanup(self):
183+ self.application.close()
184
185=== added directory 'simple_scan'
186=== added file 'simple_scan/README'
187--- simple_scan/README 1970-01-01 00:00:00 +0000
188+++ simple_scan/README 2010-11-08 09:14:42 +0000
189@@ -0,0 +1,19 @@
190+Simple-Scan Tests
191+---------------------
192+Tests that verify simple-scan functionality.
193+
194+Safety
195+------
196+None of these tests touches any configuration or system files. They use the sane-test backend to simulate a scan.
197+
198+Configuration
199+-------------
200+Nothing
201+
202+Available Tests
203+---------------
204+
205+* Simple Scan
206+ - Text Scan
207+ - Photo Scan
208+
209
210=== added directory 'simple_scan/data'
211=== added file 'simple_scan/data/photo.jpeg'
212Binary files simple_scan/data/photo.jpeg 1970-01-01 00:00:00 +0000 and simple_scan/data/photo.jpeg 2010-11-08 09:14:42 +0000 differ
213=== added file 'simple_scan/data/text.jpeg'
214Binary files simple_scan/data/text.jpeg 1970-01-01 00:00:00 +0000 and simple_scan/data/text.jpeg 2010-11-08 09:14:42 +0000 differ
215=== added file 'simple_scan/simple_scan.py'
216--- simple_scan/simple_scan.py 1970-01-01 00:00:00 +0000
217+++ simple_scan/simple_scan.py 2010-11-08 09:14:42 +0000
218@@ -0,0 +1,32 @@
219+# -*- coding: utf-8 -*-
220+from os import path
221+from time import time, gmtime, strftime
222+
223+from mago.check import ScreenshotCompare, FAIL
224+from mago.test_suite.simple_scan import Simple_scanTestSuite
225+
226+class Simple_scan(Simple_scanTestSuite):
227+ """ Some basic scan testing """
228+
229+ def test_scan(self, scan_type=None, oracle=None):
230+ test_file = strftime(
231+ "/tmp/" + "%Y%m%d_%H%M%S" + ".jpeg", gmtime((time())))
232+ self.application.scan(scan_type)
233+ self.application.save(test_file)
234+
235+ oracle = path.join(self.get_test_dir(), oracle)
236+ checker = ScreenshotCompare(oracle, test_file)
237+
238+ try:
239+ passed = checker.perform_test()
240+ except Exception, e:
241+ checker.calibrate()
242+ raise e
243+ if passed == FAIL:
244+ raise AssertionError('Scan file differs from reference', test_file)
245+
246+
247+
248+if __name__ == "__main__":
249+ simple_scan_test = Simple_scan()
250+ simple_scan_test.run()
251
252=== added file 'simple_scan/simple_scan.xml'
253--- simple_scan/simple_scan.xml 1970-01-01 00:00:00 +0000
254+++ simple_scan/simple_scan.xml 2010-11-08 09:14:42 +0000
255@@ -0,0 +1,23 @@
256+<?xml version="1.0"?>
257+<suite name="simple_scan">
258+ <class>simple_scan.Simple_scan</class>
259+ <description>
260+ Tests which verify Simple_scan basics scan functionality.
261+ </description>
262+ <case name="Text Scan test">
263+ <method>test_scan</method>
264+ <description>Text Scan test</description>
265+ <args>
266+ <oracle>data/text.jpeg</oracle>
267+ <scan_type>text</scan_type>
268+ </args>
269+ </case>
270+ <case name="Photo Scan test">
271+ <method>test_scan</method>
272+ <description>Photo Scan test</description>
273+ <args>
274+ <oracle>data/photo.jpeg</oracle>
275+ <scan_type>photo</scan_type>
276+ </args>
277+ </case>
278+</suite>

Subscribers

People subscribed via source and target branches

to status/vote changes: