[pyatspi2: 1/2] tests: Python3 compatibility
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyatspi2: 1/2] tests: Python3 compatibility
- Date: Tue, 27 Aug 2019 19:40:06 +0000 (UTC)
commit ff19354dd474811ed6c3beb3b2d9c94864cb7132
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date: Tue Aug 27 21:02:47 2019 +0200
tests: Python3 compatibility
pyatspi/state.py | 2 +-
tests/pyatspi/accessibletest.py | 24 +++++++++++++++---------
tests/pyatspi/actiontest.py | 8 ++++----
tests/pyatspi/collectiontest.py | 18 +++++++++---------
tests/pyatspi/componenttest.py | 2 +-
tests/pyatspi/pasytest/Events.py | 8 ++++----
tests/pyatspi/pasytest/Pasy.py | 12 ++++++------
tests/pyatspi/pasytest/__init__.py | 2 +-
tests/pyatspi/relationtest.py | 2 +-
tests/pyatspi/testrunner.in | 12 ++++++------
10 files changed, 48 insertions(+), 42 deletions(-)
---
diff --git a/pyatspi/state.py b/pyatspi/state.py
index 986431a..b934810 100644
--- a/pyatspi/state.py
+++ b/pyatspi/state.py
@@ -135,7 +135,7 @@ STATE_VALUE_TO_NAME = dict(((value, name[6:].lower().replace('_', ' '))
def stateset_init(self, *states):
GObject.GObject.__init__(self)
- map(self.add, states)
+ list(map(self.add, states))
# TODO: Fix pygobject so that this isn't needed (BGO#646581 may be related)
def StateSet_getStates(self):
diff --git a/tests/pyatspi/accessibletest.py b/tests/pyatspi/accessibletest.py
index cf0aff4..2426499 100644
--- a/tests/pyatspi/accessibletest.py
+++ b/tests/pyatspi/accessibletest.py
@@ -35,15 +35,21 @@ st = [pyatspi.STATE_MULTI_LINE,
pyatspi.STATE_SUPPORTS_AUTOCOMPLETION,
pyatspi.STATE_VERTICAL,]
-def _createNode(accessible, parentElement):
+def _createNode(doc, accessible, parentElement):
e = minidom.Element("accessible")
- e.attributes["name"] = accessible.name
- e.attributes["role"] = str(int(accessible.getRole()))
- e.attributes["description"] = accessible.description
+ nameA = doc.createAttribute('name')
+ roleA = doc.createAttribute('role')
+ descA = doc.createAttribute('description')
+ e.setAttributeNode(nameA)
+ e.setAttributeNode(roleA)
+ e.setAttributeNode(descA)
+ e.setAttribute("name", accessible.name)
+ e.setAttribute("role", str(int(accessible.getRole())))
+ e.setAttribute("description", accessible.description)
for i in range(0, accessible.childCount):
- _createNode(accessible.getChildAtIndex(i), e)
+ _createNode(doc, accessible.getChildAtIndex(i), e)
parentElement.appendChild(e)
@@ -77,7 +83,7 @@ class AccessibleTest(_PasyTest):
def setup(self, test):
self._registry = pyatspi.Registry()
self._desktop = self._registry.getDesktop(0)
- self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main"
and x.getRole() == pyatspi.ROLE_WINDOW)
+ self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main" and
x.getRole() == pyatspi.ROLE_WINDOW)
def test_name(self, test):
root = self._root
@@ -130,8 +136,8 @@ class AccessibleTest(_PasyTest):
root = self._root
attr = root.getAttributes()
res = ["foo:bar", "baz:qux", "quux:corge"]
- attr.sort()
- res.sort()
+ attr.sort()
+ res.sort()
test.assertEqual(attr, res, "Attributes expected %s, recieved %s" % (res, attr))
def test_parent(self, test):
@@ -225,7 +231,7 @@ class AccessibleTest(_PasyTest):
root = self._root
doc = minidom.Document()
- _createNode(root, doc)
+ _createNode(doc, root, doc)
answer = doc.toprettyxml()
diff --git a/tests/pyatspi/actiontest.py b/tests/pyatspi/actiontest.py
index 3e6b1c4..0a3bc17 100644
--- a/tests/pyatspi/actiontest.py
+++ b/tests/pyatspi/actiontest.py
@@ -48,14 +48,14 @@ class ActionTest(_PasyTest):
self._registry = pyatspi.Registry()
import time
self._desktop = self._registry.getDesktop(0)
- print "--desktop len", len(self._desktop)
+ print("--desktop len", len(self._desktop))
for i in self._desktop:
try:
- print "-- object",i,i.getRole()
+ print("-- object",i,i.getRole())
except:
pass
- self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main"
and x.getRole() == pyatspi.ROLE_APPLICATION)
- print "--root", self._root
+ self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main" and
x.getRole() == pyatspi.ROLE_APPLICATION)
+ print("--root", self._root)
def test_nActions(self, test):
root = self._root
diff --git a/tests/pyatspi/collectiontest.py b/tests/pyatspi/collectiontest.py
index f052ce2..60fd2a2 100644
--- a/tests/pyatspi/collectiontest.py
+++ b/tests/pyatspi/collectiontest.py
@@ -64,22 +64,22 @@ class AccessibleTest(_PasyTest):
def setup(self, test):
self._registry = pyatspi.Registry()
- print self._path
+ print(self._path)
self._desktop = self._registry.getDesktop(0)
self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main"
and x.getRole() == pyatspi.ROLE_WINDOW)
def assertObjects(self,test,obj,vars,msg):
- test.assertEqual(len(obj), len(vars) / 2, msg + " length")
+ test.assertEqual(len(obj), len(vars) // 2, msg + " length")
for i in range(0, len(vars), 2):
- test.assertEqual (vars[i], obj[i/2].name, msg + "name" + "#" + str(i/2))
- test.assertEqual(vars[i+1], obj[i/2].getRole(), msg + " role" + "#" + str(i/2))
+ test.assertEqual (vars[i], obj[i//2].name, msg + "name" + "#" + str(i//2))
+ test.assertEqual(vars[i+1], obj[i//2].getRole(), msg + " role" + "#" + str(i//2))
- # Used to help add new tests
+ # Used to help add new tests
def printAsserts(self,obj,msg):
- print "\t\tself.assertObjects(test,ret,("
+ print("\t\tself.assertObjects(test,ret,(")
for i in range(0,len(obj)):
- print "\t\t\t\"" + obj[i].name + "\", " + str(obj[i].getRole()) + ","
- print "\t\t), \"", msg, "\")"
+ print("\t\t\t\"" + obj[i].name + "\", " + str(obj[i].getRole()) + ",")
+ print("\t\t), \"", msg, "\")")
def test_basic(self, test):
collection = self._root.queryCollection()
@@ -114,7 +114,7 @@ class AccessibleTest(_PasyTest):
obj=ret[2]
ret = collection.getMatchesTo (obj, rule, collection.SORT_ORDER_REVERSE_CANONICAL,
collection.TREE_INORDER, True, 5, True)
- print "--ret:", len(ret)
+ print("--ret:", len(ret))
self.assertObjects(test,ret,(
"gnome-settings-daemon", 79,
"gnome-panel", 79,
diff --git a/tests/pyatspi/componenttest.py b/tests/pyatspi/componenttest.py
index 99f963f..0f49fe4 100644
--- a/tests/pyatspi/componenttest.py
+++ b/tests/pyatspi/componenttest.py
@@ -65,7 +65,7 @@ class ComponentTest(_PasyTest):
def setup(self, test):
self._registry = pyatspi.Registry()
self._desktop = self._registry.getDesktop(0)
- self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main"
and x.getRole() == pyatspi.ROLE_APPLICATION)
+ self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main" and
x.getRole() == pyatspi.ROLE_APPLICATION)
def test_contains(self, test):
pass
diff --git a/tests/pyatspi/pasytest/Events.py b/tests/pyatspi/pasytest/Events.py
index 10c0393..31e965b 100644
--- a/tests/pyatspi/pasytest/Events.py
+++ b/tests/pyatspi/pasytest/Events.py
@@ -65,17 +65,17 @@ if __name__ == '__main__':
model.events.OnChange += self.DisplayValue
##model.events.OnChange2 += self.DisplayValue # would raise exeception
def DisplayValue(self):
- print self.model.Value
+ print(self.model.Value)
model = ValueModel()
view = SillyView(model)
- print '\n--- Events Demo ---'
+ print('\n--- Events Demo ---')
# Events in action
for i in range(5):
model.Value = 2*i + 1
# Events introspection
- print model.events
+ print(model.events)
for event in model.events:
- print event
+ print(event)
diff --git a/tests/pyatspi/pasytest/Pasy.py b/tests/pyatspi/pasytest/Pasy.py
index c4a09ee..c036d27 100644
--- a/tests/pyatspi/pasytest/Pasy.py
+++ b/tests/pyatspi/pasytest/Pasy.py
@@ -14,7 +14,7 @@
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from gi.repository import GObject, GLib
-from Events import Events
+from .Events import Events
import traceback
@@ -31,7 +31,7 @@ class PasyTestStep(object):
def __init__(self, name):
self.events = PasyEvents()
self._state = PASY_TEST_NOT_STARTED
- self.failMsg = None
+ self.failMsg = None
self._name = name
@@ -79,7 +79,7 @@ class PasyTestFunc(PasyTestStep):
def entry(self):
try:
self._func(self)
- except Exception, e:
+ except Exception as e:
self.fail(e.message)
traceback.print_exc()
self.win()
@@ -96,10 +96,10 @@ class PasyTest(PasyTestStep):
for name in self.__tests__:
func = getattr(self, name)
- self._addfunc(func.func_name, func)
+ self._addfunc(name, func)
def _addfunc(self, name, func):
- functest = PasyTestFunc(func.func_name, func)
+ functest = PasyTestFunc(name, func)
self._tests.append(functest)
def entry(self):
@@ -108,7 +108,7 @@ class PasyTest(PasyTestStep):
def idle_handler(self):
try:
- step = self._iter.next()
+ step = next(self._iter)
def finished_handler():
if step.state == PASY_TEST_WIN or self._cont == True:
GLib.idle_add(self.idle_handler)
diff --git a/tests/pyatspi/pasytest/__init__.py b/tests/pyatspi/pasytest/__init__.py
index 3441237..086d893 100644
--- a/tests/pyatspi/pasytest/__init__.py
+++ b/tests/pyatspi/pasytest/__init__.py
@@ -13,4 +13,4 @@
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-from Pasy import PasyTestStep, PasyTestFunc, PasyTest
+from .Pasy import PasyTestStep, PasyTestFunc, PasyTest
diff --git a/tests/pyatspi/relationtest.py b/tests/pyatspi/relationtest.py
index 858cef5..d531d36 100644
--- a/tests/pyatspi/relationtest.py
+++ b/tests/pyatspi/relationtest.py
@@ -46,7 +46,7 @@ class RelationTest(_PasyTest):
def setup(self, test):
self._registry = pyatspi.Registry()
self._desktop = self._registry.getDesktop(0)
- self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main"
and x.getRole() == pyatspi.ROLE_APPLICATION)
+ self._root = pyatspi.findDescendant (self._desktop, lambda x: x.name == "atspi-test-main" and
x.getRole() == pyatspi.ROLE_APPLICATION)
self._rset = self._root.getRelationSet()
test.assertEqual(len(self._rset), 4, "Num relations expected %d, recieved %d" % (4,
len(self._rset)))
diff --git a/tests/pyatspi/testrunner.in b/tests/pyatspi/testrunner.in
index 3e67a62..765248d 100755
--- a/tests/pyatspi/testrunner.in
+++ b/tests/pyatspi/testrunner.in
@@ -44,12 +44,12 @@ def run_test_app(module_name, dbus_name=None, wait_for_debug=False):
test_module = os.path.join(test_modules_directory, module_name)
if (dbus_name):
- print " ".join([test_application,
+ print(" ".join([test_application,
"--atspi-dbus-name", dbus_name,
"--test-dbus-name", dbus_name,
"--test-atspi-library", test_atspi_library,
"--test-module", test_module,
- "--test-data-directory", test_data_directory,])
+ "--test-data-directory", test_data_directory,]))
pop = Popen([test_application,
"--atspi-dbus-name", dbus_name,
"--test-dbus-name", dbus_name,
@@ -57,10 +57,10 @@ def run_test_app(module_name, dbus_name=None, wait_for_debug=False):
"--test-module", test_module,
"--test-data-directory", test_data_directory,])
else:
- print " ".join([test_application,
+ print(" ".join([test_application,
"--test-atspi-library", test_atspi_library,
"--test-module", test_module,
- "--test-data-directory", test_data_directory,])
+ "--test-data-directory", test_data_directory,]))
pop = Popen([test_application,
"--test-atspi-library", test_atspi_library,
"--test-module", test_module,
@@ -87,7 +87,7 @@ def main(argv):
app = run_test_app(options.test_library, name, wait_for_debug=options.wait)
time.sleep(1)
- print "Started test app on bus name %s" % (name,)
+ print("Started test app on bus name %s" % (name,))
to = bus.get_object(name, "/org/codethink/atspi/test")
test = dbus.Interface(to, "org.codethink.atspi.test")
@@ -103,7 +103,7 @@ def main(argv):
def finished_handler():
loop.quit()
- print "\n" + test_object.report() + "\n"
+ print("\n" + test_object.report() + "\n")
if test_object.failMsg:
sys.exit (1)
test.finish()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]