[tor-commits] [stem/master] Migrating to the mock library
atagar at torproject.org
atagar at torproject.org
Thu Jun 13 16:50:53 UTC 2013
commit 101cf0b71bab55d72a831eff0236dcef5edbff0f
Merge: 65846e8 2b634a9
Author: Damian Johnson <atagar at torproject.org>
Date: Thu Jun 13 09:48:30 2013 -0700
Migrating to the mock library
Our homemade mocking framework has served us well, but over time it's taught me
one very important lesson: writing a mocking framework is hard. On the surface
it seems pretty simple: apply and revert a set of monkey patches. But how do
you monkey patch class methods? What about alias imports like the os module?
And god forbid you want to mock python's open() function.
I'm finally taking a lesson from one of my coworkers and using a library for
this. Python has several options but the most common is PyPI's mock module,
which became part of the standard library in Python 3.3...
http://www.voidspace.org.uk/python/mock/
run_tests.py | 17 ++
stem/prereq.py | 20 ++
test/integ/descriptor/reader.py | 5 -
test/integ/descriptor/server_descriptor.py | 4 -
test/integ/process.py | 20 +-
test/integ/response/protocolinfo.py | 33 ++-
test/integ/util/system.py | 138 +++++++-----
test/mocking.py | 315 ----------------------------
test/settings.cfg | 1 +
test/unit/connection/authentication.py | 47 ++---
test/unit/control/controller.py | 236 ++++++++++-----------
test/unit/descriptor/export.py | 20 +-
test/unit/descriptor/reader.py | 62 +++---
test/unit/descriptor/server_descriptor.py | 22 +-
test/unit/response/control_message.py | 2 +-
test/unit/response/events.py | 7 +-
test/unit/response/protocolinfo.py | 30 +--
test/unit/tutorial.py | 120 ++++-------
test/unit/util/proc.py | 104 +++++----
test/unit/util/system.py | 124 ++++++-----
test/unit/version.py | 27 +--
test/util.py | 8 +
22 files changed, 541 insertions(+), 821 deletions(-)
More information about the tor-commits
mailing list