diff options
Diffstat (limited to 'tests_feedgenerator')
| -rw-r--r-- | tests_feedgenerator/__init__.py | 0 | ||||
| -rw-r--r-- | tests_feedgenerator/test_feedgenerator.py | 140 | ||||
| -rw-r--r-- | tests_feedgenerator/test_stringio.py | 64 | ||||
| -rw-r--r-- | tests_feedgenerator/usage_example.py | 30 |
4 files changed, 0 insertions, 234 deletions
diff --git a/tests_feedgenerator/__init__.py b/tests_feedgenerator/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tests_feedgenerator/__init__.py +++ /dev/null diff --git a/tests_feedgenerator/test_feedgenerator.py b/tests_feedgenerator/test_feedgenerator.py deleted file mode 100644 index fd80237..0000000 --- a/tests_feedgenerator/test_feedgenerator.py +++ /dev/null @@ -1,140 +0,0 @@ -import unittest - -import datetime - -import feedgenerator - -import pytest - -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 = """<?xml version="1.0" encoding="utf-8"?> -<rss version="2.0"><channel><title>Poynter E-Media Tidbits</title><link>http://www.poynter.org/column.asp?id=31</link><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. - </description><language>en</language><lastBuildDate>%DATE%</lastBuildDate><item><title>Hello</title><link>http://www.holovaty.com/test/</link><description>Testing.</description><pubDate>Thu, 11 Aug 2016 00:00:00 -0000</pubDate></item></channel></rss>""" - -EXPECTED_RESULT_ATOM = """<?xml version="1.0" encoding="utf-8"?> -<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Poynter E-Media Tidbits</title><link href="http://www.poynter.org/column.asp?id=31" rel="alternate"></link><id>http://www.poynter.org/column.asp?id=31</id><updated>%DATE%</updated><subtitle>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. - </subtitle><entry><title>Hello</title><link href="http://www.holovaty.com/test/" rel="alternate"></link><published>2016-08-11T00:00:00Z</published><updated>2016-08-11T00:00:00Z</updated><id>tag:www.holovaty.com,2016-08-11:/test/</id><summary type="html">Testing.</summary><content type="html">Full content of our testing entry.</content></entry></feed>""" - -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 - -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) - - -@pytest.mark.parametrize("description, subtitle, fragment, nonfragment", [ - # Neither description nor subtitle are provided - (None, None, None, "<subtitle></subtitle>"), - ("", "", None, "<subtitle></subtitle>"), - # Description is provided - ("description", None, "<subtitle>description</subtitle>", None), - ("description", "", "<subtitle>description</subtitle>", None), - # Subtitle is provided - (None, "subtitle", "<subtitle>subtitle</subtitle>", None), - ("", "subtitle", "<subtitle>subtitle</subtitle>", None), - # Both description & subtitle are provided; subtitle takes precedence - ("description", "subtitle", "<subtitle>subtitle</subtitle>", "<subtitle>description</subtitle>"), -]) -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 3791035..0000000 --- a/tests_feedgenerator/test_stringio.py +++ /dev/null @@ -1,64 +0,0 @@ -import unittest - -from io import StringIO - -ENCODING = 'utf-8' - -S0 = 'hello world, Umlauts: äöüßÄÖÜ, Chinese: 四是四,十是十,十四是十四,四十是四十,四十四隻不識字之石獅子是死的' -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. 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() |
