From ad50ae1ec9b478cdce7249df83693e66be0b08f2 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 15 Sep 2015 22:38:18 +0200 Subject: [PATCH] [test] Test authors.py module --- test/test_authors.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/test_authors.py diff --git a/test/test_authors.py b/test/test_authors.py new file mode 100644 index 00000000..ef9b93a2 --- /dev/null +++ b/test/test_authors.py @@ -0,0 +1,50 @@ +"""Tests of author parsing.""" + +# pylint: disable=too-few-public-methods + +import re +import unittest + +from patacrep import authors + +SPLIT_AUTHORS_DATA = [ + ("Edgar Allan Poe", ("Poe", "Edgar Allan")), + ("Richard M. Stallman", ("Stallman", "Richard M.")), + ("Georges Brassens", ("Brassens", "Georges")), + ("The Who", ("Who", "The")), + ("Cher", ("Cher", "")), + ] + +PROCESS_AUTHORS_DATA = [ + ( + "Lyrics by William Blake (from Milton, 1808), music by Hubert Parry (1916), and sung by The Royal\ Choir~of~FooBar (just here to show you how processing is done)", + [ + ("Blake", "William"), + ("Parry", "Hubert"), + ("Royal\ Choir~of~FooBar", "The"), + ] + ), + ] + +class TestAutors(unittest.TestCase): + """Test of author parsing.""" + + def test_split_author_names(self): + for argument, expected in SPLIT_AUTHORS_DATA: + with self.subTest(argument=argument, expected=expected): + self.assertEqual(authors.split_author_names(argument), expected) + + def test_processauthors(self): + for argument, expected in PROCESS_AUTHORS_DATA: + with self.subTest(argument=argument, expected=expected): + self.assertEqual( + authors.processauthors( + argument, + **authors.compile_authwords({ + "after": ["by"], + "ignore": ["anonymous"], + "sep": ['and'], + }) + ), + expected + )