diff options
| author | Bastian Venthur <bastian.venthur@flixbus.com> | 2021-08-18 12:27:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-18 12:27:08 +0200 |
| commit | 5e9e1af94ef810336360ff83872f36ae61465dbc (patch) | |
| tree | 04a7d1abf131e8d4814683494ff2939f97b04ea1 /tests_feedgenerator | |
| parent | 4b9a12c9e30b69fc8c0fc05b126950ef1a64ae6c (diff) | |
| download | feedgenerator-5e9e1af94ef810336360ff83872f36ae61465dbc.tar.gz | |
Remove Python 2 (#27)
* removed __future__ imports and explicit encodings
* removed six dependency and code
* fixed py2/3 specific imports
* removed python2 specific code
* don't mention unittest2 anymore
Diffstat (limited to 'tests_feedgenerator')
| -rw-r--r-- | tests_feedgenerator/test_feedgenerator.py | 48 | ||||
| -rw-r--r-- | tests_feedgenerator/test_stringio.py | 97 | ||||
| -rw-r--r-- | tests_feedgenerator/usage_example.py | 10 |
3 files changed, 48 insertions, 107 deletions
diff --git a/tests_feedgenerator/test_feedgenerator.py b/tests_feedgenerator/test_feedgenerator.py index 6399f9d..6ec28aa 100644 --- a/tests_feedgenerator/test_feedgenerator.py +++ b/tests_feedgenerator/test_feedgenerator.py @@ -1,13 +1,5 @@ -# -*- encoding: utf-8 -*- +import unittest -from __future__ import unicode_literals - -try: - import unittest2 as unittest -except ImportError: - import unittest - -import six import datetime import feedgenerator @@ -73,7 +65,7 @@ class TestFeedGenerator(unittest.TestCase): self.maxDiff = None def test_000_types(self): - ty = six.text_type + ty = str for k, v in FIXT_FEED.items(): self.assertEqual(type(v), ty) for k, v in FIXT_ITEM.items(): @@ -88,21 +80,9 @@ class TestFeedGenerator(unittest.TestCase): feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED) feed.add_item(**FIXT_ITEM) result = feed.writeString(ENCODING) - if six.PY3: - # On Python 3, result of feedgenerator is a unicode string! - # So do not encode our expected_result. - expected_result = build_expected_rss_result(feed, EXPECTED_RESULT_RSS, None) - else: - # On Python 2, result of feedgenerator is a str string! - # Expected_result must therefore encoded likewise. - expected_result = build_expected_rss_result(feed, EXPECTED_RESULT_RSS, ENCODING) - # The different result types of Python 2 (str=bytes) and Python 3 - # (str=text=unicode) stems from a different implementation of StringIO. - # As I understand it, getvalue() in Python 2 returns the type you - # originally wrote into the buffer. In Python 3 getvalue() always - # returns a str (=text=unicode). - # See other test: test_stringio.py - #print type(result), type(expected_result) + # On Python 3, result of feedgenerator is a unicode string! + # So do not encode our expected_result. + expected_result = build_expected_rss_result(feed, EXPECTED_RESULT_RSS, None) self.assertEqual(type(result), type(expected_result)) self.assertEqual(result, expected_result) @@ -111,20 +91,8 @@ class TestFeedGenerator(unittest.TestCase): feed = feedgenerator.Atom1Feed(**FIXT_FEED) feed.add_item(**FIXT_ITEM) result = feed.writeString(ENCODING) - if six.PY3: - # On Python 3, result of feedgenerator is a unicode string! - # So do not encode our expected_result. - expected_result = build_expected_atom_result(feed, EXPECTED_RESULT_ATOM, None) - else: - # On Python 2, result of feedgenerator is a str string! - # Expected_result must therefore encoded likewise. - expected_result = build_expected_atom_result(feed, EXPECTED_RESULT_ATOM, ENCODING) - # The different result types of Python 2 (str=bytes) and Python 3 - # (str=text=unicode) stems from a different implementation of StringIO. - # As I understand it, getvalue() in Python 2 returns the type you - # originally wrote into the buffer. In Python 3 getvalue() always - # returns a str (=text=unicode). - # See other test: test_stringio.py - #print type(result), type(expected_result) + # On Python 3, result of feedgenerator is a unicode string! + # So do not encode our expected_result. + expected_result = build_expected_atom_result(feed, EXPECTED_RESULT_ATOM, None) self.assertEqual(type(result), type(expected_result)) self.assertEqual(result, expected_result) diff --git a/tests_feedgenerator/test_stringio.py b/tests_feedgenerator/test_stringio.py index 6689c2a..3791035 100644 --- a/tests_feedgenerator/test_stringio.py +++ b/tests_feedgenerator/test_stringio.py @@ -1,14 +1,6 @@ -# -*- encoding: utf-8 -*- +import unittest -from __future__ import unicode_literals, print_function - -try: - import unittest2 as unittest -except ImportError: - import unittest - -import six -from six import StringIO +from io import StringIO ENCODING = 'utf-8' @@ -22,62 +14,51 @@ class TestStringIO(unittest.TestCase): def test_001_text(self): # If we throw unicode into the StringIO buffer, we'll # get unicode out of it. - # Thank god this is the same in Python 2 and 3. - self.assertEqual(type(S0), six.text_type) + self.assertEqual(type(S0), str) buf = StringIO() print(S0, file=buf, end="") s1 = buf.getvalue() self.assertEqual(type(S0), type(s1)) self.assertEqual(S0, s1) - self.assertEqual(type(s1), six.text_type) + self.assertEqual(type(s1), str) def test_002_bytes(self): buf = StringIO() print(S0_BYTES, file=buf, end="") s1 = buf.getvalue() - - if six.PY3: - # In Python 3 StringIO *ALWAYS* returns str (=text=unicode) ! - # Even if we originally write bytes into the buffer, the value - # we get out of it has type str! - # Input is bytes - self.assertEqual(type(S0_BYTES), bytes) - # Output is NOT bytes... - self.assertNotEqual(type(S0_BYTES), type(s1)) - self.assertNotEqual(type(s1), bytes) - # ...but str! - self.assertEqual(type(s1), str) - # So the contents are not equal! - self.assertNotEqual(S0_BYTES, s1) - # StringIO coerced bytes into str: - # b'xyz' ---> "b'xyz'" - self.assertEqual(str(S0_BYTES), s1) - # See, the type info is literally present in the output str! - self.assertEqual("b'" + str(S0_BYTES, encoding=ENCODING) + "'", s1) - # Coercion is NOT decoding! - self.assertNotEqual(S0_BYTES.decode(ENCODING), s1) - self.assertNotEqual(str(S0_BYTES, encoding=ENCODING), s1) - # These are the same - self.assertEqual(S0_BYTES.decode(ENCODING), - str(S0_BYTES, encoding=ENCODING)) - # Additional note: - # If we do not specify an encoding when we create a StringIO - # buffer, Python 3 automatically uses the locale's preferred - # encoding: locale.getpreferredencoding() - # Cf. http://docs.python.org/release/3.0.1/library/io.html#io.TextIOWrapper - # In my case this is the same encoding as the encoding of this source file, - # namely UTF-8. If on your system both encodings are different, you may - # encounter other results than the above. - # - # In Python 3.2 the signature of StringIO() has changed. It is no more - # possible to specify an encoding here. - else: - # In Python 2 StringIO returns the type that we originally - # wrote into the buffer. - # Here we see that if we write bytes into the buffer, we'll get - # bytes out of it. - self.assertEqual(type(S0_BYTES), str) - self.assertEqual(type(S0_BYTES), type(s1)) - self.assertEqual(type(s1), str) - self.assertEqual(S0_BYTES, s1) + # In Python 3 StringIO *ALWAYS* returns str (=text=unicode) ! + # Even if we originally write bytes into the buffer, the value + # we get out of it has type str! + + # Input is bytes + self.assertEqual(type(S0_BYTES), bytes) + # Output is NOT bytes... + self.assertNotEqual(type(S0_BYTES), type(s1)) + self.assertNotEqual(type(s1), bytes) + # ...but str! + self.assertEqual(type(s1), str) + # So the contents are not equal! + self.assertNotEqual(S0_BYTES, s1) + # StringIO coerced bytes into str: + # b'xyz' ---> "b'xyz'" + self.assertEqual(str(S0_BYTES), s1) + # See, the type info is literally present in the output str! + self.assertEqual("b'" + str(S0_BYTES, encoding=ENCODING) + "'", s1) + # Coercion is NOT decoding! + self.assertNotEqual(S0_BYTES.decode(ENCODING), s1) + self.assertNotEqual(str(S0_BYTES, encoding=ENCODING), s1) + # These are the same + self.assertEqual(S0_BYTES.decode(ENCODING), + str(S0_BYTES, encoding=ENCODING)) + # Additional note: + # If we do not specify an encoding when we create a StringIO + # buffer, Python 3 automatically uses the locale's preferred + # encoding: locale.getpreferredencoding() + # Cf. http://docs.python.org/release/3.0.1/library/io.html#io.TextIOWrapper + # In my case this is the same encoding as the encoding of this source file, + # namely UTF-8. If on your system both encodings are different, you may + # encounter other results than the above. + # + # In Python 3.2 the signature of StringIO() has changed. It is no more + # possible to specify an encoding here. diff --git a/tests_feedgenerator/usage_example.py b/tests_feedgenerator/usage_example.py index 69f258b..043f8ce 100644 --- a/tests_feedgenerator/usage_example.py +++ b/tests_feedgenerator/usage_example.py @@ -1,10 +1,5 @@ -# -*- encoding: utf-8 -*- - -from __future__ import unicode_literals - import os import tempfile -import six import feedgenerator feed = feedgenerator.Rss201rev2Feed( @@ -23,10 +18,7 @@ feed.add_item( description="Testing." ) -if six.PY3: - FN_PREFIX = 'feed_py3-' -else: - FN_PREFIX = 'feed_py2-' +FN_PREFIX = 'feed_py3-' # Usage example in feedgenerator docs opens the file in text mode, not binary. # So we do this here likewise. |
