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

Using Cassette #60

Closed
wants to merge 54 commits into from
Closed

Using Cassette #60

wants to merge 54 commits into from

Conversation

oxinabox
Copy link
Member

This follows the same user facing API,
except now Mocking.enable and @mock are not required.
And you can only mock names that are inscope.
This is because mocking is now by function, not function name.

Closes #53 and #16


As of right now this works for my simple manual tests,
but getting the test suite going will take a bit.
A lot of the stuff in binding.jl will need tinkering -- the things that need to be bound have kind of flipped, I think.
Key point is that the actual mocking code is @evaled into the Cassette namespace at global scope.

Right now kwargs are not supported, see JuliaLabs/Cassette.jl#48
I think there is a workaround there.

@oxinabox
Copy link
Member Author

oxinabox commented Dec 3, 2018

Right now this also breaks the ability to mock functions that are local variables,
to the function where the @patch is declared.
This should never matter in the wild,
since you will never do that.

I think it is actually fixable, and I am just not fixing Binding's right.
But I also think it doesn't matter

Related to this is the inability to mock functions that are declared as local variables.
But the causes is different.
In that case it is because it is no-longer possible to mock things by name.

I can think of a way to mock things by name, but it involves overdubbing every single call.
so not good.

@oxinabox
Copy link
Member Author

oxinabox commented Dec 3, 2018

Other thing that is broken is the ability mock some calls but not others.
@mock(foo(x)) != foo(x)
Since mock is now a no-op.

Again, I don't think this should ever occur in the wild.

This is fixible but from a unit-testing perspective I don't think it is useful

@ararslan
Copy link
Contributor

ararslan commented Dec 3, 2018

FYI @mock in commit messages pings this guy. I typically say at-mock in commit messages to avoid pings. (I asked GitHub a long time ago to remove that "feature" but nothing has come of that so far.)

@oxinabox
Copy link
Member Author

oxinabox commented Dec 4, 2018

Other thing that is broken is the ability mock some calls but not others.
@mock(foo(x)) != foo(x)
Since mock is now a no-op.

Again, I don't think this should ever occur in the wild.

This is fixible but from a unit-testing perspective I don't think it is useful

@codecov
Copy link

codecov bot commented Dec 4, 2018

Codecov Report

Merging #60 into master will decrease coverage by 6.39%.
The diff coverage is 90.32%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #60     +/-   ##
=========================================
- Coverage   93.23%   86.84%   -6.4%     
=========================================
  Files           4        6      +2     
  Lines         281      228     -53     
=========================================
- Hits          262      198     -64     
- Misses         19       30     +11
Impacted Files Coverage Δ
src/Mocking.jl 50% <0%> (-37.92%) ⬇️
src/bindings.jl 93.25% <100%> (-1.31%) ⬇️
src/patchenv.jl 100% <100%> (ø)
src/deprecated.jl 100% <100%> (ø)
src/patch.jl 85.71% <85.71%> (ø)
src/expr.jl 78.88% <88.88%> (-17.67%) ⬇️
... and 1 more

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 03b4fc7...4315c1d. Read the comment docs.

@oxinabox
Copy link
Member Author

oxinabox commented Dec 5, 2018

This should now be feature complete.

The code is still pretty ugly,
and I still have tests that test the implementation details commented out (because the implementation details have changed, dramatically)
But it is passing all integration tests.
`

It also needs rebasing/squashing pretty badly too, I think.

end
return false
# TODO: redefine this in terms of `methodswith(pe.ctx, Cassette.execute...)`
# If required
Copy link
Member Author

Choose a reason for hiding this comment

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

@omus is this method required?
Should I delete it,
or fix it?

@oxinabox
Copy link
Member Author

oxinabox commented Dec 12, 2018

The version I just pushed should have addressed all of @omus 's comments.
It is now ready for round 2 of review.

src/patchenv.jl Outdated Show resolved Hide resolved
@oxinabox
Copy link
Member Author

We are doing nested overdubbing, though I imagine not more than 2 deep normally
so when JuliaLabs/Cassette.jl#97 (comment)
lands, we should use that maybe and disable our hooks

@oxinabox
Copy link
Member Author

oxinabox commented Jan 8, 2019

This needs to be updated to Cassette 0.2
I am not sure what that entials yet

@oxinabox
Copy link
Member Author

I have upgraded the Cassette version

@rofinn
Copy link
Collaborator

rofinn commented Jan 31, 2019

I'm wondering if this would make Mocking a good solution to the issue of connection information with AbstractPath types in Filepaths.jl? Basically, I think it'd be nice if you could patch calls to write(path::FTPath, data, nothing) with write(path::FTPPath, data, c) where c is an FTPClient defined in some application code away from the write call.

rofinn/FilePaths.jl#36

@oxinabox
Copy link
Member Author

oxinabox commented Jan 31, 2019

I wouldn't say Mocking is a nice way to do that, but using similar Cassette stuff could be,
If not for some of the special cases needed for Mocking (like storing a set of patches for later, and matching the existing API, and dealling with all the ways a user could write a function), then Cassette usage would be a lot less complex.

Probably better to discuss in FilePathBase.jl#36 about it.

@omus
Copy link
Member

omus commented Jul 22, 2019

I'm getting serious about reviewing this during JuliaCon

@omus omus mentioned this pull request Jul 27, 2019
@omus
Copy link
Member

omus commented Jul 27, 2019

I spent a bunch of time experimenting with Cassette based Mocking. At the moment there seems to be some serious performance issues using Cassette for this use case. Additionally I found several techniques we and apply to the existing @mock setup and will be making a few PRs to get those in place. These changes also are useful for switching to Cassette.

@omus
Copy link
Member

omus commented Jan 8, 2020

I'll close this PR as the integration with Cassette has significantly changed. The most recent update on this can be found here: #53 (comment)

@omus omus closed this Jan 8, 2020
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.

Switch Mocking over to using Cassette
6 participants