Skip to content

Commit

Permalink
Add test cases for substitute plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nichobi committed Sep 29, 2024
1 parent 3403a05 commit 5b54cc2
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions test/plugins/test_substitute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# This file is part of beets.
# Copyright 2024, Nicholas Boyd Isacsson.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

"""Test the substitute plugin regex functionality."""

import pytest

Check failure on line 17 in test/plugins/test_substitute.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (F401)

test/plugins/test_substitute.py:17:8: F401 `pytest` imported but unused

from beets.test.helper import PluginTestCase
from beetsplug.substitute import Substitute

PLUGIN_NAME = "substitute"

class SubstitutePluginTest(PluginTestCase):
plugin = "substitute"
preload_plugin = False

def test_simple_substitute(self):
with self.configure_plugin(
{
"a": "b",
"b": "c",
"c": "d",
}
):
cases = [
("a", "b"),
("b", "c"),
("c", "d")
]
for input, expected in cases:
assert Substitute().tmpl_substitute(input) == expected

def test_case_insensitivity(self):
with self.configure_plugin(
{ "a": "b" }
):
assert Substitute().tmpl_substitute("A") == "b"

def test_unmatched_input_preserved(self):
with self.configure_plugin(
{ "a": "b" }
):
assert Substitute().tmpl_substitute("c") == "c"

def test_regex_to_static(self):
with self.configure_plugin(
{ ".*jimi hendrix.*": "Jimi Hendrix" }
):
assert Substitute().tmpl_substitute("The Jimi Hendrix Experience") == "Jimi Hendrix"

Check failure on line 60 in test/plugins/test_substitute.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (E501)

test/plugins/test_substitute.py:60:89: E501 Line too long (96 > 88)

def test_regex_capture_group(self):
with self.configure_plugin(
{ "^(.*?)(,| &| and).*": r"\1" }
):
cases = [
("King Creosote & Jon Hopkins", "King Creosote"),
("Michael Hurley, The Holy Modal Rounders, Jeffrey Frederick & The Clamtones", "Michael Hurley"),

Check failure on line 68 in test/plugins/test_substitute.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (E501)

test/plugins/test_substitute.py:68:89: E501 Line too long (113 > 88)
("James Yorkston and the Athletes", "James Yorkston")
]
for case in cases:
assert Substitute().tmpl_substitute(case[0]) == case[1]

def test_partial_substitution(self):
with self.configure_plugin(
{
r"\.": "",
}
):
cases = [
("U.N.P.O.C.", "UNPOC"),
]
for input, expected in cases:
assert Substitute().tmpl_substitute(input) == expected


def test_break_on_first_match(self):
with self.configure_plugin(
{
"a": "b",
"[ab]": "c",
}
):
cases = [
("a", "b"),
("b", "c"),
]
for case in cases:
assert Substitute().tmpl_substitute(case[0]) == case[1]

0 comments on commit 5b54cc2

Please sign in to comment.