From 63e1e42c4b6978530042637824a40887d9e377e3 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Wed, 29 Sep 2021 20:30:54 +0200 Subject: modernize test_feedgenerator.py --- tests_feedgenerator/test_feedgenerator.py | 77 +++++++++++++++---------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/tests_feedgenerator/test_feedgenerator.py b/tests_feedgenerator/test_feedgenerator.py index fd80237..c8a5b34 100644 --- a/tests_feedgenerator/test_feedgenerator.py +++ b/tests_feedgenerator/test_feedgenerator.py @@ -1,10 +1,9 @@ -import unittest - import datetime +import pytest + import feedgenerator -import pytest FIXT_FEED = dict( title="Poynter E-Media Tidbits", @@ -51,6 +50,7 @@ def build_expected_rss_result(feed, expected_result, encoding): else: return s + def build_expected_atom_result(feed, expected_result, encoding): # Result's date is of course different from the date in the fixture. # So make them equal! @@ -61,43 +61,40 @@ def build_expected_atom_result(feed, expected_result, encoding): else: return s -class TestFeedGenerator(unittest.TestCase): - - def setUp(self): - self.maxDiff = None - - def test_000_types(self): - ty = str - for k, v in FIXT_FEED.items(): - self.assertEqual(type(v), ty) - for k, v in FIXT_ITEM.items(): - if k == "pubdate" or k == "updateddate": - self.assertEqual(type(v), datetime.datetime) - else: - self.assertEqual(type(v), ty) - self.assertEqual(type(EXPECTED_RESULT_RSS), ty) - - def test_001_string_results_rss(self): - #import ipdb; ipdb.set_trace() - feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED) - feed.add_item(**FIXT_ITEM) - result = feed.writeString(ENCODING) - # 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) - - def test_002_string_results_atom(self): - #import ipdb; ipdb.set_trace() - feed = feedgenerator.Atom1Feed(**FIXT_FEED) - feed.add_item(**FIXT_ITEM) - result = feed.writeString(ENCODING) - # 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) + +def test_000_types(): + for k, v in FIXT_FEED.items(): + assert isinstance(v, str) + for k, v in FIXT_ITEM.items(): + if k == "pubdate" or k == "updateddate": + assert isinstance(v, datetime.datetime) + else: + assert isinstance(v, str) + assert isinstance(EXPECTED_RESULT_RSS, str) + + +def test_001_string_results_rss(): + #import ipdb; ipdb.set_trace() + feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED) + feed.add_item(**FIXT_ITEM) + result = feed.writeString(ENCODING) + # 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) + assert isinstance(result, type(expected_result)) + assert result == expected_result + + +def test_002_string_results_atom(): + #import ipdb; ipdb.set_trace() + feed = feedgenerator.Atom1Feed(**FIXT_FEED) + feed.add_item(**FIXT_ITEM) + result = feed.writeString(ENCODING) + # 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) + assert isinstance(result, type(expected_result)) + assert result == expected_result @pytest.mark.parametrize("description, subtitle, fragment, nonfragment", [ -- cgit v1.2.1 From 280a3b8737038f45d4242e26896036525dc192ba Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Wed, 29 Sep 2021 20:38:21 +0200 Subject: modernize test_stringio.py --- tests_feedgenerator/test_stringio.py | 105 +++++++++++++++++------------------ 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/tests_feedgenerator/test_stringio.py b/tests_feedgenerator/test_stringio.py index 3791035..89e784f 100644 --- a/tests_feedgenerator/test_stringio.py +++ b/tests_feedgenerator/test_stringio.py @@ -1,5 +1,3 @@ -import unittest - from io import StringIO ENCODING = 'utf-8' @@ -9,56 +7,55 @@ S0_BYTES = 'fe fi foe fam'.encode(ENCODING) #print("###", StringIO, "###") -class TestStringIO(unittest.TestCase): - - def test_001_text(self): - # If we throw unicode into the StringIO buffer, we'll - # get unicode out of it. - 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), str) - - def test_002_bytes(self): - buf = StringIO() - print(S0_BYTES, file=buf, end="") - s1 = buf.getvalue() - - # 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. +def test_001_text(): + # If we throw unicode into the StringIO buffer, we'll + # get unicode out of it. + assert isinstance(S0, str) + buf = StringIO() + print(S0, file=buf, end="") + s1 = buf.getvalue() + assert isinstance(S0, type(s1)) + assert S0 == s1 + assert isinstance(s1, str) + + +def test_002_bytes(): + buf = StringIO() + print(S0_BYTES, file=buf, end="") + s1 = buf.getvalue() + + # 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 + assert isinstance(S0_BYTES, bytes) + # Output is NOT bytes... + assert not isinstance(S0_BYTES, type(s1)) + assert not isinstance(s1, bytes) + # ...but str! + assert isinstance(s1, str) + # So the contents are not equal! + assert S0_BYTES != s1 + # StringIO coerced bytes into str: + # b'xyz' ---> "b'xyz'" + assert str(S0_BYTES) == s1 + # See, the type info is literally present in the output str! + assert "b'" + str(S0_BYTES, encoding=ENCODING) + "'" == s1 + # Coercion is NOT decoding! + assert S0_BYTES.decode(ENCODING) != s1 + assert str(S0_BYTES, encoding=ENCODING) != s1 + # These are the same + assert 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. -- cgit v1.2.1 From 8bcc4d9119ed36c45ed7c2c68ac9aa5ab9c53ec2 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Wed, 29 Sep 2021 20:45:33 +0200 Subject: renamed test dir to more traditional "tests" --- MANIFEST.in | 2 +- setup.cfg | 2 +- setup.py | 2 +- tests/__init__.py | 0 tests/test_feedgenerator.py | 137 ++++++++++++++++++++++++++++++ tests/test_stringio.py | 61 +++++++++++++ tests/usage_example.py | 30 +++++++ tests_feedgenerator/__init__.py | 0 tests_feedgenerator/test_feedgenerator.py | 137 ------------------------------ tests_feedgenerator/test_stringio.py | 61 ------------- tests_feedgenerator/usage_example.py | 30 ------- 11 files changed, 231 insertions(+), 231 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_feedgenerator.py create mode 100644 tests/test_stringio.py create mode 100644 tests/usage_example.py delete mode 100644 tests_feedgenerator/__init__.py delete mode 100644 tests_feedgenerator/test_feedgenerator.py delete mode 100644 tests_feedgenerator/test_stringio.py delete mode 100644 tests_feedgenerator/usage_example.py diff --git a/MANIFEST.in b/MANIFEST.in index 7fecac1..9720425 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include README.rst LICENSE tox.ini -recursive-include tests_feedgenerator * +recursive-include tests * diff --git a/setup.cfg b/setup.cfg index 18a2b67..6836e34 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,6 +4,6 @@ force_manifest = 1 [tool:pytest] addopts = --cov=feedgenerator - --cov=tests_feedgenerator + --cov=tests --cov-report=html --cov-report=term-missing:skip-covered diff --git a/setup.py b/setup.py index 9a95646..36e8efb 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ MAINTAINER_EMAIL = 'authors@getpelican.com' KEYWORDS = "feed atom rss".split(' ') VERSION = '2.0.0' -TEST_SUITE = 'tests_feedgenerator' +TEST_SUITE = 'tests' REQUIRES = ['pytz >= 0a'] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_feedgenerator.py b/tests/test_feedgenerator.py new file mode 100644 index 0000000..c8a5b34 --- /dev/null +++ b/tests/test_feedgenerator.py @@ -0,0 +1,137 @@ +import datetime + +import pytest + +import feedgenerator + + +FIXT_FEED = dict( + title="Poynter E-Media Tidbits", + link="http://www.poynter.org/column.asp?id=31", + description="""A group Weblog by the sharpest minds in online media/journalism/publishing. + Umlauts: äöüßÄÖÜ + Chinese: 老师是四十四,是不是? + Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. + """, + language="en" +) +FIXT_ITEM = dict( + title="Hello", + link="http://www.holovaty.com/test/", + description="Testing.", + content="Full content of our testing entry.", + pubdate=datetime.datetime(2016,8,11,0,0,0,0), +) + + +EXPECTED_RESULT_RSS = """ +Poynter E-Media Tidbitshttp://www.poynter.org/column.asp?id=31A group Weblog by the sharpest minds in online media/journalism/publishing. + Umlauts: äöüßÄÖÜ + Chinese: 老师是四十四,是不是? + Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. + en%DATE%Hellohttp://www.holovaty.com/test/Testing.Thu, 11 Aug 2016 00:00:00 -0000""" + +EXPECTED_RESULT_ATOM = """ +Poynter E-Media Tidbitshttp://www.poynter.org/column.asp?id=31%DATE%A group Weblog by the sharpest minds in online media/journalism/publishing. + Umlauts: äöüßÄÖÜ + Chinese: 老师是四十四,是不是? + Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. + Hello2016-08-11T00:00:00Z2016-08-11T00:00:00Ztag:www.holovaty.com,2016-08-11:/test/Testing.Full content of our testing entry.""" + +ENCODING = 'utf-8' + +def build_expected_rss_result(feed, expected_result, encoding): + # Result's date is of course different from the date in the fixture. + # So make them equal! + d = feedgenerator.rfc2822_date(feed.latest_post_date()) + s = expected_result.replace('%DATE%', d) + if encoding: + return s.encode(encoding) + else: + return s + + +def build_expected_atom_result(feed, expected_result, encoding): + # Result's date is of course different from the date in the fixture. + # So make them equal! + d = feedgenerator.rfc3339_date(feed.latest_post_date()) + s = expected_result.replace('%DATE%', d) + if encoding: + return s.encode(encoding) + else: + return s + + +def test_000_types(): + for k, v in FIXT_FEED.items(): + assert isinstance(v, str) + for k, v in FIXT_ITEM.items(): + if k == "pubdate" or k == "updateddate": + assert isinstance(v, datetime.datetime) + else: + assert isinstance(v, str) + assert isinstance(EXPECTED_RESULT_RSS, str) + + +def test_001_string_results_rss(): + #import ipdb; ipdb.set_trace() + feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED) + feed.add_item(**FIXT_ITEM) + result = feed.writeString(ENCODING) + # 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) + assert isinstance(result, type(expected_result)) + assert result == expected_result + + +def test_002_string_results_atom(): + #import ipdb; ipdb.set_trace() + feed = feedgenerator.Atom1Feed(**FIXT_FEED) + feed.add_item(**FIXT_ITEM) + result = feed.writeString(ENCODING) + # 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) + assert isinstance(result, type(expected_result)) + assert result == expected_result + + +@pytest.mark.parametrize("description, subtitle, fragment, nonfragment", [ + # Neither description nor subtitle are provided + (None, None, None, ""), + ("", "", None, ""), + # Description is provided + ("description", None, "description", None), + ("description", "", "description", None), + # Subtitle is provided + (None, "subtitle", "subtitle", None), + ("", "subtitle", "subtitle", None), + # Both description & subtitle are provided; subtitle takes precedence + ("description", "subtitle", "subtitle", "description"), +]) +def test_subtitle(description, subtitle, fragment, nonfragment): + """Test regression for https://github.com/getpelican/feedgenerator/issues/30. + + We test against all four possible combinations of description x + subtitle parameters and additionally for None and "". + + description, subtitle are the values for the respective + feed-parameters. + + fragment and nonfragment are text fragments that should be in the + expected result or not. + + """ + FIXT_FEED = dict( + title="title", + link="https://example.com", + description=description, + subtitle=subtitle, + ) + feed = feedgenerator.Atom1Feed(**FIXT_FEED) + result = feed.writeString(ENCODING) + if fragment: + assert fragment in result + if nonfragment: + assert nonfragment not in result diff --git a/tests/test_stringio.py b/tests/test_stringio.py new file mode 100644 index 0000000..89e784f --- /dev/null +++ b/tests/test_stringio.py @@ -0,0 +1,61 @@ +from io import StringIO + +ENCODING = 'utf-8' + +S0 = 'hello world, Umlauts: äöüßÄÖÜ, Chinese: 四是四,十是十,十四是十四,四十是四十,四十四隻不識字之石獅子是死的' +S0_BYTES = 'fe fi foe fam'.encode(ENCODING) + +#print("###", StringIO, "###") + + +def test_001_text(): + # If we throw unicode into the StringIO buffer, we'll + # get unicode out of it. + assert isinstance(S0, str) + buf = StringIO() + print(S0, file=buf, end="") + s1 = buf.getvalue() + assert isinstance(S0, type(s1)) + assert S0 == s1 + assert isinstance(s1, str) + + +def test_002_bytes(): + buf = StringIO() + print(S0_BYTES, file=buf, end="") + s1 = buf.getvalue() + + # 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 + assert isinstance(S0_BYTES, bytes) + # Output is NOT bytes... + assert not isinstance(S0_BYTES, type(s1)) + assert not isinstance(s1, bytes) + # ...but str! + assert isinstance(s1, str) + # So the contents are not equal! + assert S0_BYTES != s1 + # StringIO coerced bytes into str: + # b'xyz' ---> "b'xyz'" + assert str(S0_BYTES) == s1 + # See, the type info is literally present in the output str! + assert "b'" + str(S0_BYTES, encoding=ENCODING) + "'" == s1 + # Coercion is NOT decoding! + assert S0_BYTES.decode(ENCODING) != s1 + assert str(S0_BYTES, encoding=ENCODING) != s1 + # These are the same + assert 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/usage_example.py b/tests/usage_example.py new file mode 100644 index 0000000..043f8ce --- /dev/null +++ b/tests/usage_example.py @@ -0,0 +1,30 @@ +import os +import tempfile +import feedgenerator + +feed = feedgenerator.Rss201rev2Feed( + title="Poynter E-Media Tidbits", + link="http://www.poynter.org/column.asp?id=31", + description="""A group Weblog by the sharpest minds in online media/journalism/publishing. + Umlauts: äöüßÄÖÜ + Chinese: 老师是四十四,是不是? + Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. + """, + language="en", +) +feed.add_item( + title="Hello", + link="http://www.holovaty.com/test/", + description="Testing." +) + +FN_PREFIX = 'feed_py3-' + +# Usage example in feedgenerator docs opens the file in text mode, not binary. +# So we do this here likewise. +fd, filename = tempfile.mkstemp(prefix=FN_PREFIX, suffix='.txt', text=True) +try: + fh = os.fdopen(fd, 'w') + feed.write(fh, 'utf-8') +finally: + fh.close() diff --git a/tests_feedgenerator/__init__.py b/tests_feedgenerator/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests_feedgenerator/test_feedgenerator.py b/tests_feedgenerator/test_feedgenerator.py deleted file mode 100644 index c8a5b34..0000000 --- a/tests_feedgenerator/test_feedgenerator.py +++ /dev/null @@ -1,137 +0,0 @@ -import datetime - -import pytest - -import feedgenerator - - -FIXT_FEED = dict( - title="Poynter E-Media Tidbits", - link="http://www.poynter.org/column.asp?id=31", - description="""A group Weblog by the sharpest minds in online media/journalism/publishing. - Umlauts: äöüßÄÖÜ - Chinese: 老师是四十四,是不是? - Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. - """, - language="en" -) -FIXT_ITEM = dict( - title="Hello", - link="http://www.holovaty.com/test/", - description="Testing.", - content="Full content of our testing entry.", - pubdate=datetime.datetime(2016,8,11,0,0,0,0), -) - - -EXPECTED_RESULT_RSS = """ -Poynter E-Media Tidbitshttp://www.poynter.org/column.asp?id=31A group Weblog by the sharpest minds in online media/journalism/publishing. - Umlauts: äöüßÄÖÜ - Chinese: 老师是四十四,是不是? - Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. - en%DATE%Hellohttp://www.holovaty.com/test/Testing.Thu, 11 Aug 2016 00:00:00 -0000""" - -EXPECTED_RESULT_ATOM = """ -Poynter E-Media Tidbitshttp://www.poynter.org/column.asp?id=31%DATE%A group Weblog by the sharpest minds in online media/journalism/publishing. - Umlauts: äöüßÄÖÜ - Chinese: 老师是四十四,是不是? - Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. - Hello2016-08-11T00:00:00Z2016-08-11T00:00:00Ztag:www.holovaty.com,2016-08-11:/test/Testing.Full content of our testing entry.""" - -ENCODING = 'utf-8' - -def build_expected_rss_result(feed, expected_result, encoding): - # Result's date is of course different from the date in the fixture. - # So make them equal! - d = feedgenerator.rfc2822_date(feed.latest_post_date()) - s = expected_result.replace('%DATE%', d) - if encoding: - return s.encode(encoding) - else: - return s - - -def build_expected_atom_result(feed, expected_result, encoding): - # Result's date is of course different from the date in the fixture. - # So make them equal! - d = feedgenerator.rfc3339_date(feed.latest_post_date()) - s = expected_result.replace('%DATE%', d) - if encoding: - return s.encode(encoding) - else: - return s - - -def test_000_types(): - for k, v in FIXT_FEED.items(): - assert isinstance(v, str) - for k, v in FIXT_ITEM.items(): - if k == "pubdate" or k == "updateddate": - assert isinstance(v, datetime.datetime) - else: - assert isinstance(v, str) - assert isinstance(EXPECTED_RESULT_RSS, str) - - -def test_001_string_results_rss(): - #import ipdb; ipdb.set_trace() - feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED) - feed.add_item(**FIXT_ITEM) - result = feed.writeString(ENCODING) - # 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) - assert isinstance(result, type(expected_result)) - assert result == expected_result - - -def test_002_string_results_atom(): - #import ipdb; ipdb.set_trace() - feed = feedgenerator.Atom1Feed(**FIXT_FEED) - feed.add_item(**FIXT_ITEM) - result = feed.writeString(ENCODING) - # 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) - assert isinstance(result, type(expected_result)) - assert result == expected_result - - -@pytest.mark.parametrize("description, subtitle, fragment, nonfragment", [ - # Neither description nor subtitle are provided - (None, None, None, ""), - ("", "", None, ""), - # Description is provided - ("description", None, "description", None), - ("description", "", "description", None), - # Subtitle is provided - (None, "subtitle", "subtitle", None), - ("", "subtitle", "subtitle", None), - # Both description & subtitle are provided; subtitle takes precedence - ("description", "subtitle", "subtitle", "description"), -]) -def test_subtitle(description, subtitle, fragment, nonfragment): - """Test regression for https://github.com/getpelican/feedgenerator/issues/30. - - We test against all four possible combinations of description x - subtitle parameters and additionally for None and "". - - description, subtitle are the values for the respective - feed-parameters. - - fragment and nonfragment are text fragments that should be in the - expected result or not. - - """ - FIXT_FEED = dict( - title="title", - link="https://example.com", - description=description, - subtitle=subtitle, - ) - feed = feedgenerator.Atom1Feed(**FIXT_FEED) - result = feed.writeString(ENCODING) - if fragment: - assert fragment in result - if nonfragment: - assert nonfragment not in result diff --git a/tests_feedgenerator/test_stringio.py b/tests_feedgenerator/test_stringio.py deleted file mode 100644 index 89e784f..0000000 --- a/tests_feedgenerator/test_stringio.py +++ /dev/null @@ -1,61 +0,0 @@ -from io import StringIO - -ENCODING = 'utf-8' - -S0 = 'hello world, Umlauts: äöüßÄÖÜ, Chinese: 四是四,十是十,十四是十四,四十是四十,四十四隻不識字之石獅子是死的' -S0_BYTES = 'fe fi foe fam'.encode(ENCODING) - -#print("###", StringIO, "###") - - -def test_001_text(): - # If we throw unicode into the StringIO buffer, we'll - # get unicode out of it. - assert isinstance(S0, str) - buf = StringIO() - print(S0, file=buf, end="") - s1 = buf.getvalue() - assert isinstance(S0, type(s1)) - assert S0 == s1 - assert isinstance(s1, str) - - -def test_002_bytes(): - buf = StringIO() - print(S0_BYTES, file=buf, end="") - s1 = buf.getvalue() - - # 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 - assert isinstance(S0_BYTES, bytes) - # Output is NOT bytes... - assert not isinstance(S0_BYTES, type(s1)) - assert not isinstance(s1, bytes) - # ...but str! - assert isinstance(s1, str) - # So the contents are not equal! - assert S0_BYTES != s1 - # StringIO coerced bytes into str: - # b'xyz' ---> "b'xyz'" - assert str(S0_BYTES) == s1 - # See, the type info is literally present in the output str! - assert "b'" + str(S0_BYTES, encoding=ENCODING) + "'" == s1 - # Coercion is NOT decoding! - assert S0_BYTES.decode(ENCODING) != s1 - assert str(S0_BYTES, encoding=ENCODING) != s1 - # These are the same - assert 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 deleted file mode 100644 index 043f8ce..0000000 --- a/tests_feedgenerator/usage_example.py +++ /dev/null @@ -1,30 +0,0 @@ -import os -import tempfile -import feedgenerator - -feed = feedgenerator.Rss201rev2Feed( - title="Poynter E-Media Tidbits", - link="http://www.poynter.org/column.asp?id=31", - description="""A group Weblog by the sharpest minds in online media/journalism/publishing. - Umlauts: äöüßÄÖÜ - Chinese: 老师是四十四,是不是? - Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin. - """, - language="en", -) -feed.add_item( - title="Hello", - link="http://www.holovaty.com/test/", - description="Testing." -) - -FN_PREFIX = 'feed_py3-' - -# Usage example in feedgenerator docs opens the file in text mode, not binary. -# So we do this here likewise. -fd, filename = tempfile.mkstemp(prefix=FN_PREFIX, suffix='.txt', text=True) -try: - fh = os.fdopen(fd, 'w') - feed.write(fh, 'utf-8') -finally: - fh.close() -- cgit v1.2.1