Merge lp:~dobey/tarmac/fix-whoami into lp:tarmac

Proposed by dobey
Status: Merged
Approved by: Paul Hummer
Approved revision: 357
Merged at revision: 355
Proposed branch: lp:~dobey/tarmac/fix-whoami
Merge into: lp:tarmac
Diff against target: 159 lines (+24/-14)
4 files modified
tarmac/plugins/tests/test_bugresolver.py (+3/-2)
tarmac/plugins/tests/test_recipebuilder.py (+1/-0)
tarmac/tests/__init__.py (+7/-2)
tarmac/tests/test_branch.py (+13/-10)
To merge this branch: bzr merge lp:~dobey/tarmac/fix-whoami
Reviewer Review Type Date Requested Status
Paul Hummer Approve
Gavin Panella (community) Approve
Review via email: mp+35325@code.launchpad.net

Commit message

Use bzr's TestCaseInTempDir to avoid bzr whoami errors
Fix a couple more pep8 complaints

To post a comment you must log in.
lp:~dobey/tarmac/fix-whoami updated
355. By dobey

Fix pyflakes/pep8 issues

Revision history for this message
Gavin Panella (allenap) wrote :

This works (for me) on Lucid with bzr 2.2 :)

I hope you don't mind, but I had one comment:

+ TestCaseInTempDir.setUp(self)

TestCaseInTempDir.setUp() uses super(), so I think it would be better
to use it here too. There are several other places where the super
classes are explicitly called and they should probably change too.

review: Approve
lp:~dobey/tarmac/fix-whoami updated
356. By dobey

Switch to using super for the testcase inheritence
Switch to using bzrlib's TestCaseInTempDir for all test cases
Cache and restore the old tempfile.tempdir value

357. By dobey

Fix pyflakes/pep8 issues

