Skip to content

Unittests/Python 3: update syntax, catch unbound method registration test in extension points as expected failure - #9726

Merged
michaelDCurran merged 13 commits into
nvaccess:threshold_py3_stagingfrom
josephsl:py3unittest
Jun 13, 2019
Merged

Unittests/Python 3: update syntax, catch unbound method registration test in extension points as expected failure#9726
michaelDCurran merged 13 commits into
nvaccess:threshold_py3_stagingfrom
josephsl:py3unittest

Conversation

@josephsl

Copy link
Copy Markdown
Contributor

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:

  1. With latest py3 staging branch, run unit tests with scons tests.
  2. For every error, look for tests that are causing the error. Errors may include relative import problem (unable to import "test.unit" caused by relative import issue).

Testing performed:

Tested with Python 2 and 3 from source.

Known issues with pull request:

  1. In extension points tests, unbound method registration test fails because TypeError is not raised. This is marked as expected failure.
  2. Due to repeated insertion of msvcr90.dll by brltty/brlapi, braille display gestures integrity test causes VC++ runtime error to be thrown (see Brltty/Python 3: R6034 error when running unittests #9721).

Change log entry:

None

@josephsl
josephsl requested a review from michaelDCurran June 12, 2019 15:54
@josephsl

Copy link
Copy Markdown
Contributor Author

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.

Comment thread tests/unit/test_baseObject.py Outdated

def test_abstractProperty(self):
self.assertRaisesRegexp(TypeError,
# #9720 (Py3 review required): self.assertRaisesRegexp is deprecated.

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.

I think this is just a rename, so this comment isn't necessary to go in eventually.

Comment thread tests/unit/test_baseObject.py Outdated

def test_subclassedAbstractProperty(self):
self.assertRaisesRegexp(TypeError,
# #9720 (Py3 review required): self.assertRaisesRegexp is deprecated.

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.

See above

Comment thread tests/unit/test_controlTypes.py Outdated
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():

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.

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():

Comment thread tests/unit/test_controlTypes.py Outdated
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():

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.

See above

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?

Comment thread tests/unit/test_scriptHandler.py Outdated
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.

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.

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.

@josephsl

josephsl commented Jun 12, 2019 via email

Copy link
Copy Markdown
Contributor Author

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
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?

@michaelDCurran
michaelDCurran merged commit e6fa058 into nvaccess:threshold_py3_staging Jun 13, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Jun 13, 2019
LeonarddeR pushed a commit to LeonarddeR/nvda that referenced this pull request Jun 21, 2019
@josephsl
josephsl deleted the py3unittest branch September 16, 2019 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants