1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
# This file is part of beets.
# Copyright 2021, Graham R. Cobb.
"""Tests for the 'bareasc' plugin."""
import unittest
from test.helper import capture_stdout, TestHelper
from beets import logging
class BareascPluginTest(unittest.TestCase, TestHelper):
"""Test bare ASCII query matching."""
def setUp(self):
"""Set up test environment for bare ASCII query matching."""
self.setup_beets()
self.log = logging.getLogger('beets.web')
self.config['bareasc']['prefix'] = '#'
self.load_plugins('bareasc')
# Add library elements. Note that self.lib.add overrides any "id=<n>"
# and assigns the next free id number.
self.add_item(title='with accents',
album_id=2,
artist='Antonín Dvořák')
self.add_item(title='without accents',
artist='Antonín Dvorak')
self.add_item(title='with umlaut',
album_id=2,
artist='Brüggen')
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.
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'}
)
def test_bareasc_list_output(self):
"""Bare-ASCII version of list command - check output."""
with capture_stdout() as output:
self.run_command('bareasc', 'with accents')
self.assertIn('Antonin Dvorak', output.getvalue())
def test_bareasc_format_output(self):
"""Bare-ASCII version of list -f command - check output."""
with capture_stdout() as output:
self.run_command('bareasc', 'with accents',
'-f', '$artist:: $title')
self.assertEqual('Antonin Dvorak:: with accents\n',
output.getvalue())
def suite():
"""loader."""
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|