def _split(text): # TODO: make this logic common """Split an album title into parts. @param text: string to split into parts @return: name, kind, featuring """ kind = featuring = None # Strip featured artists match = re.search(RE_FEATURING, text, re.IGNORECASE | re.VERBOSE) if match: featuring = match.group(1) logging.debug("match found: {0}".format(featuring)) text = text.replace( match.group(0), '').strip() # remove the match from the remaining text # Strip song kinds for kind in settings.KINDS: re_kind = RE_KIND.replace('<kind>', kind) match = re.search(re_kind, text, re.IGNORECASE | re.VERBOSE) if match: logging.debug("match found: {0}".format(kind)) text = text.replace( match.group(0), '').strip() # remove the match from the remaining text break else: kind = None # Return parts return TextTitle.fromstring(text), TextEnum.fromstring( kind), TextList.fromstring(featuring)
def test_ep(self): """Verify an EP can be parsed.""" album = Album("Tracks (feat. The Artist) [EP]") self.assertEqual(TextTitle("Tracks"), album.name) self.assertEqual(TextEnum("EP"), album.kind) self.assertEqual(TextList("The Artist"), album.featuring) self.assertEqual("Tracks [EP]", str(album))
def _split(text): # TODO: make this logic common """Split an album title into parts. @param text: string to split into parts @return: name, kind, featuring """ kind = featuring = None # Strip featured artists match = re.search(RE_FEATURING, text, re.IGNORECASE | re.VERBOSE) if match: featuring = match.group(1) logging.debug("match found: {0}".format(featuring)) text = text.replace(match.group(0), '').strip() # remove the match from the remaining text # Strip song kinds for kind in settings.KINDS: re_kind = RE_KIND.replace('<kind>', kind) match = re.search(re_kind, text, re.IGNORECASE | re.VERBOSE) if match: logging.debug("match found: {0}".format(kind)) text = text.replace(match.group(0), '').strip() # remove the match from the remaining text break else: kind = None # Return parts return TextTitle.fromstring(text), TextEnum.fromstring(kind), TextList.fromstring(featuring)
def test_nominal(self): """Verify a normal album name can be parsed.""" album = Album("Album Name") self.assertEqual(TextTitle("Album Name"), album.name) self.assertEqual(None, album.year) self.assertEqual(None, album.kind) self.assertEqual(None, album.featuring) self.assertEqual("Album Name", str(album))
def test_threshold(self): """Verify the TextTitle threshold is correct.""" self.assertTrue( TextTitle("The Cat and the Hat") % TextTitle("cat an' the hat")) self.assertFalse( TextTitle("The Cat and the Hat") % TextTitle("cat and hat"))
def test_close(self): """Verify two similar text titles can be compared.""" a = TextTitle("The Cat and the Hat") b = TextTitle("The Cat & The Hat") self.assertComparison(a, b, False, True, 1.00)
def test_different(self): """Verify two different text titles can be compared.""" a = TextTitle("The Cat and the Hat") b = TextTitle("A Clockwork Orange") self.assertComparison(a, b, False, False, 0.32)
def test_identical(self): """Verify two identical text titles can be compared.""" a = TextTitle("The Cat and the Hat") b = TextTitle("The Cat and the Hat") self.assertComparison(a, b, True, True, 1.00)