I'll use this in an upcoming test. The decorator dancing in this is
more complicated than I'd like, but it beats repeating all this code
everywhere.
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGd8f07b16abfc: phabricator: add support for using the vcr library to mock interactions
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
Queued the series, thanks.
+_VCR_FLAGS = [
+ (b'', b'test-vcr', b'',
+ _(b'Path to a vcr file. If nonexistent, will record a new vcr transcript'
+ b', otherwise will mock all http requests using the specified vcr file.'
+ b' (DEPRECATED)'
s/(DEPRECATED)/(ADVANCED)/ in flight.
+def vcrcommand(name, flags, spec):
+ fullflags = flags + _VCR_FLAGS
+ def decorate(fn):
+ def inner(*args, **kwargs):
+ cassette = kwargs.pop(r'test_vcr', None)
+ if cassette:
+ import hgdemandimport
+ with hgdemandimport.deactivated():
+ import vcr as vcrmod
+ from vcr import stubs
Fixed check-module-imports warning in flight.
+ vcr = vcrmod.VCR(
+ serializer=r'json',
+ custom_patches=[
+ (urlmod, 'httpconnection', stubs.VCRHTTPConnection),
+ (urlmod, 'httpsconnection', stubs.VCRHTTPSConnection),
+ ])
+ with vcr.use_cassette(cassette):
+ return fn(*args, kwargs)
+ return fn(*args, kwargs)
+ inner.name = fn.name
+ return command(name, fullflags, spec)(inner)
+ return decorate
Perhaps, it's easier to extend the registrar.command class instead. Another
option is to turn --test-vcr into a config knob, and hook somewhere in
dispatch.