Commit d7108c82 authored by Doug Turner's avatar Doug Turner Committed by Commit Bot

Fix up nvda_chrome_tests.py to run under Python 3.

See "Print Is A Function".

Bug: 742592
Change-Id: Ic2744a01a4149a466dab9a7c1208d36238206008
Reviewed-on: https://chromium-review.googlesource.com/599567Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Commit-Queue: Doug Turner <dougt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491681}
parent 3de0561a
#!/usr/bin/env python #!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved. # Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -52,13 +52,13 @@ WAIT_FOR_SPEECH_TIMEOUT_SECS = 3.0 ...@@ -52,13 +52,13 @@ WAIT_FOR_SPEECH_TIMEOUT_SECS = 3.0
class NvdaChromeTest(unittest.TestCase): class NvdaChromeTest(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
print 'user data: %s' % CHROME_PROFILES_PATH print('user data: %s' % CHROME_PROFILES_PATH)
print 'chrome: %s' % CHROME_PATH print('chrome: %s' % CHROME_PATH)
print 'nvda: %s' % NVDA_PATH print('nvda: %s' % NVDA_PATH)
print 'nvda_proctest: %s' % NVDA_PROCTEST_PATH print('nvda_proctest: %s' % NVDA_PROCTEST_PATH)
print print()
print 'Clearing user data directory and log file from previous runs' print('Clearing user data directory and log file from previous runs')
if os.access(NVDA_LOGPATH, os.F_OK): if os.access(NVDA_LOGPATH, os.F_OK):
os.remove(NVDA_LOGPATH) os.remove(NVDA_LOGPATH)
if os.access(CHROME_PROFILES_PATH, os.F_OK): if os.access(CHROME_PROFILES_PATH, os.F_OK):
...@@ -66,7 +66,7 @@ class NvdaChromeTest(unittest.TestCase): ...@@ -66,7 +66,7 @@ class NvdaChromeTest(unittest.TestCase):
os.mkdir(CHROME_PROFILES_PATH, 0777) os.mkdir(CHROME_PROFILES_PATH, 0777)
def handler(signum, frame): def handler(signum, frame):
print 'Test interrupted, attempting to kill subprocesses.' print('Test interrupted, attempting to kill subprocesses.')
self.tearDown() self.tearDown()
sys.exit() sys.exit()
signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGINT, handler)
...@@ -77,16 +77,16 @@ class NvdaChromeTest(unittest.TestCase): ...@@ -77,16 +77,16 @@ class NvdaChromeTest(unittest.TestCase):
'--user-data-dir=%s' % user_data_dir, '--user-data-dir=%s' % user_data_dir,
'--no-first-run', '--no-first-run',
'about:blank'] 'about:blank']
print print()
print ' '.join(args) print(' '.join(args))
self._chrome_proc = subprocess.Popen(args) self._chrome_proc = subprocess.Popen(args)
self._chrome_proc.poll() self._chrome_proc.poll()
if self._chrome_proc.returncode is None: if self._chrome_proc.returncode is None:
print 'Chrome is running' print('Chrome is running')
else: else:
print 'Chrome exited with code', self._chrome_proc.returncode print('Chrome exited with code', self._chrome_proc.returncode)
sys.exit() sys.exit()
print 'Chrome pid: %d' % self._chrome_proc.pid print('Chrome pid: %d' % self._chrome_proc.pid)
os.environ['NVDA_SPECIFIC_PROCESS'] = str(self._chrome_proc.pid) os.environ['NVDA_SPECIFIC_PROCESS'] = str(self._chrome_proc.pid)
...@@ -99,11 +99,11 @@ class NvdaChromeTest(unittest.TestCase): ...@@ -99,11 +99,11 @@ class NvdaChromeTest(unittest.TestCase):
self._nvda_proc = subprocess.Popen(args) self._nvda_proc = subprocess.Popen(args)
self._nvda_proc.poll() self._nvda_proc.poll()
if self._nvda_proc.returncode is None: if self._nvda_proc.returncode is None:
print 'NVDA is running' print('NVDA is running')
else: else:
print 'NVDA exited with code', self._nvda_proc.returncode print('NVDA exited with code', self._nvda_proc.returncode)
sys.exit() sys.exit()
print 'NVDA pid: %d' % self._nvda_proc.pid print('NVDA pid: %d' % self._nvda_proc.pid)
app = pywinauto.application.Application() app = pywinauto.application.Application()
app.connect_(process = self._chrome_proc.pid) app.connect_(process = self._chrome_proc.pid)
...@@ -115,22 +115,22 @@ class NvdaChromeTest(unittest.TestCase): ...@@ -115,22 +115,22 @@ class NvdaChromeTest(unittest.TestCase):
self.tearDown() self.tearDown()
def tearDown(self): def tearDown(self):
print print()
print 'Shutting down' print('Shutting down')
self._chrome_proc.poll() self._chrome_proc.poll()
if self._chrome_proc.returncode is None: if self._chrome_proc.returncode is None:
print 'Killing Chrome subprocess' print('Killing Chrome subprocess')
self._chrome_proc.kill() self._chrome_proc.kill()
else: else:
print 'Chrome already died.' print('Chrome already died.')
self._nvda_proc.poll() self._nvda_proc.poll()
if self._nvda_proc.returncode is None: if self._nvda_proc.returncode is None:
print 'Killing NVDA subprocess' print('Killing NVDA subprocess')
self._nvda_proc.kill() self._nvda_proc.kill()
else: else:
print 'NVDA already died.' print('NVDA already died.')
def _GetSpeechFromNvdaLogFile(self): def _GetSpeechFromNvdaLogFile(self):
"""Return everything NVDA would have spoken as a list of strings. """Return everything NVDA would have spoken as a list of strings.
...@@ -176,12 +176,12 @@ class NvdaChromeTest(unittest.TestCase): ...@@ -176,12 +176,12 @@ class NvdaChromeTest(unittest.TestCase):
break break
if time.time() - start_time >= WAIT_FOR_SPEECH_TIMEOUT_SECS: if time.time() - start_time >= WAIT_FOR_SPEECH_TIMEOUT_SECS:
print '** Speech from NVDA so far:' print('** Speech from NVDA so far:')
for line in lines: for line in lines:
print '"%s"' % line print('"%s"' % line)
print '** Was waiting for:' print('** Was waiting for:')
for line in expected: for line in expected:
print '"%s"' % line print('"%s"' % line)
raise Exception('Timed out') raise Exception('Timed out')
time.sleep(0.1) time.sleep(0.1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment