diff --git a/SngFileLanguagePart.py b/SngFileLanguagePart.py index 2afa056..5aea039 100644 --- a/SngFileLanguagePart.py +++ b/SngFileLanguagePart.py @@ -6,7 +6,7 @@ logger = logging.getLogger(__name__) -class SngFileLanguagePart(abc.Abc): +class SngFileLanguagePart(abc.ABC): """Part of SngFile class used with language specific actions. Args: @@ -59,10 +59,19 @@ def get_content_unique_lang_markers(self) -> set: Returns: set of all language markers used within the song """ - not_implemented_link = "https://github.com/bensteUEM/SongBeamerQS/issues/61" - raise NotImplementedError(not_implemented_link) - # TODO@benste: Implement - # https://github.com/bensteUEM/SongBeamerQS/issues/61 + language_markers = [] + block: list + for block in self.content.values(): + slide: list + for slide in block[1:]: + line: str + for line in slide: + if line.startswith("##"): + language_markers.append(line[:3]) + else: + language_markers.append(None) + + return set(language_markers) def validate_language_count(self, fix: bool = False) -> bool: """Validate the language count option in header. diff --git a/ruff.toml b/ruff.toml index 3b68082..090142b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -29,6 +29,8 @@ ignore = [ "ERA001", # commented-out-code (ERA001)# "FBT", #flake8-boolean-trap (FBT) + "D100", # using class docstrings only module docstrings don't matter + # Unittest style instead of pytest "PT009", # pytest-unittest-assertion (PT009) "PT027", #pytest-unittest-raises-assertion (PT027) @@ -52,6 +54,10 @@ extend-ignore = [] #Skip rules that need more code cleaning... "E402" #import outside top-level ] +"tests/*" =[ + "S101", #pytest allow asserts +] + [lint.pydocstyle] convention = "google" diff --git a/tests/test_sng_language.py b/tests/test_sng_language.py new file mode 100644 index 0000000..667e213 --- /dev/null +++ b/tests/test_sng_language.py @@ -0,0 +1,60 @@ +from pathlib import Path + +import pytest + +from SngFile import SngFile + + +class TestSngLanguage: + """This class is used to test anything defined in SngFileLanguagePart.""" + + def test_sample_file(self) -> None: + """Checks that sample file is loaded as expceted.""" + path = Path("testData/Test") + filename = "sample_languages.sng" + sample_song = SngFile(filename=path / filename) + + expected_lang_count = 2 + assert int(sample_song.header["LangCount"]) == expected_lang_count + + @pytest.mark.parametrize( + ("filename", "expected_result", "verse"), + [ + (Path("testData/Test") / "sample_languages.sng", {None}, "Verse 1"), + (Path("testData/Test") / "sample_languages.sng", {"##1", "##2"}, "Verse 2"), + ( + Path("testData/EG Psalmen & Sonstiges") + / "709 Herr, sei nicht ferne.sng", + {"##1", "##3"}, + None, + ), + ], + ) + def test_get_content_unique_lang_markers( + self, + filename: Path, + expected_result: set, + verse: str | None, + ) -> None: + """Checks functionality of get_content_unique_lang_markers. + + Using 3. different cases + 1. sample with no verse markers + 2. sample with 2 language versemarkers + 3. psalm sample with ##1 and ##3 + + Sample file contains 2 verses, one with and one without language markers + therefore it is used twice - with one verse only in each case + + Argument + + Args: + filename: locationm of sng to use for testing + expected_result: result which is expected + verse: limit song to the one specified verse only. Defaults to None. + """ + # 1b. with language markers + sample_song = SngFile(filename=filename) + if verse: + sample_song.content = {verse: sample_song.content[verse]} + assert expected_result == sample_song.get_content_unique_lang_markers()