Handle incomplete historical jury lists
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
from radioeins_top100 import POINTS, derive_output_dir, parse_jury_page
|
||||
from radioeins_top100 import (
|
||||
POINTS,
|
||||
IncompleteJuryListError,
|
||||
build_argument_parser,
|
||||
decide_incomplete_list,
|
||||
derive_output_dir,
|
||||
parse_jury_page,
|
||||
)
|
||||
|
||||
|
||||
class RadioeinsTop100Tests(unittest.TestCase):
|
||||
@@ -67,6 +76,73 @@ class RadioeinsTop100Tests(unittest.TestCase):
|
||||
self.assertEqual(votes[7].artist, "Boxhmasters")
|
||||
self.assertEqual(votes[7].title, "Mogli")
|
||||
|
||||
def test_historical_rank_without_dot(self):
|
||||
votes = self.parse_fixture("love-aditya-sharma.html")
|
||||
|
||||
self.assertEqual((votes[4].rank, votes[4].artist, votes[4].title),
|
||||
(5, "Nick Drake", "Northern Sky"))
|
||||
|
||||
def test_historical_period_separator(self):
|
||||
christiane = self.parse_fixture("love-christiane-falk.html")
|
||||
sven = self.parse_fixture("love-sven-erik-stephan.html")
|
||||
|
||||
self.assertEqual((christiane[3].artist, christiane[3].title),
|
||||
("Jeff Buckley", "Hallelujah"))
|
||||
self.assertEqual((sven[6].artist, sven[6].title),
|
||||
("Cyndi Lauper", "Time After Time"))
|
||||
self.assertEqual(christiane[2].artist, "R.E.M.")
|
||||
|
||||
def test_incomplete_historical_list_is_rejected(self):
|
||||
with self.assertRaises(IncompleteJuryListError) as caught:
|
||||
self.parse_fixture("love-dagobert.html")
|
||||
|
||||
output = StringIO()
|
||||
with redirect_stdout(output):
|
||||
accepted = decide_incomplete_list(
|
||||
caught.exception,
|
||||
accept_incomplete=False,
|
||||
interactive=False,
|
||||
decision_helper=lambda _: self.fail("must not prompt"),
|
||||
)
|
||||
|
||||
self.assertFalse(accepted)
|
||||
self.assertIn("Dagobert", output.getvalue())
|
||||
self.assertEqual(caught.exception.missing_ranks, [10])
|
||||
|
||||
def test_incomplete_historical_list_is_accepted_interactively(self):
|
||||
with self.assertRaises(IncompleteJuryListError) as caught:
|
||||
self.parse_fixture("love-dagobert.html")
|
||||
|
||||
with redirect_stdout(StringIO()):
|
||||
accepted = decide_incomplete_list(
|
||||
caught.exception,
|
||||
accept_incomplete=False,
|
||||
interactive=True,
|
||||
decision_helper=lambda prompt: "yes",
|
||||
)
|
||||
|
||||
self.assertTrue(accepted)
|
||||
self.assertEqual(
|
||||
[(vote.rank, vote.points) for vote in caught.exception.votes],
|
||||
[(1, 12), (2, 10), (3, 8), (4, 7), (5, 6),
|
||||
(6, 5), (7, 4), (8, 3), (9, 2)],
|
||||
)
|
||||
|
||||
def test_accept_incomplete_option(self):
|
||||
args = build_argument_parser().parse_args(["--accept-incomplete"])
|
||||
self.assertTrue(args.accept_incomplete)
|
||||
|
||||
with self.assertRaises(IncompleteJuryListError) as caught:
|
||||
self.parse_fixture("love-dagobert.html")
|
||||
with redirect_stdout(StringIO()):
|
||||
accepted = decide_incomplete_list(
|
||||
caught.exception,
|
||||
accept_incomplete=args.accept_incomplete,
|
||||
interactive=False,
|
||||
decision_helper=lambda _: self.fail("must not prompt"),
|
||||
)
|
||||
self.assertTrue(accepted)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user