Skip to content

Commit

Permalink
implement get_content_unique_lang_markers #61
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteUEM committed May 22, 2024
1 parent 464e7f2 commit cc4a32f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
19 changes: 14 additions & 5 deletions SngFileLanguagePart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"

Expand Down
60 changes: 60 additions & 0 deletions tests/test_sng_language.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit cc4a32f

Please sign in to comment.