Skip to content

Commit

Permalink
chore: More snapshot testing, test dimension calculations (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare authored Dec 8, 2024
1 parent 11f1ffc commit ce0e1ca
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 53 deletions.
79 changes: 79 additions & 0 deletions tests/__snapshots__/test_suisa_sendemeldung.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,82 @@

'''
# ---
# name: test_get_csv
'''
Titel,Komponist,Interpret,Interpreten-Info,Sender,Sendedatum,Sendedauer,Sendezeit,Werkverzeichnisangaben,ISRC,Label,CD ID / Katalog-Nummer,Aufnahmedatum,Aufnahmeland,Erstveröffentlichungsdatum,Titel des Tonträgers (Albumtitel),Autor Text,Track Nummer,Genre,Programm,Bestellnummer,Marke,Label Code,EAN/GTIN,Identifikationsnummer

'''
# ---
# name: test_get_csv.1
'''
Titel,Komponist,Interpret,Interpreten-Info,Sender,Sendedatum,Sendedauer,Sendezeit,Werkverzeichnisangaben,ISRC,Label,CD ID / Katalog-Nummer,Aufnahmedatum,Aufnahmeland,Erstveröffentlichungsdatum,Titel des Tonträgers (Albumtitel),Autor Text,Track Nummer,Genre,Programm,Bestellnummer,Marke,Label Code,EAN/GTIN,Identifikationsnummer
Uhrenvergleich,,,,Station Name,19930301,00:01:00,13:12:00,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test
Meme Dub,Da Composah,Da Gang,,Station Name,19930301,00:01:00,13:37:00,,DEZ650710376,,,,,,"album, but string",,,,,,,,,crid://rabe.ch/v1/test
Bubbles,,"Mary's Surprise Act, Climmy Jiff",,Station Name,19930301,00:01:00,16:20:00,,DEZ650710376,Jane Records,,,,20221213,Da Alboom,,,,,,,,greedy-capitalist-number,crid://rabe.ch/v1/test
,,Artists as string not list,,Station Name,19930301,00:01:00,17:17:17,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test
Long Playing,,,,Station Name,19930301,19:48:57,18:18:18,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test
composer in works,Worker,,,Station Name,19930301,19:48:57,18:18:18,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test
composer better in works,composer,same,,Station Name,19930301,19:48:57,18:18:18,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test

'''
# ---
# name: test_get_xlsx
list([
tuple(
'Titel',
'Komponist',
'Interpret',
'Interpreten-Info',
'Sender',
'Sendedatum',
'Sendedauer',
'Sendezeit',
'Werkverzeichnisangaben',
'ISRC',
'Label',
'CD ID / Katalog-Nummer',
'Aufnahmedatum',
'Aufnahmeland',
'Erstveröffentlichungsdatum',
'Titel des Tonträgers (Albumtitel)',
'Autor Text',
'Track Nummer',
'Genre',
'Programm',
'Bestellnummer',
'Marke',
'Label Code',
'EAN/GTIN',
'Identifikationsnummer',
),
])
# ---
# name: test_get_xlsx.1
DimensionHolder({
'A': <ColumnDimension Instance, Attributes={'width': '8', 'customWidth': '1', 'min': '1', 'max': '1'}>,
'B': <ColumnDimension Instance, Attributes={'width': '12', 'customWidth': '1', 'min': '2', 'max': '2'}>,
'C': <ColumnDimension Instance, Attributes={'width': '12', 'customWidth': '1', 'min': '3', 'max': '3'}>,
'D': <ColumnDimension Instance, Attributes={'width': '19', 'customWidth': '1', 'min': '4', 'max': '4'}>,
'E': <ColumnDimension Instance, Attributes={'width': '9', 'customWidth': '1', 'min': '5', 'max': '5'}>,
'F': <ColumnDimension Instance, Attributes={'width': '13', 'customWidth': '1', 'min': '6', 'max': '6'}>,
'G': <ColumnDimension Instance, Attributes={'width': '13', 'customWidth': '1', 'min': '7', 'max': '7'}>,
'H': <ColumnDimension Instance, Attributes={'width': '12', 'customWidth': '1', 'min': '8', 'max': '8'}>,
'I': <ColumnDimension Instance, Attributes={'width': '25', 'customWidth': '1', 'min': '9', 'max': '9'}>,
'J': <ColumnDimension Instance, Attributes={'width': '7', 'customWidth': '1', 'min': '10', 'max': '10'}>,
'K': <ColumnDimension Instance, Attributes={'width': '8', 'customWidth': '1', 'min': '11', 'max': '11'}>,
'L': <ColumnDimension Instance, Attributes={'width': '25', 'customWidth': '1', 'min': '12', 'max': '12'}>,
'M': <ColumnDimension Instance, Attributes={'width': '16', 'customWidth': '1', 'min': '13', 'max': '13'}>,
'N': <ColumnDimension Instance, Attributes={'width': '15', 'customWidth': '1', 'min': '14', 'max': '14'}>,
'O': <ColumnDimension Instance, Attributes={'width': '29', 'customWidth': '1', 'min': '15', 'max': '15'}>,
'P': <ColumnDimension Instance, Attributes={'width': '36', 'customWidth': '1', 'min': '16', 'max': '16'}>,
'Q': <ColumnDimension Instance, Attributes={'width': '13', 'customWidth': '1', 'min': '17', 'max': '17'}>,
'R': <ColumnDimension Instance, Attributes={'width': '15', 'customWidth': '1', 'min': '18', 'max': '18'}>,
'S': <ColumnDimension Instance, Attributes={'width': '8', 'customWidth': '1', 'min': '19', 'max': '19'}>,
'T': <ColumnDimension Instance, Attributes={'width': '11', 'customWidth': '1', 'min': '20', 'max': '20'}>,
'U': <ColumnDimension Instance, Attributes={'width': '16', 'customWidth': '1', 'min': '21', 'max': '21'}>,
'V': <ColumnDimension Instance, Attributes={'width': '8', 'customWidth': '1', 'min': '22', 'max': '22'}>,
'W': <ColumnDimension Instance, Attributes={'width': '13', 'customWidth': '1', 'min': '23', 'max': '23'}>,
'X': <ColumnDimension Instance, Attributes={'width': '11', 'customWidth': '1', 'min': '24', 'max': '24'}>,
'Y': <ColumnDimension Instance, Attributes={'width': '24', 'customWidth': '1', 'min': '25', 'max': '25'}>,
})
# ---
59 changes: 6 additions & 53 deletions tests/test_suisa_sendemeldung.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,14 @@ def test_funge_release_date(test_date, expected):


@patch("cridlib.get")
def test_get_csv(mock_cridlib_get):
def test_get_csv(mock_cridlib_get, snapshot):
"""Test get_csv."""
mock_cridlib_get.return_value = "crid://rabe.ch/v1/test"

# empty data
data = []
csv = suisa_sendemeldung.get_csv(data)
# pylint: disable=line-too-long
assert csv == (
"Titel,Komponist,Interpret,Interpreten-Info,Sender,Sendedatum,Sendedauer,Sendezeit,Werkverzeichnisangaben,ISRC,Label,CD ID / Katalog-Nummer,Aufnahmedatum,Aufnahmeland,Erstveröffentlichungsdatum,Titel des Tonträgers (Albumtitel),Autor Text,Track Nummer,Genre,Programm,Bestellnummer,Marke,Label Code,EAN/GTIN,Identifikationsnummer\r\n" # noqa: E501
)
# pylint: enable=line-too-long
assert csv == snapshot
mock_cridlib_get.assert_not_called()

# bunch of data
Expand Down Expand Up @@ -327,21 +323,7 @@ def test_get_csv(mock_cridlib_get):
},
]
csv = suisa_sendemeldung.get_csv(data, station_name="Station Name")
# pylint: disable=line-too-long
assert (
csv
== (
"Titel,Komponist,Interpret,Interpreten-Info,Sender,Sendedatum,Sendedauer,Sendezeit,Werkverzeichnisangaben,ISRC,Label,CD ID / Katalog-Nummer,Aufnahmedatum,Aufnahmeland,Erstveröffentlichungsdatum,Titel des Tonträgers (Albumtitel),Autor Text,Track Nummer,Genre,Programm,Bestellnummer,Marke,Label Code,EAN/GTIN,Identifikationsnummer\r\n" # noqa: E501
"Uhrenvergleich,,,,Station Name,19930301,00:01:00,13:12:00,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test\r\n"
'Meme Dub,Da Composah,Da Gang,,Station Name,19930301,00:01:00,13:37:00,,DEZ650710376,,,,,,"album, but string",,,,,,,,,crid://rabe.ch/v1/test\r\n' # noqa: E501
'Bubbles,,"Mary\'s Surprise Act, Climmy Jiff",,Station Name,19930301,00:01:00,16:20:00,,DEZ650710376,Jane Records,,,,20221213,Da Alboom,,,,,,,,greedy-capitalist-number,crid://rabe.ch/v1/test\r\n' # noqa: E501
",,Artists as string not list,,Station Name,19930301,00:01:00,17:17:17,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test\r\n"
"Long Playing,,,,Station Name,19930301,19:48:57,18:18:18,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test\r\n"
"composer in works,Worker,,,Station Name,19930301,19:48:57,18:18:18,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test\r\n"
"composer better in works,composer,same,,Station Name,19930301,19:48:57,18:18:18,,,,,,,,,,,,,,,,,crid://rabe.ch/v1/test\r\n"
)
)
# pylint: enable=line-too-long
assert csv == snapshot
mock_cridlib_get.assert_has_calls(
[
call(
Expand All @@ -368,45 +350,16 @@ def test_get_csv(mock_cridlib_get):
)


def test_get_xlsx():
def test_get_xlsx(snapshot):
"""Test get_xlsx."""

# empty data
data = []
xlsx = suisa_sendemeldung.get_xlsx(data)
workbook = load_workbook(xlsx)
worksheet = workbook.active
# pylint: disable=duplicate-code
assert list(worksheet.values) == [
(
"Titel",
"Komponist",
"Interpret",
"Interpreten-Info",
"Sender",
"Sendedatum",
"Sendedauer",
"Sendezeit",
"Werkverzeichnisangaben",
"ISRC",
"Label",
"CD ID / Katalog-Nummer",
"Aufnahmedatum",
"Aufnahmeland",
"Erstveröffentlichungsdatum",
"Titel des Tonträgers (Albumtitel)",
"Autor Text",
"Track Nummer",
"Genre",
"Programm",
"Bestellnummer",
"Marke",
"Label Code",
"EAN/GTIN",
"Identifikationsnummer",
),
]
# pylint: enable=duplicate-code
assert list(worksheet.values) == snapshot
assert worksheet.column_dimensions == snapshot


def test_get_email_attachment():
Expand Down

0 comments on commit ce0e1ca

Please sign in to comment.