summaryrefslogtreecommitdiff
path: root/fixtures/tests
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-02-25 10:44:57 +0000
committerStephen Finucane <stephenfin@redhat.com>2021-02-25 15:15:43 +0000
commitc4dfe1c8e1b536fe484cc641d94b53d079df8017 (patch)
tree6a5c6076e0bac85f27d508d40b360665f1e99ab1 /fixtures/tests
parent341ea07fafdf4e2a419279d6fb3032f1eba3228b (diff)
downloadfixtures-git-c4dfe1c8e1b536fe484cc641d94b53d079df8017.tar.gz
Remove six and other Python 2 handling code
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'fixtures/tests')
-rw-r--r--fixtures/tests/_fixtures/test_logger.py19
-rw-r--r--fixtures/tests/_fixtures/test_popen.py25
-rw-r--r--fixtures/tests/_fixtures/test_pythonpackage.py9
-rw-r--r--fixtures/tests/_fixtures/test_streams.py28
4 files changed, 34 insertions, 47 deletions
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())