launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07118
[Merge] lp:~jml/lp-dev-utils/fix-tests into lp:lp-dev-utils
Jonathan Lange has proposed merging lp:~jml/lp-dev-utils/fix-tests into lp:lp-dev-utils.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jml/lp-dev-utils/fix-tests/+merge/101916
I wanted to add a --public-ip option so I can run 'ec2 demo' from Millbank. I didn't want to start without a passing test suite though. This gets us there.
Main issues:
* documenting that PYTHONPATH needs to be set (this lets the subprocesses spawned in the daemonization tests find the code that we're testing)
* removing the dependency on FakeMethod
--
https://code.launchpad.net/~jml/lp-dev-utils/fix-tests/+merge/101916
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jml/lp-dev-utils/fix-tests into lp:lp-dev-utils.
=== modified file '.bzrignore'
--- .bzrignore 2009-10-16 03:03:54 +0000
+++ .bzrignore 2012-04-13 14:40:43 +0000
@@ -1,1 +1,2 @@
.launchpadlib
+_trial_temp
=== added file '.testr.conf'
--- .testr.conf 1970-01-01 00:00:00 +0000
+++ .testr.conf 2012-04-13 14:40:43 +0000
@@ -0,0 +1,3 @@
+[DEFAULT]
+test_command=PYTHONPATH=`pwd`:$PYTHONPATH python -m subunit.run discover $IDLIST
+test_id_list_default=ec2test
=== added file 'README'
--- README 1970-01-01 00:00:00 +0000
+++ README 2012-04-13 14:40:43 +0000
@@ -0,0 +1,39 @@
+==============
+ lp-dev-utils
+==============
+Tools for hacking on Launchpad
+==============================
+
+ec2
+===
+
+``ec2`` is a utility for deploying Launchpad to Amazon's EC2 service and for
+running tests there. Run ``ec2 --help`` to get some more information.
+
+Dependencies
+------------
+
+Note that this list probably over-specifies dependencies. However, this has
+been known to work on an Ubuntu 10.04 LTS machine.
+
+ * launchpad-developer-dependencies
+ * python-bzrlib.tests
+ * bzr-pqm
+
+Running tests
+-------------
+
+Tests can be run with any standard Python test runner. ``nose`` and ``trial``
+have been known to work. Make sure you run the tests with the working tree in
+the ``PYTHONPATH``, for example::
+
+ $ PYTHONPATH=`pwd`:$PYTHONPATH trial ec2test
+
+If you have ``python-testrepository`` and ``discover`` installed, you can run
+the tests using ``testr``::
+
+ $ testr init
+ $ testr run
+ Ran 84 (+84) tests in 51.723s (+51.651s)
+ FAILED (id=1)
+
=== modified file 'ec2test/tests/test_ec2instance.py'
--- ec2test/tests/test_ec2instance.py 2012-02-24 20:23:36 +0000
+++ ec2test/tests/test_ec2instance.py 2012-04-13 14:40:43 +0000
@@ -9,13 +9,15 @@
from unittest import TestCase
from ec2test.instance import EC2Instance
-from lp.testing.fakemethod import FakeMethod
class FakeAccount:
"""Helper for setting up an `EC2Instance` without EC2."""
- acquire_private_key = FakeMethod()
- acquire_security_group = FakeMethod()
+ def acquire_private_key(self):
+ pass
+
+ def acquire_security_group(self, demo_networks=None):
+ pass
class FakeOutput:
@@ -29,8 +31,12 @@
state = 'running'
public_dns_name = 'fake-instance'
- update = FakeMethod()
- stop = FakeMethod()
+ def update(self):
+ pass
+
+ def stop(self):
+ pass
+
get_console_output = FakeOutput
@@ -42,21 +48,40 @@
class FakeImage:
"""Helper for setting up an `EC2Instance` without EC2."""
- run = FakeMethod(result=FakeReservation())
+
+ def run(self, key_name, security_groups, instance_type):
+ return FakeReservation()
class FakeFailure(Exception):
"""A pretend failure from the test runner."""
+class StubbedEC2Instance(EC2Instance):
+
+ def __init__(self, *args, **kwargs):
+ super(StubbedEC2Instance, self).__init__(*args, **kwargs)
+ self._shutdown_calls = 0
+
+ def shutdown(self):
+ self._shutdown_calls += 1
+
+ def log(self, *args, **kwargs):
+ pass
+
+ def _report_traceback(self, *args, **kwargs):
+ pass
+
+
class TestEC2Instance(TestCase):
"""Test running of an `EC2Instance` without EC2."""
def _makeInstance(self):
"""Set up an `EC2Instance`, with stubbing where needed.
- `EC2Instance.shutdown` is replaced with a `FakeMethod`, so check
- its call_count to see whether it's been invoked.
+ `EC2Instance.shutdown` is replaced with a fake method that increments
+ ``_shutdown_calls``. Check its value to see if ``shutdown()`` has
+ been invoked.
"""
session_name = None
image = FakeImage()
@@ -68,21 +93,17 @@
login = None
region = None
- instance = EC2Instance(
+ instance = StubbedEC2Instance(
session_name, image, instance_type, demo_networks, account,
from_scratch, user_key, login,
region)
- instance.shutdown = FakeMethod()
- instance._report_traceback = FakeMethod()
- instance.log = FakeMethod()
-
return instance
def _runInstance(self, instance, runnee=None, headless=False):
"""Set up and run an `EC2Instance` (but without EC2)."""
if runnee is None:
- runnee = FakeMethod()
+ runnee = lambda: None
instance.set_up_and_run(False, not headless, runnee)
@@ -91,15 +112,16 @@
# down. After running, they have started.
# Not a very useful test, except it establishes the basic
# assumptions for the other tests.
+ log = []
instance = self._makeInstance()
- runnee = FakeMethod()
+ runnee = lambda: log.append(None)
- self.assertEqual(0, runnee.call_count)
- self.assertEqual(0, instance.shutdown.call_count)
+ self.assertEqual(0, len(log))
+ self.assertEqual(0, instance._shutdown_calls)
self._runInstance(instance, runnee=runnee)
- self.assertEqual(1, runnee.call_count)
+ self.assertEqual(1, len(log))
def test_set_up_and_run_headful(self):
# A non-headless run executes all tests in the instance, then
@@ -108,7 +130,7 @@
self._runInstance(instance, headless=False)
- self.assertEqual(1, instance.shutdown.call_count)
+ self.assertEqual(1, instance._shutdown_calls)
def test_set_up_and_run_headless(self):
# An asynchronous, headless run kicks off the tests on the
@@ -117,24 +139,26 @@
self._runInstance(instance, headless=True)
- self.assertEqual(0, instance.shutdown.call_count)
+ self.assertEqual(0, instance._shutdown_calls)
def test_set_up_and_run_headful_failure(self):
# If the test runner barfs, the instance swallows the exception
# and shuts down.
instance = self._makeInstance()
- runnee = FakeMethod(failure=FakeFailure("Headful barfage."))
+ def runnee():
+ raise FakeFailure("Headful barfage.")
self._runInstance(instance, runnee=runnee, headless=False)
- self.assertEqual(1, instance.shutdown.call_count)
+ self.assertEqual(1, instance._shutdown_calls)
def test_set_up_and_run_headless_failure(self):
# If the instance's test runner fails to set up for a headless
# run, the instance swallows the exception and shuts down.
instance = self._makeInstance()
- runnee = FakeMethod(failure=FakeFailure("Headless boom."))
+ def runnee():
+ raise FakeFailure("Headless boom.")
self._runInstance(instance, runnee=runnee, headless=True)
- self.assertEqual(1, instance.shutdown.call_count)
+ self.assertEqual(1, instance._shutdown_calls)