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
1=== modified file 'autopilot/testcase.py'
2--- autopilot/testcase.py 2013-07-22 04:02:05 +0000
3+++ autopilot/testcase.py 2013-07-24 02:56:31 +0000
4@@ -321,10 +321,26 @@
5
6 """
7 if key in os.environ:
8+ def _undo_patch(key, old_value):
9+ logger.info(
10+ "Resetting environment variable '%s' to '%s'",
11+ key,
12+ old_value
13+ )
14+ os.environ[key] = old_value
15 old_value = os.environ[key]
16- self.addCleanup(os.putenv, key, old_value)
17+ self.addCleanup(_undo_patch, key, old_value)
18 else:
19- self.addCleanup(os.unsetenv, key)
20+ def _remove_patch(key):
21+ try:
22+ del os.environ[key]
23+ except KeyError:
24+ logger.warning(
25+ "Attempted to delete environment key '%s' that doesn't"
26+ "exist in the environment",
27+ key
28+ )
29+ self.addCleanup(_remove_patch, key)
30 os.environ[key] = value
31
32 def assertVisibleWindowStack(self, stack_start):
33
34=== modified file 'autopilot/tests/functional/test_autopilot_functional.py'
35--- autopilot/tests/functional/test_autopilot_functional.py 2013-07-14 10:01:01 +0000
36+++ autopilot/tests/functional/test_autopilot_functional.py 2013-07-24 02:56:31 +0000
37@@ -869,6 +869,50 @@
38 self.assertThat(output, Not(Contains('Running tests in random order')))
39
40
41+class AutopilotPatchEnvironmentTests(AutopilotTestCase):
42+
43+ def test_patch_environment_new_patch_is_unset_to_none(self):
44+ """patch_environment must unset the environment variable if previously
45+ was unset.
46+
47+ """
48+
49+ class PatchEnvironmentSubTests(AutopilotTestCase):
50+
51+ def test_patch_env_sets_var(self):
52+ """Setting the environment variable must make it available."""
53+ self.patch_environment("APABC321", "Foo")
54+ self.assertThat(os.getenv("APABC321"), Equals("Foo"))
55+
56+ self.assertThat(os.getenv('APABC321'), Equals(None))
57+
58+ result = PatchEnvironmentSubTests("test_patch_env_sets_var").run()
59+
60+ self.assertThat(result.wasSuccessful(), Equals(True))
61+ self.assertThat(os.getenv('APABC321'), Equals(None))
62+
63+ def test_patch_environment_existing_patch_is_reset(self):
64+ """patch_environment must reset the environment back to it's previous
65+ value.
66+
67+ """
68+
69+ class PatchEnvironmentSubTests(AutopilotTestCase):
70+
71+ def test_patch_env_sets_var(self):
72+ """Setting the environment variable must make it available."""
73+ self.patch_environment("APABC987", "InnerTest")
74+ self.assertThat(os.getenv("APABC987"), Equals("InnerTest"))
75+
76+ self.patch_environment('APABC987', "OuterTest")
77+ self.assertThat(os.getenv('APABC987'), Equals("OuterTest"))
78+
79+ result = PatchEnvironmentSubTests("test_patch_env_sets_var").run()
80+
81+ self.assertThat(result.wasSuccessful(), Equals(True))
82+ self.assertThat(os.getenv('APABC987'), Equals("OuterTest"))
83+
84+
85 class AutopilotVerboseFunctionalTests(AutopilotFunctionalTestsBase):
86
87 """Scenarioed functional tests for autopilot's verbose logging."""

Subscribers

People subscribed via source and target branches