Merge lp:~veebers/autopilot/fix_1203716_patch_environment into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Thomi Richards
Approved revision: 284
Merged at revision: 284
Proposed branch: lp:~veebers/autopilot/fix_1203716_patch_environment
Merge into: lp:autopilot
Prerequisite: lp:~autopilot/autopilot/fix-test-failures
Diff against target: 87 lines (+62/-2)
2 files modified
autopilot/testcase.py (+18/-2)
autopilot/tests/functional/test_autopilot_functional.py (+44/-0)
To merge this branch: bzr merge lp:~veebers/autopilot/fix_1203716_patch_environment
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Thomi Richards (community) Approve
Review via email: mp+176578@code.launchpad.net

This proposal supersedes a proposal from 2013-07-22.

Commit message

Fixes bug 1203716 where patch_environment didn't cleanup after itself.

Description of the change

Fixes bug 1203716 where patch_environment didn't cleanup after itself.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:284
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~veebers/autopilot/fix_1203716_patch_environment/+merge/176578/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/autopilot-ci/174/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-saucy-amd64-ci/102
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-saucy-armhf-ci/102

Click here to trigger a rebuild:
http://s-jenkins:8080/job/autopilot-ci/174/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'autopilot/testcase.py'
--- autopilot/testcase.py 2013-07-22 04:02:05 +0000
+++ autopilot/testcase.py 2013-07-24 02:56:31 +0000
@@ -321,10 +321,26 @@
321321
322 """322 """
323 if key in os.environ:323 if key in os.environ:
324 def _undo_patch(key, old_value):
325 logger.info(
326 "Resetting environment variable '%s' to '%s'",
327 key,
328 old_value
329 )
330 os.environ[key] = old_value
324 old_value = os.environ[key]331 old_value = os.environ[key]
325 self.addCleanup(os.putenv, key, old_value)332 self.addCleanup(_undo_patch, key, old_value)
326 else:333 else:
327 self.addCleanup(os.unsetenv, key)334 def _remove_patch(key):
335 try:
336 del os.environ[key]
337 except KeyError:
338 logger.warning(
339 "Attempted to delete environment key '%s' that doesn't"
340 "exist in the environment",
341 key
342 )
343 self.addCleanup(_remove_patch, key)
328 os.environ[key] = value344 os.environ[key] = value
329345
330 def assertVisibleWindowStack(self, stack_start):346 def assertVisibleWindowStack(self, stack_start):
331347
=== modified file 'autopilot/tests/functional/test_autopilot_functional.py'
--- autopilot/tests/functional/test_autopilot_functional.py 2013-07-14 10:01:01 +0000
+++ autopilot/tests/functional/test_autopilot_functional.py 2013-07-24 02:56:31 +0000
@@ -869,6 +869,50 @@
869 self.assertThat(output, Not(Contains('Running tests in random order')))869 self.assertThat(output, Not(Contains('Running tests in random order')))
870870
871871
872class AutopilotPatchEnvironmentTests(AutopilotTestCase):
873
874 def test_patch_environment_new_patch_is_unset_to_none(self):
875 """patch_environment must unset the environment variable if previously
876 was unset.
877
878 """
879
880 class PatchEnvironmentSubTests(AutopilotTestCase):
881
882 def test_patch_env_sets_var(self):
883 """Setting the environment variable must make it available."""
884 self.patch_environment("APABC321", "Foo")
885 self.assertThat(os.getenv("APABC321"), Equals("Foo"))
886
887 self.assertThat(os.getenv('APABC321'), Equals(None))
888
889 result = PatchEnvironmentSubTests("test_patch_env_sets_var").run()
890
891 self.assertThat(result.wasSuccessful(), Equals(True))
892 self.assertThat(os.getenv('APABC321'), Equals(None))
893
894 def test_patch_environment_existing_patch_is_reset(self):
895 """patch_environment must reset the environment back to it's previous
896 value.
897
898 """
899
900 class PatchEnvironmentSubTests(AutopilotTestCase):
901
902 def test_patch_env_sets_var(self):
903 """Setting the environment variable must make it available."""
904 self.patch_environment("APABC987", "InnerTest")
905 self.assertThat(os.getenv("APABC987"), Equals("InnerTest"))
906
907 self.patch_environment('APABC987', "OuterTest")
908 self.assertThat(os.getenv('APABC987'), Equals("OuterTest"))
909
910 result = PatchEnvironmentSubTests("test_patch_env_sets_var").run()
911
912 self.assertThat(result.wasSuccessful(), Equals(True))
913 self.assertThat(os.getenv('APABC987'), Equals("OuterTest"))
914
915
872class AutopilotVerboseFunctionalTests(AutopilotFunctionalTestsBase):916class AutopilotVerboseFunctionalTests(AutopilotFunctionalTestsBase):
873917
874 """Scenarioed functional tests for autopilot's verbose logging."""918 """Scenarioed functional tests for autopilot's verbose logging."""

Subscribers

People subscribed via source and target branches