|
44 | 44 | from beets.util import displayable_path, syspath
|
45 | 45 |
|
46 | 46 |
|
47 |
| -class ItemTypesTest(PluginTestCase): |
48 |
| - def test_flex_field_type(self): |
49 |
| - class RatingPlugin(plugins.BeetsPlugin): |
50 |
| - item_types = {"rating": types.Float()} |
| 47 | +class TestPluginRegistration(PluginTestCase): |
| 48 | + class RatingPlugin(plugins.BeetsPlugin): |
| 49 | + item_types = {"rating": types.Float()} |
51 | 50 |
|
52 |
| - self.register_plugin(RatingPlugin) |
| 51 | + def __init__(self): |
| 52 | + super().__init__() |
| 53 | + self.register_listener("write", self.on_write) |
53 | 54 |
|
54 |
| - item = Item(path="apath", artist="aaa") |
55 |
| - item.add(self.lib) |
56 |
| - |
57 |
| - # Do not match unset values |
58 |
| - out = self.run_with_output("ls", "rating:1..3") |
59 |
| - assert "aaa" not in out |
60 |
| - |
61 |
| - self.run_command("modify", "rating=2", "--yes") |
62 |
| - |
63 |
| - # Match in range |
64 |
| - out = self.run_with_output("ls", "rating:1..3") |
65 |
| - assert "aaa" in out |
66 |
| - |
67 |
| - # Don't match out of range |
68 |
| - out = self.run_with_output("ls", "rating:3..5") |
69 |
| - assert "aaa" not in out |
70 |
| - |
71 |
| - |
72 |
| -class ItemWriteTest(PluginTestCase): |
73 |
| - def setUp(self): |
74 |
| - super().setUp() |
75 |
| - |
76 |
| - class EventListenerPlugin(plugins.BeetsPlugin): |
77 |
| - pass |
78 |
| - |
79 |
| - self.event_listener_plugin = EventListenerPlugin() |
80 |
| - self.register_plugin(EventListenerPlugin) |
81 |
| - |
82 |
| - def test_change_tags(self): |
| 55 | + @staticmethod |
83 | 56 | def on_write(item=None, path=None, tags=None):
|
84 | 57 | if tags["artist"] == "XXX":
|
85 | 58 | tags["artist"] = "YYY"
|
86 | 59 |
|
87 |
| - self.register_listener("write", on_write) |
88 |
| - |
89 |
| - item = self.add_item_fixture(artist="XXX") |
90 |
| - item.write() |
91 |
| - |
92 |
| - mediafile = MediaFile(syspath(item.path)) |
93 |
| - assert mediafile.artist == "YYY" |
94 |
| - |
95 |
| - def register_listener(self, event, func): |
96 |
| - self.event_listener_plugin.register_listener(event, func) |
| 60 | + def setUp(self): |
| 61 | + super().setUp() |
97 | 62 |
|
| 63 | + self.register_plugin(self.RatingPlugin) |
98 | 64 |
|
99 |
| -class ItemTypeConflictTest(PluginTestCase): |
100 |
| - class EventListenerPlugin(plugins.BeetsPlugin): |
101 |
| - item_types = {"duplicate": types.INTEGER} |
| 65 | + def test_field_type_registered(self): |
| 66 | + assert isinstance(Item._types.get("rating"), types.Float) |
102 | 67 |
|
103 |
| - def setUp(self): |
104 |
| - super().setUp() |
105 |
| - self.register_plugin(self.EventListenerPlugin) |
| 68 | + def test_duplicate_type(self): |
| 69 | + class DuplicateTypePlugin(plugins.BeetsPlugin): |
| 70 | + item_types = {"rating": types.INTEGER} |
106 | 71 |
|
107 |
| - def test_mismatch(self): |
108 |
| - class AdventListenerPlugin(plugins.BeetsPlugin): |
109 |
| - item_types = {"duplicate": types.FLOAT} |
| 72 | + self.register_plugin(DuplicateTypePlugin) |
| 73 | + with pytest.raises( |
| 74 | + plugins.PluginConflictError, match="already been defined" |
| 75 | + ): |
| 76 | + Item._types |
110 | 77 |
|
111 |
| - self.register_plugin(AdventListenerPlugin) |
112 |
| - with pytest.raises(plugins.PluginConflictError): |
113 |
| - plugins.types(Item) |
| 78 | + def test_listener_registered(self): |
| 79 | + self.RatingPlugin() |
| 80 | + item = self.add_item_fixture(artist="XXX") |
114 | 81 |
|
115 |
| - def test_match(self): |
116 |
| - class AdventListenerPlugin(plugins.BeetsPlugin): |
117 |
| - item_types = {"duplicate": types.INTEGER} |
| 82 | + item.write() |
118 | 83 |
|
119 |
| - self.register_plugin(AdventListenerPlugin) |
120 |
| - assert plugins.types(Item) |
| 84 | + assert MediaFile(syspath(item.path)).artist == "YYY" |
121 | 85 |
|
122 | 86 |
|
123 | 87 | class PluginImportTestCase(ImportHelper, PluginTestCase):
|
|
0 commit comments