Unittests/Python 3: update syntax, catch unbound method registration test in extension points as expected failure - #9726
Conversation
…nverting it into Unicode first. Re nvaccess#9720.
…l. Re nvaccess#9720. Python 2's unittest documentation states self.assertItemsEqual is replaced by self.assertCountEqual in Python 3, thus follow this directive.
…test as expected failure. Re nvaccess#9720. For some reason unbound method registration test keeps failing in Python 3. Until this is resolved, mark this test as expected failure.
…RaisesRegex due to deprecation warning. Re nvaccess#9720.
|
Hi, Note that some tests will throw errors because itertools.izip is missing in Python 3. I'll correct this issue in a follow-up pull request later today. Thanks. |
|
|
||
| def test_abstractProperty(self): | ||
| self.assertRaisesRegexp(TypeError, | ||
| # #9720 (Py3 review required): self.assertRaisesRegexp is deprecated. |
There was a problem hiding this comment.
I think this is just a rename, so this comment isn't necessary to go in eventually.
|
|
||
| def test_subclassedAbstractProperty(self): | ||
| self.assertRaisesRegexp(TypeError, | ||
| # #9720 (Py3 review required): self.assertRaisesRegexp is deprecated. |
| 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 controlTypes.__dict__.items(): |
There was a problem hiding this comment.
I think I prefer this to be changed as follows while at it
| for name, const in controlTypes.__dict__.items(): | |
| for name, const in vars(controlTypes).items(): |
| 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 controlTypes.__dict__.items(): |
| 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. |
There was a problem hiding this comment.
Please add a comment to the register method in extensionPoints. That code really needs a revisit.
There was a problem hiding this comment.
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?
| self.assertEqual(script_test.__doc__, "description") | ||
| self.assertEqual(script_test.category, SCRCAT_MISC) | ||
| self.assertItemsEqual(script_test.gestures, ["kb:a", "kb:b", "kb:c"]) | ||
| # #9720 (Py3 review required): self.assertItemsEqual -> self.assertCountEqual. |
There was a problem hiding this comment.
Again as above, I don't think this should be in the eventual code of this pr if we just take the rename for granted.
|
Hi, done. Thanks.
From: Leonard de Ruijter <notifications@github.com>
Sent: Wednesday, June 12, 2019 12:13 PM
To: nvaccess/nvda <nvda@noreply.github.com>
Cc: Joseph Lee <joseph.lee22590@gmail.com>; Author <author@noreply.github.com>
Subject: Re: [nvaccess/nvda] Unittests/Python 3: update syntax, catch unbound method registration test in extension points as expected failure (#9726)
@LeonarddeR requested changes on this pull request.
_____
In tests/unit/test_baseObject.py <#9726 (comment)> :
@@ -137,14 +137,16 @@ class TestAbstractAutoPropertyObjects(unittest.TestCase):
"""
def test_abstractProperty(self):
- self.assertRaisesRegexp(TypeError,
+ # #9720 (Py3 review required): self.assertRaisesRegexp is deprecated.
I think this is just a rename, so this comment isn't necessary to go in eventually.
_____
In tests/unit/test_baseObject.py <#9726 (comment)> :
"^Can't instantiate abstract class AutoPropertyObjectWithAbstractProperty "
"with abstract methods x",
AutoPropertyObjectWithAbstractProperty
)
def test_subclassedAbstractProperty(self):
- self.assertRaisesRegexp(TypeError,
+ # #9720 (Py3 review required): self.assertRaisesRegexp is deprecated.
See above
_____
In tests/unit/test_controlTypes.py <#9726 (comment)> :
@@ -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 controlTypes.__dict__.items():
I think I prefer this to be changed as follows while at it
⬇️ Suggested change
- for name, const in controlTypes.__dict__.items():
+ for name, const in vars(controlTypes).items():
_____
In tests/unit/test_controlTypes.py <#9726 (comment)> :
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 controlTypes.__dict__.items():
See above
_____
In tests/unit/test_extensionPoints.py <#9726 (comment)> :
@@ -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.
Please add a comment to the register method in extensionPoints. That code really needs a revisit.
_____
In tests/unit/test_scriptHandler.py <#9726 (comment)> :
@@ -29,7 +29,8 @@ 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"])
+ # #9720 (Py3 review required): self.assertItemsEqual -> self.assertCountEqual.
Again as above, I don't think this should be in the eventual code of this pr if we just take the rename for granted.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#9726?email_source=notifications&email_token=AB4AXEGT4VEAGBJ57KRROWTP2FDDBA5CNFSM4HXKNMDKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB3LNNPA#pullrequestreview-248960700> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AB4AXEDEZG7BMI7ZQFZ2EZTP2FDDBANCNFSM4HXKNMDA> .
|
| 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. |
There was a problem hiding this comment.
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?
Link to issue number:
Fixes #9720
Summary of the issue:
Updates unitt4est test case syntax to Python 3.
Description of how this pull request fixes the issue:
Unittest test cases uses Python 2 syntax, which will fail if run with Python 3. Thus update syntax.
Procedure:
Testing performed:
Tested with Python 2 and 3 from source.
Known issues with pull request:
Change log entry:
None