Base.merge
— Methodmerge(pe1::PatchEnv, pe2::PatchEnv) -> PatchEnv
Merge the two PatchEnv
instances.
This is done in such a way that the following always holds:
patches_1 = Patch[...]
patches_2 = Patch[...]
patches = vcat(patches_1, patches_2)
pe1 = PatchEnv(patches_1)
pe2 = PatchEnv(patches_2)
pe = PatchEnv(patches)
@assert pe == merge(pe1, pe2)
The debug
flag will be set to true if either pe1
or pe2
have it set to true.
Mocking.activate
— MethodMocking.activate()
Enable @mock
call sites to allow for calling patches instead of the original function.
Mocking.anon_morespecific
— Methodanon_morespecific(a::Method, b::Method) -> Bool
Determine which method is more specific for multiple dispatch without considering the function type. By not considering the function type we can determine which method is more specific as if they are a part of the same generic function.
Mocking.anonymous_signature
— Methodanonymous_signature(m::Method) -> Type{<:Tuple}
Construct a Tuple of the methods signature with the function type removed
Example
julia> m = first(methods(first, (String,)));
julia> m.sig
Tuple{typeof(first),Any}
julia> anonymous_signature(m)
Tuple{Any}
Mocking.apply
— Methodapply(body::Function, patches; debug::Bool=false)
apply(body::Function, pe::PatchEnv)
Convenience function to run body
in the context of the given patches
.
This is intended to be used with do-block notation, e.g.:
patch = @patch ...
apply(patch) do
...
end
Nesting
Note that calls to apply will nest the patches that are applied. If multiple patches are made to the same method, the innermost patch takes precedence.
The following two examples are equivalent:
patch_2 = @patch ...
apply([patch, patch_2]) do
...
end
apply(patch) do
apply(patch_2) do
...
end
end
Mocking.deactivate
— MethodMocking.deactivate()
Disable @mock
call sites to only call the original function.
Mocking.dispatch
— Methoddispatch(funcs::AbstractVector, args...) -> Tuple{Method, Any}
Choose which method to execute based upon the provided arguments (values not types). Emulates Julia's multiple dispatch system but allows for dispatching between methods of multiple generic functions instead of just methods of a single generic function. Returns a tuple of the selected method and the generic function of the method.
When the function to dispatch to is ambiguous last ambiguous function in the vector is used.
Mocking.extract_kwargs
— Methodextract_kwargs(expr::Expr) -> Vector{Union{Expr,Symbol}}
Extract the :parameters and :kw value into an array of :kw expressions we don't evaluate any expressions for values yet though.
Mocking.nullify
— MethodMocking.nullify()
Force any packages loaded after this point to treat the @mock
macro as a no-op. Doing so will maximize performance by eliminating any runtime checks taking place at the @mock
call sites but will break any tests that require patches to be applied.
Note to ensure that all @mock
macros are inoperative be sure to call this function before loading any packages which depend on Mocking.jl.