Merge lp:~jml/python-fixtures/normal-names-893539 into lp:~python-fixtures/python-fixtures/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
Reviewer Review Type Date Requested Status
python-fixtures committers Pending
Review via email: mp+83424@code.launchpad.net

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.

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

Subscribers

People subscribed via source and target branches