summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastian Venthur <venthur@debian.org>2021-09-27 21:43:51 +0200
committerJustin Mayer <entroP@gmail.com>2021-09-28 12:57:20 +0200
commitd42117480d939c64f6706e1c282b9cbaba6170fd (patch)
tree9bef2b17b067e02f8072a6baa0358908efe8dbe9
parent1ab5258243a012cb372ea4c0772b13a288a127df (diff)
downloadfeedgenerator-d42117480d939c64f6706e1c282b9cbaba6170fd.tar.gz
Simplify tests by using pytest.mark.parametrize
-rw-r--r--tests_feedgenerator/test_feedgenerator.py122
1 files changed, 41 insertions, 81 deletions
diff --git a/tests_feedgenerator/test_feedgenerator.py b/tests_feedgenerator/test_feedgenerator.py
index e44eadb..fd80237 100644
--- a/tests_feedgenerator/test_feedgenerator.py
+++ b/tests_feedgenerator/test_feedgenerator.py
@@ -4,6 +4,8 @@ import datetime
import feedgenerator
+import pytest
+
FIXT_FEED = dict(
title="Poynter E-Media Tidbits",
link="http://www.poynter.org/column.asp?id=31",
@@ -97,84 +99,42 @@ class TestFeedGenerator(unittest.TestCase):
self.assertEqual(type(result), type(expected_result))
self.assertEqual(result, expected_result)
- def test_subtitle(self):
- """Test regression for https://github.com/getpelican/feedgenerator/issues/30.
-
- """
- # case 1: neither should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description=None,
- subtitle=None,
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle></subtitle>" not in result
-
- # case 1.b: neither should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description="",
- subtitle="",
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle></subtitle>" not in result
-
- # case 2: only description should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description="description",
- subtitle=None,
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle>description</subtitle>" in result
-
- # case 2.b: only description should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description="description",
- subtitle="",
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle>description</subtitle>" in result
-
- # case 3: only subtitle should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description=None,
- subtitle="subtitle",
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle>subtitle</subtitle>" in result
-
- # case 3.b: only subtitle should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description="",
- subtitle="subtitle",
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle>subtitle</subtitle>" in result
-
- # case 4: both are in, only subtitle should be in
- FIXT_FEED = dict(
- title="title",
- link="https://example.com",
- description="description",
- subtitle="subtitle",
- )
- feed = feedgenerator.Atom1Feed(**FIXT_FEED)
- result = feed.writeString(ENCODING)
- assert "<subtitle>subtitle</subtitle>" in result
- assert "<subtitle>description</subtitle>" not in 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