Merge lp:~jml/python-fixtures/normal-names-893539 into lp:~python-fixtures/python-fixtures/trunk
- normal-names-893539
- Merge into trunk
Proposed by
Jonathan Lange
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 47 | ||||
Proposed branch: | lp:~jml/python-fixtures/normal-names-893539 | ||||
Merge into: | lp:~python-fixtures/python-fixtures/trunk | ||||
Diff against target: |
505 lines (+96/-64) 10 files modified
NEWS (+5/-1) README (+15/-15) lib/fixtures/__init__.py (+7/-2) lib/fixtures/_fixtures/__init__.py (+16/-4) lib/fixtures/_fixtures/environ.py (+8/-4) lib/fixtures/_fixtures/logger.py (+8/-4) lib/fixtures/_fixtures/popen.py (+8/-3) lib/fixtures/tests/_fixtures/test_environ.py (+13/-14) lib/fixtures/tests/_fixtures/test_logger.py (+10/-10) lib/fixtures/tests/_fixtures/test_popen.py (+6/-7) |
||||
To merge this branch: | bzr merge lp:~jml/python-fixtures/normal-names-893539 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
python-fixtures committers | Pending | ||
Review via email: mp+83424@code.launchpad.net |
Commit message
Description of the change
This addresses bug 893539 by changing the three fixtures with "Fixture" in their name to not have Fixture in their name.
EnvironmentVar
LoggerFixture => FakeLogger
PopenFixture => FakePopen
EnvironmentVariable is the one I really care about.
I did this by renaming the classes and providing exported aliases for the old names. All the docs have been updated for the new names.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'NEWS' | |||
2 | --- NEWS 2011-11-22 09:26:54 +0000 | |||
3 | +++ NEWS 2011-11-25 17:48:24 +0000 | |||
4 | @@ -8,7 +8,11 @@ | |||
5 | 8 | 8 | ||
6 | 9 | CHANGES: | 9 | CHANGES: |
7 | 10 | 10 | ||
9 | 11 | * EnvironmentVariableFixture now upcalls via super(). | 11 | * EnvironmentVariableFixture, LoggerFixture, PopenFixture renamed to |
10 | 12 | EnvironmentVariable, FakeLogger and FakePopen respectively. All are still | ||
11 | 13 | available under their old, deprecated names. (Jonathan Lange, #893539) | ||
12 | 14 | |||
13 | 15 | * EnvironmentVariable now upcalls via super(). | ||
14 | 12 | (Jonathan Lange, #881120) | 16 | (Jonathan Lange, #881120) |
15 | 13 | 17 | ||
16 | 14 | 0.3.7 | 18 | 0.3.7 |
17 | 15 | 19 | ||
18 | === modified file 'README' | |||
19 | --- README 2011-11-22 10:07:24 +0000 | |||
20 | +++ README 2011-11-25 17:48:24 +0000 | |||
21 | @@ -266,21 +266,30 @@ | |||
22 | 266 | includes a number of precanned fixtures. The API docs for fixtures will list | 266 | includes a number of precanned fixtures. The API docs for fixtures will list |
23 | 267 | the complete set of these, should the dcs be out of date or not to hand. | 267 | the complete set of these, should the dcs be out of date or not to hand. |
24 | 268 | 268 | ||
27 | 269 | EnvironmentVariableFixture | 269 | EnvironmentVariable |
28 | 270 | ++++++++++++++++++++++++++ | 270 | +++++++++++++++++++ |
29 | 271 | 271 | ||
30 | 272 | Isolate your code from environmental variables, delete them or set them to a | 272 | Isolate your code from environmental variables, delete them or set them to a |
31 | 273 | new value. | 273 | new value. |
32 | 274 | 274 | ||
34 | 275 | >>> fixture = fixtures.EnvironmentVariableFixture('HOME') | 275 | >>> fixture = fixtures.EnvironmentVariable('HOME') |
35 | 276 | 276 | ||
38 | 277 | LoggerFixture | 277 | FakeLogger |
39 | 278 | +++++++++++++ | 278 | ++++++++++ |
40 | 279 | 279 | ||
41 | 280 | Isolate your code from an external logging configuration - so that your test | 280 | Isolate your code from an external logging configuration - so that your test |
42 | 281 | gets the output from logged messages, but they don't go to e.g. the console. | 281 | gets the output from logged messages, but they don't go to e.g. the console. |
43 | 282 | 282 | ||
45 | 283 | >>> fixture = fixtures.LoggerFixture() | 283 | >>> fixture = fixtures.FakeLogger() |
46 | 284 | |||
47 | 285 | FakePopen | ||
48 | 286 | +++++++++ | ||
49 | 287 | |||
50 | 288 | Pretend to run an external command rather than needing it to be present to run | ||
51 | 289 | tests. | ||
52 | 290 | |||
53 | 291 | >>> from testtools.compat import BytesIO | ||
54 | 292 | >>> fixture = fixtures.FakePopen(lambda _:{'stdout': BytesIO('foobar')}) | ||
55 | 284 | 293 | ||
56 | 285 | MonkeyPatch | 294 | MonkeyPatch |
57 | 286 | +++++++++++ | 295 | +++++++++++ |
58 | @@ -300,15 +309,6 @@ | |||
59 | 300 | 309 | ||
60 | 301 | >>> fixture = fixtures.PackagePathEntry('package/name', '/foo/bar') | 310 | >>> fixture = fixtures.PackagePathEntry('package/name', '/foo/bar') |
61 | 302 | 311 | ||
62 | 303 | PopenFixture | ||
63 | 304 | ++++++++++++ | ||
64 | 305 | |||
65 | 306 | Pretend to run an external command rather than needing it to be present to run | ||
66 | 307 | tests. | ||
67 | 308 | |||
68 | 309 | >>> from testtools.compat import BytesIO | ||
69 | 310 | >>> fixture = fixtures.PopenFixture(lambda _:{'stdout': BytesIO('foobar')}) | ||
70 | 311 | |||
71 | 312 | PythonPackage | 312 | PythonPackage |
72 | 313 | +++++++++++++ | 313 | +++++++++++++ |
73 | 314 | 314 | ||
74 | 315 | 315 | ||
75 | === modified file 'lib/fixtures/__init__.py' | |||
76 | --- lib/fixtures/__init__.py 2011-11-22 08:58:38 +0000 | |||
77 | +++ lib/fixtures/__init__.py 2011-11-25 17:48:24 +0000 | |||
78 | @@ -1,6 +1,6 @@ | |||
79 | 1 | # fixtures: Fixtures with cleanups for testing and convenience. | 1 | # fixtures: Fixtures with cleanups for testing and convenience. |
80 | 2 | # | 2 | # |
82 | 3 | # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> | 3 | # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> |
83 | 4 | # | 4 | # |
84 | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause |
85 | 6 | # license at the users choice. A copy of both licenses are available in the | 6 | # license at the users choice. A copy of both licenses are available in the |
86 | @@ -39,7 +39,10 @@ | |||
87 | 39 | __version__ = (0, 3, 8, 'beta', 0) | 39 | __version__ = (0, 3, 8, 'beta', 0) |
88 | 40 | 40 | ||
89 | 41 | __all__ = [ | 41 | __all__ = [ |
90 | 42 | 'EnvironmentVariable', | ||
91 | 42 | 'EnvironmentVariableFixture', | 43 | 'EnvironmentVariableFixture', |
92 | 44 | 'FakeLogger', | ||
93 | 45 | 'FakePopen', | ||
94 | 43 | 'Fixture', | 46 | 'Fixture', |
95 | 44 | 'FunctionFixture', | 47 | 'FunctionFixture', |
96 | 45 | 'LoggerFixture', | 48 | 'LoggerFixture', |
97 | @@ -56,7 +59,10 @@ | |||
98 | 56 | 59 | ||
99 | 57 | from fixtures.fixture import Fixture, FunctionFixture, MethodFixture | 60 | from fixtures.fixture import Fixture, FunctionFixture, MethodFixture |
100 | 58 | from fixtures._fixtures import ( | 61 | from fixtures._fixtures import ( |
101 | 62 | EnvironmentVariable, | ||
102 | 59 | EnvironmentVariableFixture, | 63 | EnvironmentVariableFixture, |
103 | 64 | FakeLogger, | ||
104 | 65 | FakePopen, | ||
105 | 60 | LoggerFixture, | 66 | LoggerFixture, |
106 | 61 | MonkeyPatch, | 67 | MonkeyPatch, |
107 | 62 | PackagePathEntry, | 68 | PackagePathEntry, |
108 | @@ -69,7 +75,6 @@ | |||
109 | 69 | 75 | ||
110 | 70 | 76 | ||
111 | 71 | def test_suite(): | 77 | def test_suite(): |
112 | 72 | import unittest | ||
113 | 73 | import fixtures.tests | 78 | import fixtures.tests |
114 | 74 | return fixtures.tests.test_suite() | 79 | return fixtures.tests.test_suite() |
115 | 75 | 80 | ||
116 | 76 | 81 | ||
117 | === modified file 'lib/fixtures/_fixtures/__init__.py' | |||
118 | --- lib/fixtures/_fixtures/__init__.py 2011-10-26 15:10:31 +0000 | |||
119 | +++ lib/fixtures/_fixtures/__init__.py 2011-11-25 17:48:24 +0000 | |||
120 | @@ -1,6 +1,6 @@ | |||
121 | 1 | # fixtures: Fixtures with cleanups for testing and convenience. | 1 | # fixtures: Fixtures with cleanups for testing and convenience. |
122 | 2 | # | 2 | # |
124 | 3 | # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> | 3 | # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> |
125 | 4 | # | 4 | # |
126 | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause |
127 | 6 | # license at the users choice. A copy of both licenses are available in the | 6 | # license at the users choice. A copy of both licenses are available in the |
128 | @@ -17,7 +17,10 @@ | |||
129 | 17 | """Included fixtures.""" | 17 | """Included fixtures.""" |
130 | 18 | 18 | ||
131 | 19 | __all__ = [ | 19 | __all__ = [ |
132 | 20 | 'EnvironmentVariable', | ||
133 | 20 | 'EnvironmentVariableFixture', | 21 | 'EnvironmentVariableFixture', |
134 | 22 | 'FakeLogger', | ||
135 | 23 | 'FakePopen', | ||
136 | 21 | 'LoggerFixture', | 24 | 'LoggerFixture', |
137 | 22 | 'MonkeyPatch', | 25 | 'MonkeyPatch', |
138 | 23 | 'PackagePathEntry', | 26 | 'PackagePathEntry', |
139 | @@ -28,10 +31,19 @@ | |||
140 | 28 | ] | 31 | ] |
141 | 29 | 32 | ||
142 | 30 | 33 | ||
145 | 31 | from fixtures._fixtures.environ import EnvironmentVariableFixture | 34 | from fixtures._fixtures.environ import ( |
146 | 32 | from fixtures._fixtures.logger import LoggerFixture | 35 | EnvironmentVariable, |
147 | 36 | EnvironmentVariableFixture, | ||
148 | 37 | ) | ||
149 | 38 | from fixtures._fixtures.logger import ( | ||
150 | 39 | FakeLogger, | ||
151 | 40 | LoggerFixture, | ||
152 | 41 | ) | ||
153 | 33 | from fixtures._fixtures.monkeypatch import MonkeyPatch | 42 | from fixtures._fixtures.monkeypatch import MonkeyPatch |
155 | 34 | from fixtures._fixtures.popen import PopenFixture | 43 | from fixtures._fixtures.popen import ( |
156 | 44 | FakePopen, | ||
157 | 45 | PopenFixture, | ||
158 | 46 | ) | ||
159 | 35 | from fixtures._fixtures.packagepath import PackagePathEntry | 47 | from fixtures._fixtures.packagepath import PackagePathEntry |
160 | 36 | from fixtures._fixtures.pythonpackage import PythonPackage | 48 | from fixtures._fixtures.pythonpackage import PythonPackage |
161 | 37 | from fixtures._fixtures.pythonpath import PythonPathEntry | 49 | from fixtures._fixtures.pythonpath import PythonPathEntry |
162 | 38 | 50 | ||
163 | === modified file 'lib/fixtures/_fixtures/environ.py' | |||
164 | --- lib/fixtures/_fixtures/environ.py 2011-10-31 16:30:52 +0000 | |||
165 | +++ lib/fixtures/_fixtures/environ.py 2011-11-25 17:48:24 +0000 | |||
166 | @@ -14,6 +14,7 @@ | |||
167 | 14 | # limitations under that license. | 14 | # limitations under that license. |
168 | 15 | 15 | ||
169 | 16 | __all__ = [ | 16 | __all__ = [ |
170 | 17 | 'EnvironmentVariable', | ||
171 | 17 | 'EnvironmentVariableFixture' | 18 | 'EnvironmentVariableFixture' |
172 | 18 | ] | 19 | ] |
173 | 19 | 20 | ||
174 | @@ -22,11 +23,11 @@ | |||
175 | 22 | from fixtures import Fixture | 23 | from fixtures import Fixture |
176 | 23 | 24 | ||
177 | 24 | 25 | ||
179 | 25 | class EnvironmentVariableFixture(Fixture): | 26 | class EnvironmentVariable(Fixture): |
180 | 26 | """Isolate a specific environment variable.""" | 27 | """Isolate a specific environment variable.""" |
181 | 27 | 28 | ||
182 | 28 | def __init__(self, varname, newvalue=None): | 29 | def __init__(self, varname, newvalue=None): |
184 | 29 | """Create an EnvironmentVariableFixture. | 30 | """Create an EnvironmentVariable fixture. |
185 | 30 | 31 | ||
186 | 31 | :param varname: the name of the variable to isolate. | 32 | :param varname: the name of the variable to isolate. |
187 | 32 | :param newvalue: A value to set the variable to. If None, the variable | 33 | :param newvalue: A value to set the variable to. If None, the variable |
188 | @@ -35,12 +36,12 @@ | |||
189 | 35 | During setup the variable will be deleted or assigned the requested | 36 | During setup the variable will be deleted or assigned the requested |
190 | 36 | value, and this will be restored in cleanUp. | 37 | value, and this will be restored in cleanUp. |
191 | 37 | """ | 38 | """ |
193 | 38 | Fixture.__init__(self) | 39 | super(EnvironmentVariable, self).__init__() |
194 | 39 | self.varname = varname | 40 | self.varname = varname |
195 | 40 | self.newvalue = newvalue | 41 | self.newvalue = newvalue |
196 | 41 | 42 | ||
197 | 42 | def setUp(self): | 43 | def setUp(self): |
199 | 43 | super(EnvironmentVariableFixture, self).setUp() | 44 | super(EnvironmentVariable, self).setUp() |
200 | 44 | varname = self.varname | 45 | varname = self.varname |
201 | 45 | orig_value = os.environ.get(varname) | 46 | orig_value = os.environ.get(varname) |
202 | 46 | if orig_value is not None: | 47 | if orig_value is not None: |
203 | @@ -52,3 +53,6 @@ | |||
204 | 52 | os.environ[varname] = self.newvalue | 53 | os.environ[varname] = self.newvalue |
205 | 53 | else: | 54 | else: |
206 | 54 | os.environ.pop(varname, '') | 55 | os.environ.pop(varname, '') |
207 | 56 | |||
208 | 57 | |||
209 | 58 | EnvironmentVariableFixture = EnvironmentVariable | ||
210 | 55 | 59 | ||
211 | === modified file 'lib/fixtures/_fixtures/logger.py' | |||
212 | --- lib/fixtures/_fixtures/logger.py 2011-11-22 08:58:59 +0000 | |||
213 | +++ lib/fixtures/_fixtures/logger.py 2011-11-25 17:48:24 +0000 | |||
214 | @@ -19,15 +19,16 @@ | |||
215 | 19 | from fixtures import Fixture | 19 | from fixtures import Fixture |
216 | 20 | 20 | ||
217 | 21 | __all__ = [ | 21 | __all__ = [ |
218 | 22 | 'FakeLogger', | ||
219 | 22 | 'LoggerFixture', | 23 | 'LoggerFixture', |
220 | 23 | ] | 24 | ] |
221 | 24 | 25 | ||
222 | 25 | 26 | ||
224 | 26 | class LoggerFixture(Fixture): | 27 | class FakeLogger(Fixture): |
225 | 27 | """Replace a logger and capture its output.""" | 28 | """Replace a logger and capture its output.""" |
226 | 28 | 29 | ||
227 | 29 | def __init__(self, name="", level=INFO, format=None, nuke_handlers=True): | 30 | def __init__(self, name="", level=INFO, format=None, nuke_handlers=True): |
229 | 30 | """Create a LoggerFixture. | 31 | """Create a FakeLogger fixture. |
230 | 31 | 32 | ||
231 | 32 | :param name: The name of the logger to replace. Defaults to "". | 33 | :param name: The name of the logger to replace. Defaults to "". |
232 | 33 | :param level: The log level to set, defaults to INFO. | 34 | :param level: The log level to set, defaults to INFO. |
233 | @@ -43,14 +44,14 @@ | |||
234 | 43 | logging.info('message') | 44 | logging.info('message') |
235 | 44 | self.assertEqual('message', fixture.output) | 45 | self.assertEqual('message', fixture.output) |
236 | 45 | """ | 46 | """ |
238 | 46 | super(LoggerFixture, self).__init__() | 47 | super(FakeLogger, self).__init__() |
239 | 47 | self._name = name | 48 | self._name = name |
240 | 48 | self._level = level | 49 | self._level = level |
241 | 49 | self._format = format | 50 | self._format = format |
242 | 50 | self._nuke_handlers = nuke_handlers | 51 | self._nuke_handlers = nuke_handlers |
243 | 51 | 52 | ||
244 | 52 | def setUp(self): | 53 | def setUp(self): |
246 | 53 | super(LoggerFixture, self).setUp() | 54 | super(FakeLogger, self).setUp() |
247 | 54 | self._output = StringIO() | 55 | self._output = StringIO() |
248 | 55 | logger = getLogger(self._name) | 56 | logger = getLogger(self._name) |
249 | 56 | if self._level: | 57 | if self._level: |
250 | @@ -71,3 +72,6 @@ | |||
251 | 71 | @property | 72 | @property |
252 | 72 | def output(self): | 73 | def output(self): |
253 | 73 | return self._output.getvalue() | 74 | return self._output.getvalue() |
254 | 75 | |||
255 | 76 | |||
256 | 77 | LoggerFixture = FakeLogger | ||
257 | 74 | 78 | ||
258 | === modified file 'lib/fixtures/_fixtures/popen.py' | |||
259 | --- lib/fixtures/_fixtures/popen.py 2010-10-15 02:41:18 +0000 | |||
260 | +++ lib/fixtures/_fixtures/popen.py 2011-11-25 17:48:24 +0000 | |||
261 | @@ -1,6 +1,6 @@ | |||
262 | 1 | # fixtures: Fixtures with cleanups for testing and convenience. | 1 | # fixtures: Fixtures with cleanups for testing and convenience. |
263 | 2 | # | 2 | # |
265 | 3 | # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> | 3 | # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> |
266 | 4 | # | 4 | # |
267 | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause |
268 | 6 | # license at the users choice. A copy of both licenses are available in the | 6 | # license at the users choice. A copy of both licenses are available in the |
269 | @@ -14,6 +14,7 @@ | |||
270 | 14 | # limitations under that license. | 14 | # limitations under that license. |
271 | 15 | 15 | ||
272 | 16 | __all__ = [ | 16 | __all__ = [ |
273 | 17 | 'FakePopen', | ||
274 | 17 | 'PopenFixture' | 18 | 'PopenFixture' |
275 | 18 | ] | 19 | ] |
276 | 19 | 20 | ||
277 | @@ -50,7 +51,7 @@ | |||
278 | 50 | return self.returncode | 51 | return self.returncode |
279 | 51 | 52 | ||
280 | 52 | 53 | ||
282 | 53 | class PopenFixture(Fixture): | 54 | class FakePopen(Fixture): |
283 | 54 | """Replace subprocess.Popen. | 55 | """Replace subprocess.Popen. |
284 | 55 | 56 | ||
285 | 56 | Primarily useful for testing, this fixture replaces subprocess.Popen with a | 57 | Primarily useful for testing, this fixture replaces subprocess.Popen with a |
286 | @@ -67,10 +68,11 @@ | |||
287 | 67 | call, and should return a dict with any desired attributes. | 68 | call, and should return a dict with any desired attributes. |
288 | 68 | e.g. return {'stdin': StringIO('foobar')} | 69 | e.g. return {'stdin': StringIO('foobar')} |
289 | 69 | """ | 70 | """ |
290 | 71 | super(FakePopen, self).__init__() | ||
291 | 70 | self.get_info = get_info | 72 | self.get_info = get_info |
292 | 71 | 73 | ||
293 | 72 | def setUp(self): | 74 | def setUp(self): |
295 | 73 | super(PopenFixture, self).setUp() | 75 | super(FakePopen, self).setUp() |
296 | 74 | self.addCleanup(setattr, subprocess, 'Popen', subprocess.Popen) | 76 | self.addCleanup(setattr, subprocess, 'Popen', subprocess.Popen) |
297 | 75 | subprocess.Popen = self | 77 | subprocess.Popen = self |
298 | 76 | self.procs = [] | 78 | self.procs = [] |
299 | @@ -83,3 +85,6 @@ | |||
300 | 83 | result = FakeProcess(proc_args, proc_info) | 85 | result = FakeProcess(proc_args, proc_info) |
301 | 84 | self.procs.append(result) | 86 | self.procs.append(result) |
302 | 85 | return result | 87 | return result |
303 | 88 | |||
304 | 89 | |||
305 | 90 | PopenFixture = FakePopen | ||
306 | 86 | 91 | ||
307 | === modified file 'lib/fixtures/tests/_fixtures/test_environ.py' | |||
308 | --- lib/fixtures/tests/_fixtures/test_environ.py 2010-10-17 09:45:38 +0000 | |||
309 | +++ lib/fixtures/tests/_fixtures/test_environ.py 2011-11-25 17:48:24 +0000 | |||
310 | @@ -1,6 +1,6 @@ | |||
311 | 1 | # fixtures: Fixtures with cleanups for testing and convenience. | 1 | # fixtures: Fixtures with cleanups for testing and convenience. |
312 | 2 | # | 2 | # |
314 | 3 | # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> | 3 | # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> |
315 | 4 | # | 4 | # |
316 | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause |
317 | 6 | # license at the users choice. A copy of both licenses are available in the | 6 | # license at the users choice. A copy of both licenses are available in the |
318 | @@ -17,59 +17,58 @@ | |||
319 | 17 | 17 | ||
320 | 18 | import testtools | 18 | import testtools |
321 | 19 | 19 | ||
327 | 20 | import fixtures | 20 | from fixtures import EnvironmentVariable, TestWithFixtures |
328 | 21 | from fixtures import EnvironmentVariableFixture, TestWithFixtures | 21 | |
329 | 22 | 22 | ||
330 | 23 | 23 | class TestEnvironmentVariable(testtools.TestCase, TestWithFixtures): | |
326 | 24 | class TestEnvironmentVariableFixture(testtools.TestCase, TestWithFixtures): | ||
331 | 25 | 24 | ||
332 | 26 | def test_setup_ignores_missing(self): | 25 | def test_setup_ignores_missing(self): |
334 | 27 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR') | 26 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR') |
335 | 28 | os.environ.pop('FIXTURES_TEST_VAR', '') | 27 | os.environ.pop('FIXTURES_TEST_VAR', '') |
336 | 29 | self.useFixture(fixture) | 28 | self.useFixture(fixture) |
337 | 30 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) | 29 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) |
338 | 31 | 30 | ||
339 | 32 | def test_setup_sets_when_missing(self): | 31 | def test_setup_sets_when_missing(self): |
341 | 33 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR', 'bar') | 32 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR', 'bar') |
342 | 34 | os.environ.pop('FIXTURES_TEST_VAR', '') | 33 | os.environ.pop('FIXTURES_TEST_VAR', '') |
343 | 35 | self.useFixture(fixture) | 34 | self.useFixture(fixture) |
344 | 36 | self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR')) | 35 | self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR')) |
345 | 37 | 36 | ||
346 | 38 | def test_setup_deletes(self): | 37 | def test_setup_deletes(self): |
348 | 39 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR') | 38 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR') |
349 | 40 | os.environ['FIXTURES_TEST_VAR'] = 'foo' | 39 | os.environ['FIXTURES_TEST_VAR'] = 'foo' |
350 | 41 | self.useFixture(fixture) | 40 | self.useFixture(fixture) |
351 | 42 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) | 41 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) |
352 | 43 | 42 | ||
353 | 44 | def test_setup_overrides(self): | 43 | def test_setup_overrides(self): |
355 | 45 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR', 'bar') | 44 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR', 'bar') |
356 | 46 | os.environ['FIXTURES_TEST_VAR'] = 'foo' | 45 | os.environ['FIXTURES_TEST_VAR'] = 'foo' |
357 | 47 | self.useFixture(fixture) | 46 | self.useFixture(fixture) |
358 | 48 | self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR')) | 47 | self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR')) |
359 | 49 | 48 | ||
360 | 50 | def test_cleanup_deletes_when_missing(self): | 49 | def test_cleanup_deletes_when_missing(self): |
362 | 51 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR') | 50 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR') |
363 | 52 | os.environ.pop('FIXTURES_TEST_VAR', '') | 51 | os.environ.pop('FIXTURES_TEST_VAR', '') |
364 | 53 | with fixture: | 52 | with fixture: |
365 | 54 | os.environ['FIXTURES_TEST_VAR'] = 'foo' | 53 | os.environ['FIXTURES_TEST_VAR'] = 'foo' |
366 | 55 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) | 54 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) |
367 | 56 | 55 | ||
368 | 57 | def test_cleanup_deletes_when_set(self): | 56 | def test_cleanup_deletes_when_set(self): |
370 | 58 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR', 'bar') | 57 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR', 'bar') |
371 | 59 | os.environ.pop('FIXTURES_TEST_VAR', '') | 58 | os.environ.pop('FIXTURES_TEST_VAR', '') |
372 | 60 | with fixture: | 59 | with fixture: |
373 | 61 | os.environ['FIXTURES_TEST_VAR'] = 'foo' | 60 | os.environ['FIXTURES_TEST_VAR'] = 'foo' |
374 | 62 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) | 61 | self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR')) |
375 | 63 | 62 | ||
376 | 64 | def test_cleanup_restores_when_missing(self): | 63 | def test_cleanup_restores_when_missing(self): |
378 | 65 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR') | 64 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR') |
379 | 66 | os.environ['FIXTURES_TEST_VAR'] = 'bar' | 65 | os.environ['FIXTURES_TEST_VAR'] = 'bar' |
380 | 67 | with fixture: | 66 | with fixture: |
381 | 68 | os.environ.pop('FIXTURES_TEST_VAR', '') | 67 | os.environ.pop('FIXTURES_TEST_VAR', '') |
382 | 69 | self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR')) | 68 | self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR')) |
383 | 70 | 69 | ||
384 | 71 | def test_cleanup_restores_when_set(self): | 70 | def test_cleanup_restores_when_set(self): |
386 | 72 | fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR') | 71 | fixture = EnvironmentVariable('FIXTURES_TEST_VAR') |
387 | 73 | os.environ['FIXTURES_TEST_VAR'] = 'bar' | 72 | os.environ['FIXTURES_TEST_VAR'] = 'bar' |
388 | 74 | with fixture: | 73 | with fixture: |
389 | 75 | os.environ['FIXTURES_TEST_VAR'] = 'quux' | 74 | os.environ['FIXTURES_TEST_VAR'] = 'quux' |
390 | 76 | 75 | ||
391 | === modified file 'lib/fixtures/tests/_fixtures/test_logger.py' | |||
392 | --- lib/fixtures/tests/_fixtures/test_logger.py 2011-11-22 08:12:48 +0000 | |||
393 | +++ lib/fixtures/tests/_fixtures/test_logger.py 2011-11-25 17:48:24 +0000 | |||
394 | @@ -18,13 +18,13 @@ | |||
395 | 18 | from testtools import TestCase | 18 | from testtools import TestCase |
396 | 19 | from cStringIO import StringIO | 19 | from cStringIO import StringIO |
397 | 20 | 20 | ||
402 | 21 | from fixtures import LoggerFixture, TestWithFixtures | 21 | from fixtures import FakeLogger, TestWithFixtures |
403 | 22 | 22 | ||
404 | 23 | 23 | ||
405 | 24 | class LoggerFixtureTest(TestCase, TestWithFixtures): | 24 | class FakeLoggerTest(TestCase, TestWithFixtures): |
406 | 25 | 25 | ||
407 | 26 | def setUp(self): | 26 | def setUp(self): |
409 | 27 | super(LoggerFixtureTest, self).setUp() | 27 | super(FakeLoggerTest, self).setUp() |
410 | 28 | self.logger = logging.getLogger() | 28 | self.logger = logging.getLogger() |
411 | 29 | self.addCleanup(self.removeHandlers, self.logger) | 29 | self.addCleanup(self.removeHandlers, self.logger) |
412 | 30 | 30 | ||
413 | @@ -33,7 +33,7 @@ | |||
414 | 33 | logger.removeHandler(handler) | 33 | logger.removeHandler(handler) |
415 | 34 | 34 | ||
416 | 35 | def test_output_property_has_output(self): | 35 | def test_output_property_has_output(self): |
418 | 36 | fixture = self.useFixture(LoggerFixture()) | 36 | fixture = self.useFixture(FakeLogger()) |
419 | 37 | logging.info("some message") | 37 | logging.info("some message") |
420 | 38 | self.assertEqual("some message\n", fixture.output) | 38 | self.assertEqual("some message\n", fixture.output) |
421 | 39 | 39 | ||
422 | @@ -43,7 +43,7 @@ | |||
423 | 43 | logger.addHandler(logging.StreamHandler(stream)) | 43 | logger.addHandler(logging.StreamHandler(stream)) |
424 | 44 | logger.setLevel(logging.INFO) | 44 | logger.setLevel(logging.INFO) |
425 | 45 | logging.info("one") | 45 | logging.info("one") |
427 | 46 | fixture = LoggerFixture() | 46 | fixture = FakeLogger() |
428 | 47 | with fixture: | 47 | with fixture: |
429 | 48 | logging.info("two") | 48 | logging.info("two") |
430 | 49 | logging.info("three") | 49 | logging.info("three") |
431 | @@ -54,7 +54,7 @@ | |||
432 | 54 | stream = StringIO() | 54 | stream = StringIO() |
433 | 55 | self.logger.addHandler(logging.StreamHandler(stream)) | 55 | self.logger.addHandler(logging.StreamHandler(stream)) |
434 | 56 | self.logger.setLevel(logging.INFO) | 56 | self.logger.setLevel(logging.INFO) |
436 | 57 | fixture = LoggerFixture(nuke_handlers=False) | 57 | fixture = FakeLogger(nuke_handlers=False) |
437 | 58 | with fixture: | 58 | with fixture: |
438 | 59 | logging.info("message") | 59 | logging.info("message") |
439 | 60 | self.assertEqual("message\n", fixture.output) | 60 | self.assertEqual("message\n", fixture.output) |
440 | @@ -62,7 +62,7 @@ | |||
441 | 62 | 62 | ||
442 | 63 | def test_logging_level_restored(self): | 63 | def test_logging_level_restored(self): |
443 | 64 | self.logger.setLevel(logging.DEBUG) | 64 | self.logger.setLevel(logging.DEBUG) |
445 | 65 | fixture = LoggerFixture(level=logging.WARNING) | 65 | fixture = FakeLogger(level=logging.WARNING) |
446 | 66 | with fixture: | 66 | with fixture: |
447 | 67 | # The fixture won't capture this, because the DEBUG level | 67 | # The fixture won't capture this, because the DEBUG level |
448 | 68 | # is lower than the WARNING one | 68 | # is lower than the WARNING one |
449 | @@ -72,7 +72,7 @@ | |||
450 | 72 | self.assertEqual(logging.DEBUG, self.logger.level) | 72 | self.assertEqual(logging.DEBUG, self.logger.level) |
451 | 73 | 73 | ||
452 | 74 | def test_custom_format(self): | 74 | def test_custom_format(self): |
454 | 75 | fixture = LoggerFixture(format="%(module)s") | 75 | fixture = FakeLogger(format="%(module)s") |
455 | 76 | self.useFixture(fixture) | 76 | self.useFixture(fixture) |
456 | 77 | logging.info("message") | 77 | logging.info("message") |
457 | 78 | self.assertEqual("test_logger\n", fixture.output) | 78 | self.assertEqual("test_logger\n", fixture.output) |
458 | 79 | 79 | ||
459 | === modified file 'lib/fixtures/tests/_fixtures/test_popen.py' | |||
460 | --- lib/fixtures/tests/_fixtures/test_popen.py 2011-07-26 23:07:48 +0000 | |||
461 | +++ lib/fixtures/tests/_fixtures/test_popen.py 2011-11-25 17:48:24 +0000 | |||
462 | @@ -1,6 +1,6 @@ | |||
463 | 1 | # fixtures: Fixtures with cleanups for testing and convenience. | 1 | # fixtures: Fixtures with cleanups for testing and convenience. |
464 | 2 | # | 2 | # |
466 | 3 | # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> | 3 | # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> |
467 | 4 | # | 4 | # |
468 | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause | 5 | # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause |
469 | 6 | # license at the users choice. A copy of both licenses are available in the | 6 | # license at the users choice. A copy of both licenses are available in the |
470 | @@ -21,15 +21,14 @@ | |||
471 | 21 | BytesIO, | 21 | BytesIO, |
472 | 22 | ) | 22 | ) |
473 | 23 | 23 | ||
476 | 24 | import fixtures | 24 | from fixtures import FakePopen, TestWithFixtures |
475 | 25 | from fixtures import PopenFixture, TestWithFixtures | ||
477 | 26 | from fixtures._fixtures.popen import FakeProcess | 25 | from fixtures._fixtures.popen import FakeProcess |
478 | 27 | 26 | ||
479 | 28 | 27 | ||
481 | 29 | class TestPopenFixture(testtools.TestCase, TestWithFixtures): | 28 | class TestFakePopen(testtools.TestCase, TestWithFixtures): |
482 | 30 | 29 | ||
483 | 31 | def test_installs_restores_global(self): | 30 | def test_installs_restores_global(self): |
485 | 32 | fixture = PopenFixture() | 31 | fixture = FakePopen() |
486 | 33 | popen = subprocess.Popen | 32 | popen = subprocess.Popen |
487 | 34 | fixture.setUp() | 33 | fixture.setUp() |
488 | 35 | try: | 34 | try: |
489 | @@ -39,7 +38,7 @@ | |||
490 | 39 | self.assertEqual(subprocess.Popen, popen) | 38 | self.assertEqual(subprocess.Popen, popen) |
491 | 40 | 39 | ||
492 | 41 | def test___call___is_recorded(self): | 40 | def test___call___is_recorded(self): |
494 | 42 | fixture = self.useFixture(PopenFixture()) | 41 | fixture = self.useFixture(FakePopen()) |
495 | 43 | proc = fixture(['foo', 'bar'], 1, None, 'in', 'out', 'err') | 42 | proc = fixture(['foo', 'bar'], 1, None, 'in', 'out', 'err') |
496 | 44 | self.assertEqual(1, len(fixture.procs)) | 43 | self.assertEqual(1, len(fixture.procs)) |
497 | 45 | self.assertEqual(dict(args=['foo', 'bar'], bufsize=1, executable=None, | 44 | self.assertEqual(dict(args=['foo', 'bar'], bufsize=1, executable=None, |
498 | @@ -48,7 +47,7 @@ | |||
499 | 48 | def test_inject_content_stdout(self): | 47 | def test_inject_content_stdout(self): |
500 | 49 | def get_info(args): | 48 | def get_info(args): |
501 | 50 | return {'stdout': 'stdout'} | 49 | return {'stdout': 'stdout'} |
503 | 51 | fixture = self.useFixture(PopenFixture(get_info)) | 50 | fixture = self.useFixture(FakePopen(get_info)) |
504 | 52 | proc = fixture(['foo']) | 51 | proc = fixture(['foo']) |
505 | 53 | self.assertEqual('stdout', proc.stdout) | 52 | self.assertEqual('stdout', proc.stdout) |
506 | 54 | 53 |