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
=== modified file 'NEWS'
--- NEWS 2011-11-22 09:26:54 +0000
+++ NEWS 2011-11-25 17:48:24 +0000
@@ -8,7 +8,11 @@
88
9CHANGES:9CHANGES:
1010
11* EnvironmentVariableFixture now upcalls via super().11* EnvironmentVariableFixture, LoggerFixture, PopenFixture renamed to
12 EnvironmentVariable, FakeLogger and FakePopen respectively. All are still
13 available under their old, deprecated names. (Jonathan Lange, #893539)
14
15* EnvironmentVariable now upcalls via super().
12 (Jonathan Lange, #881120)16 (Jonathan Lange, #881120)
1317
140.3.7180.3.7
1519
=== modified file 'README'
--- README 2011-11-22 10:07:24 +0000
+++ README 2011-11-25 17:48:24 +0000
@@ -266,21 +266,30 @@
266includes a number of precanned fixtures. The API docs for fixtures will list266includes a number of precanned fixtures. The API docs for fixtures will list
267the complete set of these, should the dcs be out of date or not to hand.267the complete set of these, should the dcs be out of date or not to hand.
268268
269EnvironmentVariableFixture269EnvironmentVariable
270++++++++++++++++++++++++++270+++++++++++++++++++
271271
272Isolate your code from environmental variables, delete them or set them to a272Isolate your code from environmental variables, delete them or set them to a
273new value.273new value.
274274
275 >>> fixture = fixtures.EnvironmentVariableFixture('HOME')275 >>> fixture = fixtures.EnvironmentVariable('HOME')
276276
277LoggerFixture277FakeLogger
278+++++++++++++278++++++++++
279279
280Isolate your code from an external logging configuration - so that your test280Isolate your code from an external logging configuration - so that your test
281gets the output from logged messages, but they don't go to e.g. the console.281gets the output from logged messages, but they don't go to e.g. the console.
282282
283 >>> fixture = fixtures.LoggerFixture()283 >>> fixture = fixtures.FakeLogger()
284
285FakePopen
286+++++++++
287
288Pretend to run an external command rather than needing it to be present to run
289tests.
290
291 >>> from testtools.compat import BytesIO
292 >>> fixture = fixtures.FakePopen(lambda _:{'stdout': BytesIO('foobar')})
284293
285MonkeyPatch294MonkeyPatch
286+++++++++++295+++++++++++
@@ -300,15 +309,6 @@
300309
301 >>> fixture = fixtures.PackagePathEntry('package/name', '/foo/bar')310 >>> fixture = fixtures.PackagePathEntry('package/name', '/foo/bar')
302311
303PopenFixture
304++++++++++++
305
306Pretend to run an external command rather than needing it to be present to run
307tests.
308
309 >>> from testtools.compat import BytesIO
310 >>> fixture = fixtures.PopenFixture(lambda _:{'stdout': BytesIO('foobar')})
311
312PythonPackage312PythonPackage
313+++++++++++++313+++++++++++++
314314
315315
=== modified file 'lib/fixtures/__init__.py'
--- lib/fixtures/__init__.py 2011-11-22 08:58:38 +0000
+++ lib/fixtures/__init__.py 2011-11-25 17:48:24 +0000
@@ -1,6 +1,6 @@
1# fixtures: Fixtures with cleanups for testing and convenience.1# fixtures: Fixtures with cleanups for testing and convenience.
2#2#
3# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>3# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
4# 4#
5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6# license at the users choice. A copy of both licenses are available in the6# license at the users choice. A copy of both licenses are available in the
@@ -39,7 +39,10 @@
39__version__ = (0, 3, 8, 'beta', 0)39__version__ = (0, 3, 8, 'beta', 0)
4040
41__all__ = [41__all__ = [
42 'EnvironmentVariable',
42 'EnvironmentVariableFixture',43 'EnvironmentVariableFixture',
44 'FakeLogger',
45 'FakePopen',
43 'Fixture',46 'Fixture',
44 'FunctionFixture',47 'FunctionFixture',
45 'LoggerFixture',48 'LoggerFixture',
@@ -56,7 +59,10 @@
5659
57from fixtures.fixture import Fixture, FunctionFixture, MethodFixture60from fixtures.fixture import Fixture, FunctionFixture, MethodFixture
58from fixtures._fixtures import (61from fixtures._fixtures import (
62 EnvironmentVariable,
59 EnvironmentVariableFixture,63 EnvironmentVariableFixture,
64 FakeLogger,
65 FakePopen,
60 LoggerFixture,66 LoggerFixture,
61 MonkeyPatch,67 MonkeyPatch,
62 PackagePathEntry,68 PackagePathEntry,
@@ -69,7 +75,6 @@
6975
7076
71def test_suite():77def test_suite():
72 import unittest
73 import fixtures.tests78 import fixtures.tests
74 return fixtures.tests.test_suite()79 return fixtures.tests.test_suite()
7580
7681
=== modified file 'lib/fixtures/_fixtures/__init__.py'
--- lib/fixtures/_fixtures/__init__.py 2011-10-26 15:10:31 +0000
+++ lib/fixtures/_fixtures/__init__.py 2011-11-25 17:48:24 +0000
@@ -1,6 +1,6 @@
1# fixtures: Fixtures with cleanups for testing and convenience.1# fixtures: Fixtures with cleanups for testing and convenience.
2#2#
3# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>3# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
4# 4#
5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6# license at the users choice. A copy of both licenses are available in the6# license at the users choice. A copy of both licenses are available in the
@@ -17,7 +17,10 @@
17"""Included fixtures."""17"""Included fixtures."""
1818
19__all__ = [19__all__ = [
20 'EnvironmentVariable',
20 'EnvironmentVariableFixture',21 'EnvironmentVariableFixture',
22 'FakeLogger',
23 'FakePopen',
21 'LoggerFixture',24 'LoggerFixture',
22 'MonkeyPatch',25 'MonkeyPatch',
23 'PackagePathEntry',26 'PackagePathEntry',
@@ -28,10 +31,19 @@
28 ]31 ]
2932
3033
31from fixtures._fixtures.environ import EnvironmentVariableFixture34from fixtures._fixtures.environ import (
32from fixtures._fixtures.logger import LoggerFixture35 EnvironmentVariable,
36 EnvironmentVariableFixture,
37 )
38from fixtures._fixtures.logger import (
39 FakeLogger,
40 LoggerFixture,
41 )
33from fixtures._fixtures.monkeypatch import MonkeyPatch42from fixtures._fixtures.monkeypatch import MonkeyPatch
34from fixtures._fixtures.popen import PopenFixture43from fixtures._fixtures.popen import (
44 FakePopen,
45 PopenFixture,
46 )
35from fixtures._fixtures.packagepath import PackagePathEntry47from fixtures._fixtures.packagepath import PackagePathEntry
36from fixtures._fixtures.pythonpackage import PythonPackage48from fixtures._fixtures.pythonpackage import PythonPackage
37from fixtures._fixtures.pythonpath import PythonPathEntry49from fixtures._fixtures.pythonpath import PythonPathEntry
3850
=== modified file 'lib/fixtures/_fixtures/environ.py'
--- lib/fixtures/_fixtures/environ.py 2011-10-31 16:30:52 +0000
+++ lib/fixtures/_fixtures/environ.py 2011-11-25 17:48:24 +0000
@@ -14,6 +14,7 @@
14# limitations under that license.14# limitations under that license.
1515
16__all__ = [16__all__ = [
17 'EnvironmentVariable',
17 'EnvironmentVariableFixture'18 'EnvironmentVariableFixture'
18 ]19 ]
1920
@@ -22,11 +23,11 @@
22from fixtures import Fixture23from fixtures import Fixture
2324
2425
25class EnvironmentVariableFixture(Fixture):26class EnvironmentVariable(Fixture):
26 """Isolate a specific environment variable."""27 """Isolate a specific environment variable."""
2728
28 def __init__(self, varname, newvalue=None):29 def __init__(self, varname, newvalue=None):
29 """Create an EnvironmentVariableFixture.30 """Create an EnvironmentVariable fixture.
3031
31 :param varname: the name of the variable to isolate.32 :param varname: the name of the variable to isolate.
32 :param newvalue: A value to set the variable to. If None, the variable33 :param newvalue: A value to set the variable to. If None, the variable
@@ -35,12 +36,12 @@
35 During setup the variable will be deleted or assigned the requested36 During setup the variable will be deleted or assigned the requested
36 value, and this will be restored in cleanUp.37 value, and this will be restored in cleanUp.
37 """38 """
38 Fixture.__init__(self)39 super(EnvironmentVariable, self).__init__()
39 self.varname = varname40 self.varname = varname
40 self.newvalue = newvalue41 self.newvalue = newvalue
4142
42 def setUp(self):43 def setUp(self):
43 super(EnvironmentVariableFixture, self).setUp()44 super(EnvironmentVariable, self).setUp()
44 varname = self.varname45 varname = self.varname
45 orig_value = os.environ.get(varname)46 orig_value = os.environ.get(varname)
46 if orig_value is not None:47 if orig_value is not None:
@@ -52,3 +53,6 @@
52 os.environ[varname] = self.newvalue53 os.environ[varname] = self.newvalue
53 else:54 else:
54 os.environ.pop(varname, '')55 os.environ.pop(varname, '')
56
57
58EnvironmentVariableFixture = EnvironmentVariable
5559
=== modified file 'lib/fixtures/_fixtures/logger.py'
--- lib/fixtures/_fixtures/logger.py 2011-11-22 08:58:59 +0000
+++ lib/fixtures/_fixtures/logger.py 2011-11-25 17:48:24 +0000
@@ -19,15 +19,16 @@
19from fixtures import Fixture19from fixtures import Fixture
2020
21__all__ = [21__all__ = [
22 'FakeLogger',
22 'LoggerFixture',23 'LoggerFixture',
23 ]24 ]
2425
2526
26class LoggerFixture(Fixture):27class FakeLogger(Fixture):
27 """Replace a logger and capture its output."""28 """Replace a logger and capture its output."""
2829
29 def __init__(self, name="", level=INFO, format=None, nuke_handlers=True):30 def __init__(self, name="", level=INFO, format=None, nuke_handlers=True):
30 """Create a LoggerFixture.31 """Create a FakeLogger fixture.
3132
32 :param name: The name of the logger to replace. Defaults to "".33 :param name: The name of the logger to replace. Defaults to "".
33 :param level: The log level to set, defaults to INFO.34 :param level: The log level to set, defaults to INFO.
@@ -43,14 +44,14 @@
43 logging.info('message')44 logging.info('message')
44 self.assertEqual('message', fixture.output)45 self.assertEqual('message', fixture.output)
45 """46 """
46 super(LoggerFixture, self).__init__()47 super(FakeLogger, self).__init__()
47 self._name = name48 self._name = name
48 self._level = level49 self._level = level
49 self._format = format50 self._format = format
50 self._nuke_handlers = nuke_handlers51 self._nuke_handlers = nuke_handlers
5152
52 def setUp(self):53 def setUp(self):
53 super(LoggerFixture, self).setUp()54 super(FakeLogger, self).setUp()
54 self._output = StringIO()55 self._output = StringIO()
55 logger = getLogger(self._name) 56 logger = getLogger(self._name)
56 if self._level:57 if self._level:
@@ -71,3 +72,6 @@
71 @property72 @property
72 def output(self):73 def output(self):
73 return self._output.getvalue()74 return self._output.getvalue()
75
76
77LoggerFixture = FakeLogger
7478
=== modified file 'lib/fixtures/_fixtures/popen.py'
--- lib/fixtures/_fixtures/popen.py 2010-10-15 02:41:18 +0000
+++ lib/fixtures/_fixtures/popen.py 2011-11-25 17:48:24 +0000
@@ -1,6 +1,6 @@
1# fixtures: Fixtures with cleanups for testing and convenience.1# fixtures: Fixtures with cleanups for testing and convenience.
2#2#
3# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>3# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
4# 4#
5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6# license at the users choice. A copy of both licenses are available in the6# license at the users choice. A copy of both licenses are available in the
@@ -14,6 +14,7 @@
14# limitations under that license.14# limitations under that license.
1515
16__all__ = [16__all__ = [
17 'FakePopen',
17 'PopenFixture'18 'PopenFixture'
18 ]19 ]
1920
@@ -50,7 +51,7 @@
50 return self.returncode51 return self.returncode
5152
5253
53class PopenFixture(Fixture):54class FakePopen(Fixture):
54 """Replace subprocess.Popen.55 """Replace subprocess.Popen.
5556
56 Primarily useful for testing, this fixture replaces subprocess.Popen with a57 Primarily useful for testing, this fixture replaces subprocess.Popen with a
@@ -67,10 +68,11 @@
67 call, and should return a dict with any desired attributes.68 call, and should return a dict with any desired attributes.
68 e.g. return {'stdin': StringIO('foobar')}69 e.g. return {'stdin': StringIO('foobar')}
69 """70 """
71 super(FakePopen, self).__init__()
70 self.get_info = get_info72 self.get_info = get_info
7173
72 def setUp(self):74 def setUp(self):
73 super(PopenFixture, self).setUp()75 super(FakePopen, self).setUp()
74 self.addCleanup(setattr, subprocess, 'Popen', subprocess.Popen)76 self.addCleanup(setattr, subprocess, 'Popen', subprocess.Popen)
75 subprocess.Popen = self77 subprocess.Popen = self
76 self.procs = []78 self.procs = []
@@ -83,3 +85,6 @@
83 result = FakeProcess(proc_args, proc_info)85 result = FakeProcess(proc_args, proc_info)
84 self.procs.append(result)86 self.procs.append(result)
85 return result87 return result
88
89
90PopenFixture = FakePopen
8691
=== modified file 'lib/fixtures/tests/_fixtures/test_environ.py'
--- lib/fixtures/tests/_fixtures/test_environ.py 2010-10-17 09:45:38 +0000
+++ lib/fixtures/tests/_fixtures/test_environ.py 2011-11-25 17:48:24 +0000
@@ -1,6 +1,6 @@
1# fixtures: Fixtures with cleanups for testing and convenience.1# fixtures: Fixtures with cleanups for testing and convenience.
2#2#
3# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>3# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
4# 4#
5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6# license at the users choice. A copy of both licenses are available in the6# license at the users choice. A copy of both licenses are available in the
@@ -17,59 +17,58 @@
1717
18import testtools18import testtools
1919
20import fixtures20from fixtures import EnvironmentVariable, TestWithFixtures
21from fixtures import EnvironmentVariableFixture, TestWithFixtures21
2222
2323class TestEnvironmentVariable(testtools.TestCase, TestWithFixtures):
24class TestEnvironmentVariableFixture(testtools.TestCase, TestWithFixtures):
2524
26 def test_setup_ignores_missing(self):25 def test_setup_ignores_missing(self):
27 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR')26 fixture = EnvironmentVariable('FIXTURES_TEST_VAR')
28 os.environ.pop('FIXTURES_TEST_VAR', '')27 os.environ.pop('FIXTURES_TEST_VAR', '')
29 self.useFixture(fixture)28 self.useFixture(fixture)
30 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))29 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))
3130
32 def test_setup_sets_when_missing(self):31 def test_setup_sets_when_missing(self):
33 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR', 'bar')32 fixture = EnvironmentVariable('FIXTURES_TEST_VAR', 'bar')
34 os.environ.pop('FIXTURES_TEST_VAR', '')33 os.environ.pop('FIXTURES_TEST_VAR', '')
35 self.useFixture(fixture)34 self.useFixture(fixture)
36 self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR'))35 self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR'))
3736
38 def test_setup_deletes(self):37 def test_setup_deletes(self):
39 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR')38 fixture = EnvironmentVariable('FIXTURES_TEST_VAR')
40 os.environ['FIXTURES_TEST_VAR'] = 'foo'39 os.environ['FIXTURES_TEST_VAR'] = 'foo'
41 self.useFixture(fixture)40 self.useFixture(fixture)
42 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))41 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))
4342
44 def test_setup_overrides(self):43 def test_setup_overrides(self):
45 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR', 'bar')44 fixture = EnvironmentVariable('FIXTURES_TEST_VAR', 'bar')
46 os.environ['FIXTURES_TEST_VAR'] = 'foo'45 os.environ['FIXTURES_TEST_VAR'] = 'foo'
47 self.useFixture(fixture)46 self.useFixture(fixture)
48 self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR'))47 self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR'))
4948
50 def test_cleanup_deletes_when_missing(self):49 def test_cleanup_deletes_when_missing(self):
51 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR')50 fixture = EnvironmentVariable('FIXTURES_TEST_VAR')
52 os.environ.pop('FIXTURES_TEST_VAR', '')51 os.environ.pop('FIXTURES_TEST_VAR', '')
53 with fixture:52 with fixture:
54 os.environ['FIXTURES_TEST_VAR'] = 'foo'53 os.environ['FIXTURES_TEST_VAR'] = 'foo'
55 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))54 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))
56 55
57 def test_cleanup_deletes_when_set(self):56 def test_cleanup_deletes_when_set(self):
58 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR', 'bar')57 fixture = EnvironmentVariable('FIXTURES_TEST_VAR', 'bar')
59 os.environ.pop('FIXTURES_TEST_VAR', '')58 os.environ.pop('FIXTURES_TEST_VAR', '')
60 with fixture:59 with fixture:
61 os.environ['FIXTURES_TEST_VAR'] = 'foo'60 os.environ['FIXTURES_TEST_VAR'] = 'foo'
62 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))61 self.assertEqual(None, os.environ.get('FIXTURES_TEST_VAR'))
6362
64 def test_cleanup_restores_when_missing(self):63 def test_cleanup_restores_when_missing(self):
65 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR')64 fixture = EnvironmentVariable('FIXTURES_TEST_VAR')
66 os.environ['FIXTURES_TEST_VAR'] = 'bar'65 os.environ['FIXTURES_TEST_VAR'] = 'bar'
67 with fixture:66 with fixture:
68 os.environ.pop('FIXTURES_TEST_VAR', '')67 os.environ.pop('FIXTURES_TEST_VAR', '')
69 self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR'))68 self.assertEqual('bar', os.environ.get('FIXTURES_TEST_VAR'))
70 69
71 def test_cleanup_restores_when_set(self):70 def test_cleanup_restores_when_set(self):
72 fixture = EnvironmentVariableFixture('FIXTURES_TEST_VAR')71 fixture = EnvironmentVariable('FIXTURES_TEST_VAR')
73 os.environ['FIXTURES_TEST_VAR'] = 'bar'72 os.environ['FIXTURES_TEST_VAR'] = 'bar'
74 with fixture:73 with fixture:
75 os.environ['FIXTURES_TEST_VAR'] = 'quux'74 os.environ['FIXTURES_TEST_VAR'] = 'quux'
7675
=== modified file 'lib/fixtures/tests/_fixtures/test_logger.py'
--- lib/fixtures/tests/_fixtures/test_logger.py 2011-11-22 08:12:48 +0000
+++ lib/fixtures/tests/_fixtures/test_logger.py 2011-11-25 17:48:24 +0000
@@ -18,13 +18,13 @@
18from testtools import TestCase18from testtools import TestCase
19from cStringIO import StringIO19from cStringIO import StringIO
2020
21from fixtures import LoggerFixture, TestWithFixtures21from fixtures import FakeLogger, TestWithFixtures
2222
2323
24class LoggerFixtureTest(TestCase, TestWithFixtures):24class FakeLoggerTest(TestCase, TestWithFixtures):
2525
26 def setUp(self):26 def setUp(self):
27 super(LoggerFixtureTest, self).setUp()27 super(FakeLoggerTest, self).setUp()
28 self.logger = logging.getLogger()28 self.logger = logging.getLogger()
29 self.addCleanup(self.removeHandlers, self.logger)29 self.addCleanup(self.removeHandlers, self.logger)
3030
@@ -33,7 +33,7 @@
33 logger.removeHandler(handler)33 logger.removeHandler(handler)
3434
35 def test_output_property_has_output(self):35 def test_output_property_has_output(self):
36 fixture = self.useFixture(LoggerFixture())36 fixture = self.useFixture(FakeLogger())
37 logging.info("some message")37 logging.info("some message")
38 self.assertEqual("some message\n", fixture.output)38 self.assertEqual("some message\n", fixture.output)
3939
@@ -43,7 +43,7 @@
43 logger.addHandler(logging.StreamHandler(stream))43 logger.addHandler(logging.StreamHandler(stream))
44 logger.setLevel(logging.INFO)44 logger.setLevel(logging.INFO)
45 logging.info("one")45 logging.info("one")
46 fixture = LoggerFixture()46 fixture = FakeLogger()
47 with fixture:47 with fixture:
48 logging.info("two")48 logging.info("two")
49 logging.info("three")49 logging.info("three")
@@ -54,7 +54,7 @@
54 stream = StringIO()54 stream = StringIO()
55 self.logger.addHandler(logging.StreamHandler(stream))55 self.logger.addHandler(logging.StreamHandler(stream))
56 self.logger.setLevel(logging.INFO)56 self.logger.setLevel(logging.INFO)
57 fixture = LoggerFixture(nuke_handlers=False)57 fixture = FakeLogger(nuke_handlers=False)
58 with fixture:58 with fixture:
59 logging.info("message")59 logging.info("message")
60 self.assertEqual("message\n", fixture.output)60 self.assertEqual("message\n", fixture.output)
@@ -62,7 +62,7 @@
6262
63 def test_logging_level_restored(self):63 def test_logging_level_restored(self):
64 self.logger.setLevel(logging.DEBUG)64 self.logger.setLevel(logging.DEBUG)
65 fixture = LoggerFixture(level=logging.WARNING)65 fixture = FakeLogger(level=logging.WARNING)
66 with fixture:66 with fixture:
67 # The fixture won't capture this, because the DEBUG level67 # The fixture won't capture this, because the DEBUG level
68 # is lower than the WARNING one68 # is lower than the WARNING one
@@ -72,7 +72,7 @@
72 self.assertEqual(logging.DEBUG, self.logger.level)72 self.assertEqual(logging.DEBUG, self.logger.level)
7373
74 def test_custom_format(self):74 def test_custom_format(self):
75 fixture = LoggerFixture(format="%(module)s")75 fixture = FakeLogger(format="%(module)s")
76 self.useFixture(fixture)76 self.useFixture(fixture)
77 logging.info("message")77 logging.info("message")
78 self.assertEqual("test_logger\n", fixture.output)78 self.assertEqual("test_logger\n", fixture.output)
7979
=== modified file 'lib/fixtures/tests/_fixtures/test_popen.py'
--- lib/fixtures/tests/_fixtures/test_popen.py 2011-07-26 23:07:48 +0000
+++ lib/fixtures/tests/_fixtures/test_popen.py 2011-11-25 17:48:24 +0000
@@ -1,6 +1,6 @@
1# fixtures: Fixtures with cleanups for testing and convenience.1# fixtures: Fixtures with cleanups for testing and convenience.
2#2#
3# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>3# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
4# 4#
5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause5# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6# license at the users choice. A copy of both licenses are available in the6# license at the users choice. A copy of both licenses are available in the
@@ -21,15 +21,14 @@
21 BytesIO,21 BytesIO,
22 )22 )
2323
24import fixtures24from fixtures import FakePopen, TestWithFixtures
25from fixtures import PopenFixture, TestWithFixtures
26from fixtures._fixtures.popen import FakeProcess25from fixtures._fixtures.popen import FakeProcess
2726
2827
29class TestPopenFixture(testtools.TestCase, TestWithFixtures):28class TestFakePopen(testtools.TestCase, TestWithFixtures):
3029
31 def test_installs_restores_global(self):30 def test_installs_restores_global(self):
32 fixture = PopenFixture()31 fixture = FakePopen()
33 popen = subprocess.Popen32 popen = subprocess.Popen
34 fixture.setUp()33 fixture.setUp()
35 try:34 try:
@@ -39,7 +38,7 @@
39 self.assertEqual(subprocess.Popen, popen)38 self.assertEqual(subprocess.Popen, popen)
4039
41 def test___call___is_recorded(self):40 def test___call___is_recorded(self):
42 fixture = self.useFixture(PopenFixture())41 fixture = self.useFixture(FakePopen())
43 proc = fixture(['foo', 'bar'], 1, None, 'in', 'out', 'err')42 proc = fixture(['foo', 'bar'], 1, None, 'in', 'out', 'err')
44 self.assertEqual(1, len(fixture.procs))43 self.assertEqual(1, len(fixture.procs))
45 self.assertEqual(dict(args=['foo', 'bar'], bufsize=1, executable=None,44 self.assertEqual(dict(args=['foo', 'bar'], bufsize=1, executable=None,
@@ -48,7 +47,7 @@
48 def test_inject_content_stdout(self):47 def test_inject_content_stdout(self):
49 def get_info(args):48 def get_info(args):
50 return {'stdout': 'stdout'}49 return {'stdout': 'stdout'}
51 fixture = self.useFixture(PopenFixture(get_info))50 fixture = self.useFixture(FakePopen(get_info))
52 proc = fixture(['foo'])51 proc = fixture(['foo'])
53 self.assertEqual('stdout', proc.stdout)52 self.assertEqual('stdout', proc.stdout)
5453

Subscribers

People subscribed via source and target branches