mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Refactor to merge similar test methods
This commit is contained in:
parent
67d14a2e12
commit
9a843e5d6b
1 changed files with 16 additions and 90 deletions
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
"""Tests for the 'bareasc' plugin."""
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
from beets import logging
|
||||
|
|
@ -28,96 +27,23 @@ class BareascPluginTest(unittest.TestCase, TestHelper):
|
|||
self.add_item(title="without umlaut or e", artist="Bruggen")
|
||||
self.add_item(title="without umlaut with e", artist="Brueggen")
|
||||
|
||||
def test_search_normal_noaccent(self):
|
||||
"""Normal search, no accents, not using bare-ASCII match.
|
||||
def test_bareasc_search(self):
|
||||
test_cases = [
|
||||
("dvorak", ["without accents"]), # Normal search, no accents, not using bare-ASCII match.
|
||||
("dvořák", ["with accents"]), # Normal search, with accents, not using bare-ASCII match.
|
||||
("#dvorak", ["without accents", "with accents"]), # Bare-ASCII search, no accents.
|
||||
("#dvořák", ["without accents", "with accents"]), # Bare-ASCII search, with accents.
|
||||
("#dvořäk", ["without accents", "with accents"]), # Bare-ASCII search, with incorrect accent.
|
||||
("#Bruggen", ["without umlaut or e", "with umlaut"]), # Bare-ASCII search, with no umlaut.
|
||||
("#Brüggen", ["without umlaut or e", "with umlaut"]), # Bare-ASCII search, with umlaut.
|
||||
]
|
||||
|
||||
Finds just the unaccented entry.
|
||||
"""
|
||||
items = self.lib.items("dvorak")
|
||||
|
||||
self.assertEqual(len(items), 1)
|
||||
self.assertEqual([items[0].title], ["without accents"])
|
||||
|
||||
def test_search_normal_accent(self):
|
||||
"""Normal search, with accents, not using bare-ASCII match.
|
||||
|
||||
Finds just the accented entry.
|
||||
"""
|
||||
items = self.lib.items("dvořák")
|
||||
|
||||
self.assertEqual(len(items), 1)
|
||||
self.assertEqual([items[0].title], ["with accents"])
|
||||
|
||||
def test_search_bareasc_noaccent(self):
|
||||
"""Bare-ASCII search, no accents.
|
||||
|
||||
Finds both entries.
|
||||
"""
|
||||
items = self.lib.items("#dvorak")
|
||||
|
||||
self.assertEqual(len(items), 2)
|
||||
self.assertEqual(
|
||||
{items[0].title, items[1].title},
|
||||
{"without accents", "with accents"},
|
||||
)
|
||||
|
||||
def test_search_bareasc_accent(self):
|
||||
"""Bare-ASCII search, with accents.
|
||||
|
||||
Finds both entries.
|
||||
"""
|
||||
items = self.lib.items("#dvořák")
|
||||
|
||||
self.assertEqual(len(items), 2)
|
||||
self.assertEqual(
|
||||
{items[0].title, items[1].title},
|
||||
{"without accents", "with accents"},
|
||||
)
|
||||
|
||||
def test_search_bareasc_wrong_accent(self):
|
||||
"""Bare-ASCII search, with incorrect accent.
|
||||
|
||||
Finds both entries.
|
||||
"""
|
||||
items = self.lib.items("#dvořäk")
|
||||
|
||||
self.assertEqual(len(items), 2)
|
||||
self.assertEqual(
|
||||
{items[0].title, items[1].title},
|
||||
{"without accents", "with accents"},
|
||||
)
|
||||
|
||||
def test_search_bareasc_noumlaut(self):
|
||||
"""Bare-ASCII search, with no umlaut.
|
||||
|
||||
Finds entry with 'u' not 'ue', although German speaker would
|
||||
normally replace ü with ue.
|
||||
|
||||
This is expected behaviour for this simple plugin.
|
||||
"""
|
||||
items = self.lib.items("#Bruggen")
|
||||
|
||||
self.assertEqual(len(items), 2)
|
||||
self.assertEqual(
|
||||
{items[0].title, items[1].title},
|
||||
{"without umlaut or e", "with umlaut"},
|
||||
)
|
||||
|
||||
def test_search_bareasc_umlaut(self):
|
||||
"""Bare-ASCII search, with umlaut.
|
||||
|
||||
Finds entry with 'u' not 'ue', although German speaker would
|
||||
normally replace ü with ue.
|
||||
|
||||
This is expected behaviour for this simple plugin.
|
||||
"""
|
||||
items = self.lib.items("#Brüggen")
|
||||
|
||||
self.assertEqual(len(items), 2)
|
||||
self.assertEqual(
|
||||
{items[0].title, items[1].title},
|
||||
{"without umlaut or e", "with umlaut"},
|
||||
)
|
||||
for query, expected_titles in test_cases:
|
||||
with self.subTest(query=query, expected_titles=expected_titles):
|
||||
items = self.lib.items(query)
|
||||
titles = [item.title for item in items]
|
||||
self.assertEqual(len(items), len(expected_titles))
|
||||
self.assertEqual(titles, expected_titles)
|
||||
|
||||
def test_bareasc_list_output(self):
|
||||
"""Bare-ASCII version of list command - check output."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue