Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/extensionPoints/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def register(self, handler):
However, the callable must be kept alive by your code otherwise it will be de-registered. This is due to the use
of weak references. This is especially relevant when using lambdas.
"""
# #9720 (Py3 review required): this method causes unittest to fail in Python 3.
if hasattr(handler, "__self__"):
if not handler.__self__:
raise TypeError("Registering unbound instance methods not supported.")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2017 NV Access Limited
#Copyright (C) 2017-2019 NV Access Limited

"""NVDA unit testing.
All unit tests should reside within this package and should be
Expand Down Expand Up @@ -40,7 +40,7 @@ class AppArgs:
# Ideally, this would be an in-memory, default configuration.
# However, config currently requires a path.
# We use the unit test directory, since we want a clean config.
configPath = UNIT_DIR.decode("mbcs")
configPath = UNIT_DIR
secure = False
disableAddons = True
launcher = False
Expand Down Expand Up @@ -80,7 +80,7 @@ class AppArgs:
braille.handler.displaySize=40
braille.handler.enabled = True
# The focus and navigator objects need to be initialized to something.
from objectProvider import PlaceholderNVDAObject,NVDAObjectWithRole
from .objectProvider import PlaceholderNVDAObject,NVDAObjectWithRole
phObj = PlaceholderNVDAObject()
import api
api.setFocusObject(phObj)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_baseObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2018 NV Access Limited, Babbage B.V.
#Copyright (C) 2018-2019 NV Access Limited, Babbage B.V.

"""Unit tests for the baseObject module, its classes and their derivatives."""

import unittest
from baseObject import AutoPropertyObject, ScriptableObject
from objectProvider import PlaceholderNVDAObject
from .objectProvider import PlaceholderNVDAObject
from scriptHandler import script
from abc import abstractmethod

Expand Down Expand Up @@ -137,14 +137,14 @@ class TestAbstractAutoPropertyObjects(unittest.TestCase):
"""

def test_abstractProperty(self):
self.assertRaisesRegexp(TypeError,
self.assertRaisesRegex(TypeError,
"^Can't instantiate abstract class AutoPropertyObjectWithAbstractProperty "
"with abstract methods x",
AutoPropertyObjectWithAbstractProperty
)

def test_subclassedAbstractProperty(self):
self.assertRaisesRegexp(TypeError,
self.assertRaisesRegex(TypeError,
"^Can't instantiate abstract class SubclassedAutoPropertyObjectWithAbstractProperty "
"with abstract methods x",
SubclassedAutoPropertyObjectWithAbstractProperty
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2017 NV Access Limited, Babbage B.V.
#Copyright (C) 2017-2019 NV Access Limited, Babbage B.V.

"""Unit tests for the braille module.
"""

import unittest
import braille
from objectProvider import PlaceholderNVDAObject, NVDAObjectWithRole
from .objectProvider import PlaceholderNVDAObject, NVDAObjectWithRole
import controlTypes
from config import conf
import api
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_brailleTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2018 NV Access Limited, Babbage B.V.
#Copyright (C) 2018-2019 NV Access Limited, Babbage B.V.

"""Unit tests for the brailleTables module.
"""
Expand All @@ -26,5 +26,5 @@ def test_tableExistence(self):
def test_renamedTableExistence(self):
"""Tests whether all defined renamed tables are part of the actual list of tables."""
tableNames = [table.fileName for table in brailleTables.listTables()]
for name in brailleTables.RENAMED_TABLES.itervalues():
for name in brailleTables.RENAMED_TABLES.values():
self.assertIn(name, tableNames)
6 changes: 3 additions & 3 deletions tests/unit/test_controlTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2017 NV Access Limited, Babbage B.V.
#Copyright (C) 2017-2019 NV Access Limited, Babbage B.V.

"""Unit tests for the controlTypes module.
"""
Expand All @@ -15,13 +15,13 @@ class TestLabels(unittest.TestCase):

def test_roleLabels(self):
"""Test to check whether every role has its own label in controlTypes.roleLabels"""
for name, const in controlTypes.__dict__.iteritems():
for name, const in vars(controlTypes).items():
if name.startswith("ROLE_"):
self.assertIsNotNone(controlTypes.roleLabels.get(const),msg="{name} has no label".format(name=name))

def test_positiveStateLabels(self):
"""Test to check whether every state has its own label in controlTypes.stateLabels"""
for name, const in controlTypes.__dict__.iteritems():
for name, const in vars(controlTypes).items():
if name.startswith("STATE_"):
self.assertIsNotNone(controlTypes.stateLabels.get(const),msg="{name} has no label".format(name=name))

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_extensionPoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2017 NV Access Limited
#Copyright (C) 2017-2019 NV Access Limited

"""Unit tests for the extensionPoints module.
"""
Expand Down Expand Up @@ -335,6 +335,8 @@ def test_registerInstanceMethod(self):
actual = list(self.reg.handlers)
self.assertEqual(actual, [inst.method])

# #9720 (Py3 review required): for some reason, this test keeps failing, so mark this as expected failure for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to the register method in extensionPoints. That code really needs a revisit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python3, unbound methods no longer exist. Rather, fetching a method from a class directly (I.e. not from an instance) gives you back a normal function.
In the case of register: it will handle these as normal functions, and succeed.
I don't believe this would cause any problems for us: the handler will be called later like any normal function, as far as it makes sense to call an unbound method function. I.e. the code registering this function would have to pass in self as one of its arguments to make the function work in any meaningful way.
We could argue that we should disallow registering unbound method functions still, but there is no way of detecting these -- they are just functions.
I am happy to leave this in the code as a disabled test and approve/merge this as is. Though I would be interested in thoughts from @jcsteh on this. Should we just remove the test?

@unittest.expectedFailure
def test_registerUnboundInstanceMethod_raisesException(self):
unboundInstMethod = ExampleClass.method
with self.assertRaises(TypeError):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_scriptHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2018 NV Access Limited, Babbage B.V.
#Copyright (C) 2018-2019 NV Access Limited, Babbage B.V.

"""Unit tests for the scriptHandler module."""

Expand All @@ -29,7 +29,7 @@ def script_test(self, gesture):

self.assertEqual(script_test.__doc__, "description")
self.assertEqual(script_test.category, SCRCAT_MISC)
self.assertItemsEqual(script_test.gestures, ["kb:a", "kb:b", "kb:c"])
self.assertCountEqual(script_test.gestures, ["kb:a", "kb:b", "kb:c"])
self.assertTrue(script_test.canPropagate)
self.assertTrue(script_test.bypassInputHelp)
self.assertEqual(script_test.resumeSayAllMode, CURSOR_CARET)
4 changes: 2 additions & 2 deletions tests/unit/textProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2017 NV Access Limited
#Copyright (C) 2017-2019 NV Access Limited

"""Fake text provider implementation for testing of code which uses TextInfos.
See the L{BasicTextProvider} class.
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self, text=None, selection=(0, 0)):
@type selection: tuple of (int, int)
"""
super(BasicTextProvider, self).__init__()
self.basicText = unicode(text)
self.basicText = text
self.selectionOffsets = selection

def makeTextInfo(self, position):
Expand Down