Revision history for this message
Paul Hummer (rockstar) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tarmac/plugins/tests/test_bugresolver.py'
2--- tarmac/plugins/tests/test_bugresolver.py 2010-09-09 16:28:47 +0000
3+++ tarmac/plugins/tests/test_bugresolver.py 2010-09-14 16:58:40 +0000
4@@ -19,6 +19,7 @@
5 from tarmac.tests import TarmacTestCase
6 from tarmac.tests.mock import Thing
7
8+
9 class BugResolverTests(TarmacTestCase):
10 """Test the BugResolver."""
11
12@@ -35,12 +36,12 @@
13 pass
14
15 bugs = {
16- '0' : Thing(
17+ '0': Thing(
18 bug_tasks=[Thing(target='Target', status='In Progress',
19 lp_save=lp_save),
20 Thing(target='Ubuntu', status='Incomplete',
21 lp_save=lp_save)]),
22- '1' : Thing(
23+ '1': Thing(
24 bug_tasks=[Thing(target='Target', status='Confirmed',
25 lp_save=lp_save)]),
26 }
27
28=== modified file 'tarmac/plugins/tests/test_recipebuilder.py'
29--- tarmac/plugins/tests/test_recipebuilder.py 2010-09-09 16:28:47 +0000
30+++ tarmac/plugins/tests/test_recipebuilder.py 2010-09-14 16:58:40 +0000
31@@ -19,6 +19,7 @@
32 from tarmac.tests import TarmacTestCase
33 from tarmac.tests.mock import Thing
34
35+
36 class RecipeBuilderTests(TarmacTestCase):
37 """Test the Recipe Builder."""
38
39
40=== modified file 'tarmac/tests/__init__.py'
41--- tarmac/tests/__init__.py 2010-08-13 18:56:40 +0000
42+++ tarmac/tests/__init__.py 2010-09-14 16:58:40 +0000
43@@ -18,12 +18,12 @@
44 import os
45 import shutil
46 import tempfile
47-import unittest
48
49+from bzrlib.tests import TestCaseInTempDir
50 from tarmac.config import TarmacConfig
51
52
53-class TarmacTestCase(unittest.TestCase):
54+class TarmacTestCase(TestCaseInTempDir):
55 '''A base TestCase for all Tarmac tests.'''
56
57 CREDS_TEMPLATE = '''
58@@ -36,6 +36,9 @@
59
60 def setUp(self):
61 # Set up the environment.
62+ super(TarmacTestCase, self).setUp()
63+
64+ self._oldtemp = tempfile.tempdir
65 tempfile.tempdir = os.getcwd()
66 self.tempdir = tempfile.mkdtemp(dir=os.getcwd())
67 os.environ['TARMAC_CONFIG_HOME'] = os.path.join(
68@@ -61,6 +64,8 @@
69 del os.environ[key]
70 except KeyError:
71 pass
72+ tempfile.tempdir = self._oldtemp
73+ super(TarmacTestCase, self).tearDown()
74
75 def write_credentials_file(self):
76 """Write out the temporary credentials file for testing."""
77
78=== modified file 'tarmac/tests/test_branch.py'
79--- tarmac/tests/test_branch.py 2010-09-02 15:18:07 +0000
80+++ tarmac/tests/test_branch.py 2010-09-14 16:58:40 +0000
81@@ -18,6 +18,7 @@
82
83 '''Tests for tarmac.branch'''
84 import os
85+import shutil
86
87 from bzrlib.errors import PointlessMerge
88
89@@ -31,10 +32,7 @@
90
91 def setUp(self):
92 '''Set up the test environment.'''
93- TarmacTestCase.setUp(self)
94-
95- self.bzrdir = os.path.join(os.getcwd(), "bzr")
96- os.environ['BZR_HOME'] = self.bzrdir
97+ super(TestBranch, self).setUp()
98
99 self.branch1, self.branch2 = self.make_two_branches_to_merge()
100
101@@ -42,12 +40,15 @@
102 """Tear down the tests."""
103 self.remove_branch_config(self.branch1.lp_branch.tree_dir)
104 self.remove_branch_config(self.branch2.lp_branch.tree_dir)
105- TarmacTestCase.tearDown(self)
106+ shutil.rmtree(self.branch1.lp_branch.tree_dir)
107+ shutil.rmtree(self.branch2.lp_branch.tree_dir)
108+
109+ super(TestBranch, self).tearDown()
110
111 def make_two_branches_to_merge(self):
112 '''Make two branches, one with revisions to merge.'''
113- branch1_dir = os.path.join(self.tempdir, 'branch1')
114- branch2_dir = os.path.join(self.tempdir, 'branch2')
115+ branch1_dir = os.path.join(self.TEST_ROOT, 'branch1')
116+ branch2_dir = os.path.join(self.TEST_ROOT, 'branch2')
117 self.add_branch_config(branch1_dir)
118 self.add_branch_config(branch2_dir)
119
120@@ -72,7 +73,7 @@
121
122 def test_create(self):
123 '''Test the creation of a TarmacBranch instance.'''
124- tree_dir = os.path.join(self.tempdir, 'test_create')
125+ tree_dir = os.path.join(self.TEST_ROOT, 'test_create')
126 self.add_branch_config(tree_dir)
127
128 a_branch = branch.Branch.create(MockLPBranch(tree_dir), self.config)
129@@ -89,7 +90,7 @@
130
131 def test_merge_raises_exception_with_no_tree(self):
132 '''A merge on a branch with no tree will raise an exception.'''
133- branch3_dir = os.path.join(self.tempdir, 'branch3')
134+ branch3_dir = os.path.join(self.TEST_ROOT, 'branch3')
135 self.add_branch_config(branch3_dir)
136 branch3 = branch.Branch.create(MockLPBranch(
137 branch3_dir, source_branch=self.branch1.lp_branch),
138@@ -98,11 +99,12 @@
139 self.assertRaises(
140 AttributeError, branch3.merge, self.branch2)
141 self.remove_branch_config(branch3_dir)
142+ shutil.rmtree(branch3_dir)
143
144 def test_merge_no_changes(self):
145 '''A merge on a branch with a tree will raise an exception if no
146 changes are present.'''
147- branch3_dir = os.path.join(self.tempdir, 'branch3')
148+ branch3_dir = os.path.join(self.TEST_ROOT, 'branch3')
149 self.add_branch_config(branch3_dir)
150 branch3 = branch.Branch.create(MockLPBranch(
151 branch3_dir, source_branch=self.branch1.lp_branch),
152@@ -110,6 +112,7 @@
153
154 self.assertRaises(PointlessMerge, self.branch1.merge, branch3)
155 self.remove_branch_config(branch3_dir)
156+ shutil.rmtree(branch3_dir)
157
158 def test_merge(self):
159 '''A merge on a branch with a tree of a branch with changes will merge.

Subscribers

People subscribed via source and target branches