Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strengthen interface checks in tests #1225

Merged
merged 3 commits into from
Jul 13, 2020

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Jun 25, 2020

This PR enhances some of the tests in test_interfaces.py:

  • Fix test classes that claim to provide given interfaces, to actually provide that interface. (Without this, these tests fail if CHECK_INTERFACES is set to 2.)
  • Add some additional assertIsInstance checks to verify that instances of those test classes do pass the appropriate isinstance checks.

@mdickinson mdickinson changed the title Strengthen interface checks Strengthen interface checks in tests Jun 26, 2020
@mdickinson mdickinson added component: test suite Issues related directly to the test suite type: cleanup labels Jun 26, 2020
@mdickinson mdickinson added this to the 6.2.0 release milestone Jun 26, 2020
@mdickinson
Copy link
Member Author

I extended the PR to add some tests for the current interface-checking behaviour of the @provides decorator.

with self.set_check_interfaces(2):
with self.assertRaises(InterfaceError):
# Simulate application of the decorator
Test = provides_ifoo(Test)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the assignment Test = necessary here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not. I'm surprised I didn't get a flake8 warning. I'll remove it, and the similar occurrence in test_provides_with_interface_check_warn.

Copy link
Member Author

Choose a reason for hiding this comment

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

Though actually, it may be worth adding explicit tests that in the warning case, we do end up with something that implements IFoo, and in the error case, we don't.

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way sounds good to me!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. It turns out that the extra test I added failed: even though the application of provides_ifoo fails in this case, Test still gets registered as implementing IFoo! It doesn't seem worth fixing, for something we're deprecating anyway, but now I'm not sure whether to encode the behaviour in a test or just leave it out.

On balance, I think I'll keep the extra test, but I could be persuaded otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Extra tests added; unused variable is now used!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. It turns out that the extra test I added failed: even though the application of provides_ifoo fails in this case, Test still gets registered as implementing IFoo! It doesn't seem worth fixing, for something we're deprecating anyway, but now I'm not sure whether to encode the behaviour in a test or just leave it out.

Yep this is surprising, and I agree that this is not worth fixing.

Copy link
Contributor

@kitchoi kitchoi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@kitchoi kitchoi left a comment

Choose a reason for hiding this comment

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

Still LGTM

@mdickinson mdickinson merged commit 579d957 into master Jul 13, 2020
@mdickinson mdickinson deleted the tests/strengthen-interface-checks branch July 13, 2020 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: test suite Issues related directly to the test suite type: cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants