Test for second refactor pass
unknown
python
3 years ago
1.9 kB
18
Indexable
from __future__ import annotations
from main import (
_create_counter_id,
_get_billboard_chart_data,
_get_decade_input,
_scan_billboard_chart_data,
)
test_filepath = 'billboard_chart_test_data.json'
def test_load_data() -> None:
expected_data = {
'song': 'Rebel-\u0027rouser',
'artist': 'Duane Eddy His Twangy Guitar And The Rebels',
'this_week': 6,
'peak_position': 6,
'weeks_on_chart': 1,
}
actual_data = _get_billboard_chart_data(test_filepath)
assert expected_data in actual_data[0]['data']
def test_get_decade_input(monkeypatch) -> None:
# monkeypatch the "input" function, so that it returns "1950".
# This simulates the user entering "1950" in the terminal:
monkeypatch.setattr('builtins.input', lambda _: '1950')
year = _get_decade_input()
assert year == '1950'
def test_create_counter_id() -> None:
expected_id = 50000001
actual_id = _create_counter_id('1950')
assert expected_id == actual_id
def test_scan_billboard_chart_data() -> None:
expected_data = [
{'song_id': 50000001, 'year': '1958', 'artist': 'Ricky Nelson', 'song': 'Poor Little Fool', 'peak_position': 1},
{
'song_id': 50000002,
'year': '1958',
'artist': 'Perez Prado And His Orchestra',
'song': 'Patricia',
'peak_position': 2,
},
{'song_id': 50000003, 'year': '1958', 'artist': 'Bobby Darin', 'song': 'Splish Splash', 'peak_position': 3},
{
'song_id': 50000004,
'year': '1958',
'artist': 'Elvis Presley With The Jordanaires',
'song': 'Hard Headed Woman',
'peak_position': 4,
},
]
actual_data = _scan_billboard_chart_data(
_get_billboard_chart_data(test_filepath),
'1950',
_create_counter_id('1950'),
)
assert actual_data == expected_data
Editor is loading...