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

Add tests for extended trait change issues #537 and #538 #543

Merged
merged 6 commits into from
Nov 29, 2019

Conversation

corranwebster
Copy link
Contributor

@corranwebster corranwebster commented Nov 5, 2019

Will mark as expected failures for now. When #537 and #538 are resolved expected failures should be removed.

@corranwebster corranwebster changed the title Add tests for extended trait change issues #537 and #538 [WIP] Add tests for extended trait change issues #537 and #538 Nov 5, 2019
@corranwebster corranwebster changed the title [WIP] Add tests for extended trait change issues #537 and #538 Add tests for extended trait change issues #537 and #538 Nov 5, 2019
@codecov-io
Copy link

codecov-io commented Nov 5, 2019

Codecov Report

Merging #543 into master will increase coverage by 0.15%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #543      +/-   ##
==========================================
+ Coverage   65.15%   65.31%   +0.15%     
==========================================
  Files          44       44              
  Lines        7040     7040              
  Branches     1413     1413              
==========================================
+ Hits         4587     4598      +11     
+ Misses       2030     2017      -13     
- Partials      423      425       +2
Impacted Files Coverage Δ
traits/traits_listener.py 79.13% <0%> (+0.2%) ⬆️
traits/etsconfig/etsconfig.py 63.58% <0%> (+6.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94308a2...f26e117. Read the comment docs.

@mdickinson
Copy link
Member

Is there any chance we could untangle the class inheritance a bit in this PR? We've got a lot of monkeypatch-style subclassing from leaf classes going on - it would be cleaner to restructure so that we have only abstract base classes (that don't get instantiated) and concrete subclasses of those abcs (which do).

ref = Instance(ArgCheckList, ())


class Instance3(Instance2):
Copy link
Member

Choose a reason for hiding this comment

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

Could we replace this with a direct HasTraits subclass? With the current inheritance structure it's hard for the reader to see easily what Instance3 is doing.

@on_trait_change("ref.value[]")
def arg_check1(self, new):
self.calls[1] += 1
self.tc.assertEqual(new, self.dst_new)
Copy link
Member

Choose a reason for hiding this comment

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

Any idea what dst is supposed to stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am guessing "dst" is destination and "src" is source, but I don't have the mental model for why those terms. It clearly made sense to someone (probably Dave Morrill) but there's no deeper explanation that I have found in the documentation that explains the terms.

self.tc.assertIs(object, self.exp_object)
self.tc.assertEqual(name, self.exp_name)
self.tc.assertEqual(old, self.exp_old)
self.tc.assertEqual(new, self.exp_new)


class Instance2(Instance1):
Copy link
Member

Choose a reason for hiding this comment

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

Can we come up with a more meaningful class name?

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

LOKTM. I think we can remove some of the monkey-patch-style subclassing, and there's one minor suggested change (calls = calls = ...).

I'm impressed at how this PR maintains consistency with the existing style, but I have to say that I find this test style horrible, and I want to go in and rewrite the whole module: names of classes don't give a hint about what those classes do (what is Instance4 for, as opposed to Instance3?); tests should be broken up and new instances created instead of resetting traits before doing further tests; there's way too much unnecessary subclassing going on, and the actual test assertions should be in the tests instead of hidden away in the classes under test (which then allows one to stop doing the weird and ugly create-instance-then-call-trait-set-to-initialise-it dance). But that rewrite can happen after this goes in.

@corranwebster
Copy link
Contributor Author

I've replaced the InstanceN classes with better named versions and assed better method and variable names. Assuming tests pass, this is ready for a re-review.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

Changes LGTM

@mdickinson mdickinson merged commit 5bdc874 into master Nov 29, 2019
@mdickinson mdickinson deleted the test/better-extended-trait-handler-tests branch November 29, 2019 10:16
@kitchoi
Copy link
Contributor

kitchoi commented Jan 17, 2020

Super minor... With #537 and #538 being nontrivial to fix without breaking downstream projects, these tests may be here to stay for sometime. It is difficult to maintain a test for the long-term using the expectedFailure decorator, because any error (e.g. SyntaxError) is considered an "expected failure". What do you think if I try modifying the tests to use self.assertRaises(AssertionError) instead? This would help me understand #537 and #538 a bit more as well.

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