[orca] More work on the test harness
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] More work on the test harness
- Date: Fri, 6 Dec 2013 19:09:31 +0000 (UTC)
commit 569ae2854b570393d1c37dce2b411b7672b93855
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Mon Dec 2 13:35:31 2013 -0500
More work on the test harness
src/orca/braille.py | 7 +-
src/orca/logger.py | 99 ++++++++++-----------------------
src/orca/orca.py | 5 ++
src/orca/speech.py | 26 +-------
test/harness/runone.sh | 2 +-
test/harness/runorca.py | 58 ++++++++++++++++++-
test/harness/utils.py | 11 +++-
test/keystrokes/firefox/bug_511389.py | 18 ++++--
8 files changed, 121 insertions(+), 105 deletions(-)
---
diff --git a/src/orca/braille.py b/src/orca/braille.py
index 7da3c48..20813d8 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -31,9 +31,6 @@ __date__ = "$Date$"
__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
__license__ = "LGPL"
-import logging
-log = logging.getLogger("braille")
-
import signal
import os
@@ -71,8 +68,12 @@ from . import brltablenames
from . import cmdnames
from . import debug
from . import eventsynthesizer
+from . import logger
from . import orca_state
+_logger = logger.getLogger()
+log = _logger.newLog("braille")
+
# Right now, the orca autogen.sh/configure needs a priori knowledge of
# where the liblouis tables are. When running autogen.sh/configure,
# orca_platform.py:tablesdir will be set to point to the liblouis table
diff --git a/src/orca/logger.py b/src/orca/logger.py
index d5bf6ad..0f779a4 100644
--- a/src/orca/logger.py
+++ b/src/orca/logger.py
@@ -28,86 +28,47 @@ __date__ = "$Date$"
__copyright__ = "Copyright (c) 2012 Igalia, S.L."
__license__ = "LGPL"
-import logging
import io
-
-from . import debug
+import logging
class Logger:
- def __init__(self, *types):
- self._types = types or ['braille', 'speech']
- self._fileHandlers = {}
- self._streamHandlers = {}
- self._formatter = logging.Formatter('%(message)s')
-
- def setDebug(self, debugFile, debugLevel):
- if debug.debugFile:
- debug.debugFile.close()
- debug.debugFile = None
- if debugFile:
- debug.debugFile = open('%s.debug' % debugFile, 'w')
- debug.debugLevel = debugLevel
+ def __init__(self):
+ self._logs = {}
- def setLogFile(self, logFile):
- self._closeFileHandlers()
- self._createFileHandlers(logFile)
+ def getLogNames(self):
+ return self._logs.keys()
- def startRecording(self):
- self._closeStreamHandlers()
- self._createStreamHandlers()
+ def newLog(self, name, level=logging.INFO):
+ log = logging.getLogger(name)
+ log.setLevel(level)
- def stopRecording(self):
- return self._closeStreamHandlers()
-
- def _createFileHandlers(self, fileName):
- if not fileName:
- return
+ handler = logging.StreamHandler(io.StringIO())
+ handler.setFormatter(logging.Formatter('%(message)s'))
+ log.addHandler(handler)
- for logger in self._types:
- handler = logging.FileHandler('%s.%s' % (fileName, logger), 'w')
- self._fileHandlers[logger] = handler
- log = logging.getLogger(logger)
- self._createHandler(log, handler)
+ self._logs[name] = handler.stream
+ return log
- def _createStreamHandlers(self):
- for logger in self._types:
- stringIO = io.StringIO()
- handler = logging.StreamHandler(stringIO)
- self._streamHandlers[logger] = [stringIO, handler]
- log = logging.getLogger(logger)
- self._createHandler(log, handler)
+ def clearLog(self, name):
+ stream = self._logs.get(name)
+ if stream:
+ stream.truncate(0)
+ stream.seek(0)
- def _createHandler(self, log, handler):
- handler.setFormatter(self._formatter)
- log.setLevel(logging.INFO)
- log.addHandler(handler)
+ def getLogContent(self, name):
+ stream = self._logs.get(name)
+ if stream:
+ return stream.getvalue()
- def _closeFileHandlers(self):
- for logger in self._types:
- log = logging.getLogger(logger)
- handler = self._fileHandlers.get(logger)
- self._closeHandler(log, handler)
+ return ""
- def _closeStreamHandlers(self):
- result = ''
- for logger in self._types:
- log = logging.getLogger(logger)
- stringIO, handler = self._streamHandlers.get(logger, (None, None))
- self._closeHandler(log, handler)
- if stringIO:
- try:
- result += stringIO.getvalue()
- stringIO.close()
- except ValueError:
- pass
+ def shutdown(self):
+ for name in self._logs.keys():
+ stream = self._logs.get(name)
+ stream.close()
- return result
+_logger = Logger()
- def _closeHandler(self, log, handler):
- try:
- handler.flush()
- handler.close()
- log.removeHandler(handler)
- except:
- pass
+def getLogger():
+ return _logger
diff --git a/src/orca/orca.py b/src/orca/orca.py
index bf4ec1c..01210fd 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -60,6 +60,7 @@ except:
from . import braille
from . import debug
from . import event_manager
+from . import logger
from . import messages
from . import notification_messages
from . import orca_state
@@ -73,6 +74,7 @@ from .input_event import KeyboardEvent
_eventManager = event_manager.getManager()
_scriptManager = script_manager.getManager()
_settingsManager = settings_manager.getManager()
+_logger = logger.getLogger()
try:
# If we don't have an active desktop, we will get a RuntimeError.
@@ -92,6 +94,9 @@ def onEnabledChanged(gsetting, key):
def getSettingsManager():
return _settingsManager
+def getLogger():
+ return _logger
+
EXIT_CODE_HANG = 50
# The user-settings module (see loadUserSettings).
diff --git a/src/orca/speech.py b/src/orca/speech.py
index 20455a2..febc601 100644
--- a/src/orca/speech.py
+++ b/src/orca/speech.py
@@ -27,14 +27,13 @@ __copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
__license__ = "LGPL"
import importlib
-import logging
-log = logging.getLogger("speech")
import re
import time
from . import chnames
from . import debug
+from . import logger
from . import orca_state
from . import settings
from . import sound
@@ -42,6 +41,9 @@ from . import speech_generator
from .acss import ACSS
+_logger = logger.getLogger()
+log = _logger.newLog("speech")
+
# The speech server to use for all speech operations.
#
_speechserver = None
@@ -307,10 +309,6 @@ def stop():
def updateCapitalizationStyle(script=None, inputEvent=None):
if _speechserver:
_speechserver.updateCapitalizationStyle()
- else:
- logLine = "SPEECH OUTPUT: 'capitalization style' updated"
- debug.println(debug.LEVEL_INFO, logLine)
- log.info(logLine)
return True
@@ -319,20 +317,12 @@ def updatePunctuationLevel(script=None, inputEvent=None):
if _speechserver:
_speechserver.updatePunctuationLevel()
- else:
- logLine = "SPEECH OUTPUT: 'punctuation level' updated"
- debug.println(debug.LEVEL_INFO, logLine)
- log.info(logLine)
return True
def increaseSpeechRate(script=None, inputEvent=None):
if _speechserver:
_speechserver.increaseSpeechRate()
- else:
- logLine = "SPEECH OUTPUT: 'faster'"
- debug.println(debug.LEVEL_INFO, logLine)
- log.info(logLine)
return True
@@ -349,20 +339,12 @@ def decreaseSpeechRate(script=None, inputEvent=None):
def increaseSpeechPitch(script=None, inputEvent=None):
if _speechserver:
_speechserver.increaseSpeechPitch()
- else:
- logLine = "SPEECH OUTPUT: 'higher'"
- debug.println(debug.LEVEL_INFO, logLine)
- log.info(logLine)
return True
def decreaseSpeechPitch(script=None, inputEvent=None):
if _speechserver:
_speechserver.decreaseSpeechPitch()
- else:
- logLine = "SPEECH OUTPUT: 'lower'"
- debug.println(debug.LEVEL_INFO, logLine)
- log.info(logLine)
return True
diff --git a/test/harness/runone.sh b/test/harness/runone.sh
index 8dbb8ae..ebf9ab2 100755
--- a/test/harness/runone.sh
+++ b/test/harness/runone.sh
@@ -163,7 +163,7 @@ if [ $orcaRunning -eq 0 ]
then
# Run orca and let it settle in.
#echo starting Orca...
- orca --user-prefs `pwd`&
+ $harnessDir/runorca.py --user-prefs `pwd`&
sleep $WAIT_TIME
fi
diff --git a/test/harness/runorca.py b/test/harness/runorca.py
old mode 100644
new mode 100755
index 1cf5674..39e6356
--- a/test/harness/runorca.py
+++ b/test/harness/runorca.py
@@ -1,2 +1,56 @@
-import orca.orca
-orca.orca.main()
+#!/usr/bin/python3
+
+# N.B. Orca's only use of dbus-python is this logger service which is only
+# used by the regression tests. It does not introduce a dependency, is not
+# encountered by end users, and will be removed in favor for pygi once bugs
+# 656325 and 656330 are resolved.
+
+import argparse
+import dbus
+import dbus.service
+import sys
+
+from orca import orca
+from dbus.mainloop.glib import DBusGMainLoop
+
+class LoggerService(dbus.service.Object):
+
+ def __init__(self):
+ self._logger = orca.getLogger()
+
+ DBusGMainLoop(set_as_default=True)
+ busname = dbus.service.BusName('org.gnome.Orca', bus=dbus.SessionBus())
+ dbus.service.Object.__init__(self, busname, '/org/gnome/Orca')
+
+ @dbus.service.method(dbus_interface='org.gnome.Orca.Logger', in_signature='', out_signature='')
+ def startRecording(self):
+ names = self._logger.getLogNames()
+ for name in names:
+ self._logger.clearLog(name)
+
+ @dbus.service.method(dbus_interface='org.gnome.Orca.Logger', in_signature='', out_signature='s')
+ def stopRecording(self):
+ contents = ''
+ names = self._logger.getLogNames()
+ for name in names:
+ contents += self._logger.getLogContent(name)
+
+ return contents
+
+def main():
+ sys.argv[0] = 'orca'
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-u", "--user-prefs", action="store")
+ args = parser.parse_args()
+
+ manager = orca.getSettingsManager()
+ manager.activate(args.user_prefs)
+ sys.path.insert(0, manager.getPrefsDir())
+
+ service = LoggerService()
+
+ return orca.main()
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/test/harness/utils.py b/test/harness/utils.py
index 39c2c5b..821e4d3 100644
--- a/test/harness/utils.py
+++ b/test/harness/utils.py
@@ -3,8 +3,15 @@ sure your PYTHONPATH includes the directory containing this
file in order for the tests that use it to work. The test
harness does that automatically for you."""
-import orca.logger as logger
-testLogger = logger.Logger()
+from gi.repository import Gio
+testLogger = Gio.DBusProxy.new_for_bus_sync(
+ Gio.BusType.SESSION,
+ Gio.DBusProxyFlags.NONE,
+ None,
+ 'org.gnome.Orca',
+ '/org/gnome/Orca',
+ 'org.gnome.Orca.Logger',
+ None)
# Where to find Dojo tests.
#
diff --git a/test/keystrokes/firefox/bug_511389.py b/test/keystrokes/firefox/bug_511389.py
index 8bbf837..2171233 100644
--- a/test/keystrokes/firefox/bug_511389.py
+++ b/test/keystrokes/firefox/bug_511389.py
@@ -33,7 +33,9 @@ sequence.append(utils.AssertPresentationAction(
"Top of file",
["BRAILLE LINE: 'Hello world, this is a test.'",
" VISIBLE: 'Hello world, this is a test.', cursor=1",
- "SPEECH OUTPUT: 'Hello world link , this is a test.'"]))
+ "SPEECH OUTPUT: 'Hello world'",
+ "SPEECH OUTPUT: 'link'",
+ "SPEECH OUTPUT: ', this is a test. '"]))
########################################################################
# Down Arrow to the link.
@@ -42,10 +44,12 @@ sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
"Line Down",
- ["BRAILLE LINE: 'Foo'",
+ ["BRAILLE LINE: 'Hello world, this is a test.'",
+ " VISIBLE: 'Hello world, this is a test.', cursor=1",
+ "BRAILLE LINE: 'Foo'",
" VISIBLE: 'Foo', cursor=1",
- "SPEECH OUTPUT: 'Foo link ",
- "'"]))
+ "SPEECH OUTPUT: 'Foo'",
+ "SPEECH OUTPUT: 'link'"]))
########################################################################
# Tab forward.
@@ -56,7 +60,8 @@ sequence.append(utils.AssertPresentationAction(
"Tab",
["BRAILLE LINE: 'Bar'",
" VISIBLE: 'Bar', cursor=1",
- "SPEECH OUTPUT: 'Bar link'"]))
+ "SPEECH OUTPUT: 'Bar'",
+ "SPEECH OUTPUT: 'link'"]))
########################################################################
# Shift+Tab back. The bug was that we weren't speaking the link in
@@ -68,7 +73,8 @@ sequence.append(utils.AssertPresentationAction(
"Shift Tab",
["BRAILLE LINE: 'Foo'",
" VISIBLE: 'Foo', cursor=1",
- "SPEECH OUTPUT: 'Foo link'"]))
+ "SPEECH OUTPUT: 'Foo'",
+ "SPEECH OUTPUT: 'link'"]))
########################################################################
# Move to the location bar by pressing Control+L. When it has focus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]