diff options
| author | Stephen Finucane <stephenfin@redhat.com> | 2021-02-25 10:44:57 +0000 |
|---|---|---|
| committer | Stephen Finucane <stephenfin@redhat.com> | 2021-02-25 15:15:43 +0000 |
| commit | c4dfe1c8e1b536fe484cc641d94b53d079df8017 (patch) | |
| tree | 6a5c6076e0bac85f27d508d40b360665f1e99ab1 | |
| parent | 341ea07fafdf4e2a419279d6fb3032f1eba3228b (diff) | |
| download | fixtures-git-c4dfe1c8e1b536fe484cc641d94b53d079df8017.tar.gz | |
Remove six and other Python 2 handling code
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
| -rw-r--r-- | README | 2 | ||||
| -rw-r--r-- | fixtures/__init__.py | 6 | ||||
| -rw-r--r-- | fixtures/_fixtures/logger.py | 8 | ||||
| -rw-r--r-- | fixtures/_fixtures/monkeypatch.py | 5 | ||||
| -rw-r--r-- | fixtures/_fixtures/streams.py | 10 | ||||
| -rw-r--r-- | fixtures/callmany.py | 5 | ||||
| -rw-r--r-- | fixtures/fixture.py | 8 | ||||
| -rw-r--r-- | fixtures/tests/_fixtures/test_logger.py | 19 | ||||
| -rw-r--r-- | fixtures/tests/_fixtures/test_popen.py | 25 | ||||
| -rw-r--r-- | fixtures/tests/_fixtures/test_pythonpackage.py | 9 | ||||
| -rw-r--r-- | fixtures/tests/_fixtures/test_streams.py | 28 | ||||
| -rw-r--r-- | requirements.txt | 1 |
12 files changed, 45 insertions, 81 deletions
@@ -358,7 +358,7 @@ FakePopen Pretend to run an external command rather than needing it to be present to run tests. - >>> from testtools.compat import BytesIO + >>> from io import BytesIO >>> fixture = fixtures.FakePopen(lambda _:{'stdout': BytesIO('foobar')}) MockPatchObject diff --git a/fixtures/__init__.py b/fixtures/__init__.py index cef2af2..a47f9e8 100644 --- a/fixtures/__init__.py +++ b/fixtures/__init__.py @@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -29,7 +29,7 @@ Most users will want to look at TestWithFixtures and Fixture, to start with. # the version number: major, minor, micro, releaselevel, and serial. All # values except releaselevel are integers; the release level is 'alpha', # 'beta', 'candidate', or 'final'. The version_info value corresponding to the -# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a +# Python version 3.9 is (3, 9, 0, 'final', 0)." Additionally we use a # releaselevel of 'dev' for unreleased under-development code. # # If the releaselevel is 'alpha' then the major/minor/micro components are not diff --git a/fixtures/_fixtures/logger.py b/fixtures/_fixtures/logger.py index b60b7ec..562c1d9 100644 --- a/fixtures/_fixtures/logger.py +++ b/fixtures/_fixtures/logger.py @@ -16,9 +16,6 @@ from logging import StreamHandler, getLogger, INFO, Formatter import sys -import six -from testtools.compat import _u - from fixtures import Fixture from fixtures._fixtures.streams import StringStream @@ -66,7 +63,8 @@ class LogHandler(Fixture): class StreamHandlerRaiseException(StreamHandler): """Handler class that will raise an exception on formatting errors.""" def handleError(self, record): - six.reraise(*sys.exc_info()) + _, value, tb = sys.exc_info() + raise value.with_traceback(tb) class FakeLogger(Fixture): @@ -103,7 +101,7 @@ class FakeLogger(Fixture): self._formatter = formatter def _setUp(self): - name = _u("pythonlogging:'%s'") % self._name + name = "pythonlogging:'%s'" % self._name output = self.useFixture(StringStream(name)).stream self._output = output handler = StreamHandlerRaiseException(output) diff --git a/fixtures/_fixtures/monkeypatch.py b/fixtures/_fixtures/monkeypatch.py index 710a79c..3d9545e 100644 --- a/fixtures/_fixtures/monkeypatch.py +++ b/fixtures/_fixtures/monkeypatch.py @@ -15,7 +15,7 @@ __all__ = [ 'MonkeyPatch' - ] +] import functools import types @@ -24,9 +24,6 @@ from fixtures import Fixture _class_types = (type, ) -if getattr(types, 'ClassType', None): - # Python 2 has multiple types of classes. - _class_types = _class_types + (types.ClassType,) def _coerce_values(obj, name, new_value, sentinel): diff --git a/fixtures/_fixtures/streams.py b/fixtures/_fixtures/streams.py index 8ceb4fc..7686376 100644 --- a/fixtures/_fixtures/streams.py +++ b/fixtures/_fixtures/streams.py @@ -20,7 +20,6 @@ __all__ = [ ] import io -import sys from fixtures import Fixture import testtools @@ -69,15 +68,6 @@ def _string_stream_factory(): upper = io.TextIOWrapper(lower, encoding="utf8") # See http://bugs.python.org/issue7955 upper._CHUNK_SIZE = 1 - # In theory, this is sufficient and correct, but on Python2, - # upper.write(_b('foo")) will whinge louadly. - if sys.version_info[0] < 3: - upper_write = upper.write - def safe_write(str_or_bytes): - if type(str_or_bytes) is str: - str_or_bytes = str_or_bytes.decode('utf8') - return upper_write(str_or_bytes) - upper.write = safe_write return upper, lower diff --git a/fixtures/callmany.py b/fixtures/callmany.py index 1683b26..39b23ef 100644 --- a/fixtures/callmany.py +++ b/fixtures/callmany.py @@ -19,9 +19,6 @@ __all__ = [ import sys -from testtools.compat import ( - reraise, - ) from testtools.helpers import try_import @@ -86,7 +83,7 @@ class CallMany(object): if result and raise_errors: if 1 == len(result): error = result[0] - reraise(error[0], error[1], error[2]) + raise error[1].with_traceback(error[2]) else: raise MultipleExceptions(*result) if not raise_errors: diff --git a/fixtures/fixture.py b/fixtures/fixture.py index 2c8454b..cdfdc76 100644 --- a/fixtures/fixture.py +++ b/fixtures/fixture.py @@ -25,10 +25,6 @@ __all__ = [ import itertools import sys -import six -from testtools.compat import ( - advance_iterator, - ) from testtools.helpers import try_import from fixtures.callmany import ( @@ -46,7 +42,7 @@ def combine_details(source_details, target_details): new_name = name disambiguator = itertools.count(1) while new_name in target_details: - new_name = '%s-%d' % (name, advance_iterator(disambiguator)) + new_name = '%s-%d' % (name, next(disambiguator)) name = new_name target_details[name] = content_object @@ -211,7 +207,7 @@ class Fixture(object): if issubclass(err[0], Exception): raise MultipleExceptions(*errors) else: - six.reraise(*err) + raise err[1].with_traceback(err[2]) def _setUp(self): """Template method for subclasses to override. diff --git a/fixtures/tests/_fixtures/test_logger.py b/fixtures/tests/_fixtures/test_logger.py index f8e11cc..25d4813 100644 --- a/fixtures/tests/_fixtures/test_logger.py +++ b/fixtures/tests/_fixtures/test_logger.py @@ -13,13 +13,12 @@ # license you chose for the specific language governing permissions and # limitations under that license. +import io import logging -import sys import time import testtools from testtools import TestCase -from testtools.compat import StringIO from fixtures import ( FakeLogger, @@ -32,12 +31,8 @@ from fixtures import ( # testing formatter overrides. class FooFormatter(logging.Formatter): def format(self, record): - # custom formatters interface changes in python 3.2 - if sys.version_info < (3, 2): - self._fmt = "Foo " + self._fmt - else: - self._style = logging.PercentStyle("Foo " + self._style._fmt) - self._fmt = self._style._fmt + self._style = logging.PercentStyle("Foo " + self._style._fmt) + self._fmt = self._style._fmt return logging.Formatter.format(self, record) @@ -58,7 +53,7 @@ class FakeLoggerTest(TestCase, TestWithFixtures): self.assertEqual("some message\n", fixture.output) def test_replace_and_restore_handlers(self): - stream = StringIO() + stream = io.StringIO() logger = logging.getLogger() logger.addHandler(logging.StreamHandler(stream)) logger.setLevel(logging.INFO) @@ -71,7 +66,7 @@ class FakeLoggerTest(TestCase, TestWithFixtures): self.assertEqual("one\nthree\n", stream.getvalue()) def test_preserving_existing_handlers(self): - stream = StringIO() + stream = io.StringIO() self.logger.addHandler(logging.StreamHandler(stream)) self.logger.setLevel(logging.INFO) fixture = FakeLogger(nuke_handlers=False) @@ -174,7 +169,7 @@ class LogHandlerTest(TestCase, TestWithFixtures): self.assertEqual(["some message"], fixture.handler.msgs) def test_replace_and_restore_handlers(self): - stream = StringIO() + stream = io.StringIO() logger = logging.getLogger() logger.addHandler(logging.StreamHandler(stream)) logger.setLevel(logging.INFO) @@ -187,7 +182,7 @@ class LogHandlerTest(TestCase, TestWithFixtures): self.assertEqual("one\nthree\n", stream.getvalue()) def test_preserving_existing_handlers(self): - stream = StringIO() + stream = io.StringIO() self.logger.addHandler(logging.StreamHandler(stream)) self.logger.setLevel(logging.INFO) fixture = LogHandler(self.CustomHandler(), nuke_handlers=False) diff --git a/fixtures/tests/_fixtures/test_popen.py b/fixtures/tests/_fixtures/test_popen.py index ed9c2c7..b0af3d3 100644 --- a/fixtures/tests/_fixtures/test_popen.py +++ b/fixtures/tests/_fixtures/test_popen.py @@ -13,13 +13,10 @@ # license you chose for the specific language governing permissions and # limitations under that license. +import io import subprocess import testtools -from testtools.compat import ( - _b, - BytesIO, - ) from fixtures import FakePopen, TestWithFixtures from fixtures._fixtures.popen import FakeProcess @@ -92,23 +89,23 @@ class TestFakeProcess(testtools.TestCase): self.assertEqual(0, proc.returncode) def test_communicate_with_out(self): - proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) - self.assertEqual((_b('foo'), ''), proc.communicate()) + proc = FakeProcess({}, {'stdout': io.BytesIO(b'foo')}) + self.assertEqual((b'foo', ''), proc.communicate()) self.assertEqual(0, proc.returncode) def test_communicate_with_input(self): - proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) - self.assertEqual((_b('foo'), ''), proc.communicate(input=_b("bar"))) + proc = FakeProcess({}, {'stdout': io.BytesIO(b'foo')}) + self.assertEqual((b'foo', ''), proc.communicate(input=b'bar')) def test_communicate_with_input_and_stdin(self): - stdin = BytesIO() + stdin = io.BytesIO() proc = FakeProcess({}, {'stdin': stdin}) - proc.communicate(input=_b("hello")) - self.assertEqual(_b("hello"), stdin.getvalue()) + proc.communicate(input=b'hello') + self.assertEqual(b'hello', stdin.getvalue()) def test_communicate_with_timeout(self): - proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) - self.assertEqual((_b('foo'), ''), proc.communicate(timeout=10)) + proc = FakeProcess({}, {'stdout': io.BytesIO(b'foo')}) + self.assertEqual((b'foo', ''), proc.communicate(timeout=10)) def test_args(self): proc = FakeProcess({"args": ["ls", "-lh"]}, {}) @@ -133,4 +130,4 @@ class TestFakeProcess(testtools.TestCase): def test_wait_with_timeout_and_endtime(self): proc = FakeProcess({}, {}) - self.assertEqual(0 , proc.wait(timeout=4, endtime=7)) + self.assertEqual(0, proc.wait(timeout=4, endtime=7)) diff --git a/fixtures/tests/_fixtures/test_pythonpackage.py b/fixtures/tests/_fixtures/test_pythonpackage.py index 4e2160b..41ac1b6 100644 --- a/fixtures/tests/_fixtures/test_pythonpackage.py +++ b/fixtures/tests/_fixtures/test_pythonpackage.py @@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -16,7 +16,6 @@ import os.path import testtools -from testtools.compat import _b from fixtures import PythonPackage, TestWithFixtures @@ -32,7 +31,7 @@ class TestPythonPackage(testtools.TestCase, TestWithFixtures): fixture.cleanUp() def test_writes_package(self): - fixture = PythonPackage('foo', [('bar.py', _b('woo'))]) + fixture = PythonPackage('foo', [('bar.py', b'woo')]) fixture.setUp() try: self.assertEqual('', open(os.path.join(fixture.base, 'foo', @@ -43,7 +42,7 @@ class TestPythonPackage(testtools.TestCase, TestWithFixtures): fixture.cleanUp() def test_no__init__(self): - fixture = PythonPackage('foo', [('bar.py', _b('woo'))], init=False) + fixture = PythonPackage('foo', [('bar.py', b'woo')], init=False) fixture.setUp() try: self.assertFalse(os.path.exists(os.path.join(fixture.base, 'foo', diff --git a/fixtures/tests/_fixtures/test_streams.py b/fixtures/tests/_fixtures/test_streams.py index 68396cd..5d1c20d 100644 --- a/fixtures/tests/_fixtures/test_streams.py +++ b/fixtures/tests/_fixtures/test_streams.py @@ -14,10 +14,6 @@ # limitations under that license. from testtools import TestCase -from testtools.compat import ( - _b, - _u, - ) from testtools.matchers import Contains from fixtures import ( @@ -40,7 +36,7 @@ class TestByteStreams(TestCase): fixture = ByteStream(detail_name) with fixture: content = fixture.getDetails()[detail_name] - self.assertEqual(_u(""), content.as_text()) + self.assertEqual("", content.as_text()) def test_stream_content_in_details(self): detail_name = 'test' @@ -49,7 +45,7 @@ class TestByteStreams(TestCase): stream = fixture.stream content = fixture.getDetails()[detail_name] # Output after getDetails is called is included. - stream.write(_b("testing 1 2 3")) + stream.write(b"testing 1 2 3") self.assertEqual("testing 1 2 3", content.as_text()) def test_stream_content_reset(self): @@ -58,15 +54,15 @@ class TestByteStreams(TestCase): with fixture: stream = fixture.stream content = fixture.getDetails()[detail_name] - stream.write(_b("testing 1 2 3")) + stream.write(b"testing 1 2 3") with fixture: # The old content object returns the old usage - self.assertEqual(_u("testing 1 2 3"), content.as_text()) + self.assertEqual("testing 1 2 3", content.as_text()) content = fixture.getDetails()[detail_name] # A new fixture returns the new output: stream = fixture.stream - stream.write(_b("1 2 3 testing")) - self.assertEqual(_u("1 2 3 testing"), content.as_text()) + stream.write(b"1 2 3 testing") + self.assertEqual("1 2 3 testing", content.as_text()) class TestStringStreams(TestCase): @@ -76,7 +72,7 @@ class TestStringStreams(TestCase): fixture = StringStream(detail_name) with fixture: content = fixture.getDetails()[detail_name] - self.assertEqual(_u(""), content.as_text()) + self.assertEqual("", content.as_text()) def test_stream_content_in_details(self): detail_name = 'test' @@ -85,7 +81,7 @@ class TestStringStreams(TestCase): stream = fixture.stream content = fixture.getDetails()[detail_name] # Output after getDetails is called is included. - stream.write(_u("testing 1 2 3")) + stream.write("testing 1 2 3") self.assertEqual("testing 1 2 3", content.as_text()) def test_stream_content_reset(self): @@ -94,12 +90,12 @@ class TestStringStreams(TestCase): with fixture: stream = fixture.stream content = fixture.getDetails()[detail_name] - stream.write(_u("testing 1 2 3")) + stream.write("testing 1 2 3") with fixture: # The old content object returns the old usage - self.assertEqual(_u("testing 1 2 3"), content.as_text()) + self.assertEqual("testing 1 2 3", content.as_text()) content = fixture.getDetails()[detail_name] # A new fixture returns the new output: stream = fixture.stream - stream.write(_u("1 2 3 testing")) - self.assertEqual(_u("1 2 3 testing"), content.as_text()) + stream.write("1 2 3 testing") + self.assertEqual("1 2 3 testing", content.as_text()) diff --git a/requirements.txt b/requirements.txt index f1852fb..f9efc61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ pbr>=0.11 -six testtools>=0.9.22 |
