|
@@ -12,18 +12,18 @@ import symuid
|
|
|
TRACKS_DIR_PATH = os.path.join(os.path.dirname(__file__), 'tracks')
|
|
|
|
|
|
|
|
|
-def utc_dt(h=0):
|
|
|
- return dt.datetime(2018, 9, 26, h, tzinfo=dt.timezone.utc)
|
|
|
+def utc_dt(hour=0):
|
|
|
+ return dt.datetime(2018, 9, 26, hour, tzinfo=dt.timezone.utc)
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
def empty_id3_track(tmpdir):
|
|
|
- p = tmpdir.join('empty.mp3').strpath
|
|
|
+ path = tmpdir.join('empty.mp3').strpath
|
|
|
shutil.copyfile(
|
|
|
src=os.path.join(TRACKS_DIR_PATH, 'id3v2.4-empty.mp3'),
|
|
|
- dst=p,
|
|
|
+ dst=path,
|
|
|
)
|
|
|
- return symuid.Track(p)
|
|
|
+ return symuid.Track(path)
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('path', [
|
|
@@ -39,32 +39,33 @@ def test_init(path):
|
|
|
(os.path.join(TRACKS_DIR_PATH, 'id3v2.4-empty.mp3'), None),
|
|
|
])
|
|
|
def test_get_comment(path, expected_comment):
|
|
|
- t = symuid.Track(path)
|
|
|
- assert expected_comment == t.comment
|
|
|
+ track = symuid.Track(path)
|
|
|
+ assert expected_comment == track.comment
|
|
|
|
|
|
|
|
|
def test_set_comment(empty_id3_track):
|
|
|
- assert None == empty_id3_track.comment
|
|
|
+ assert empty_id3_track.comment is None
|
|
|
empty_id3_track.comment = 'note'
|
|
|
- assert 'note' == empty_id3_track.comment
|
|
|
+ assert empty_id3_track.comment == 'note'
|
|
|
empty_id3_track.comment += 's'
|
|
|
- assert 'notes' == empty_id3_track.comment
|
|
|
- assert 'notes' == symuid.Track(empty_id3_track.path).comment
|
|
|
+ assert empty_id3_track.comment == 'notes'
|
|
|
+ assert symuid.Track(empty_id3_track.path).comment == 'notes'
|
|
|
|
|
|
|
|
|
-@pytest.mark.parametrize(('pc'), [
|
|
|
+@pytest.mark.parametrize(('play_count'), [
|
|
|
symuid.PlayCount('pytest', 'lib', utc_dt(), 7),
|
|
|
])
|
|
|
-def test_register_play_count(empty_id3_track, pc):
|
|
|
- empty_id3_track.register_play_count(pc)
|
|
|
+def test_register_play_count(empty_id3_track, play_count):
|
|
|
+ empty_id3_track.register_play_count(play_count)
|
|
|
tags = mutagen.File(empty_id3_track.path).tags
|
|
|
assert len(tags) == 1
|
|
|
expected_desc = 'symuid:pcnt:{}:{}:{}'.format(
|
|
|
- pc.player, pc.library_id, int(pc.register_dt.timestamp()),
|
|
|
+ play_count.player, play_count.library_id, int(
|
|
|
+ play_count.register_dt.timestamp()),
|
|
|
)
|
|
|
tag = tags['TXXX:' + expected_desc]
|
|
|
assert tag.desc == expected_desc
|
|
|
- assert tag.text == [str(pc.count)]
|
|
|
+ assert tag.text == [str(play_count.count)]
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('expected_counts'), [
|
|
@@ -77,8 +78,8 @@ def test_register_play_count(empty_id3_track, pc):
|
|
|
symuid.PlayCount('b', '3', utc_dt(3), 3)],
|
|
|
])
|
|
|
def test__get_play_counts_all(empty_id3_track, expected_counts):
|
|
|
- for pc in expected_counts:
|
|
|
- empty_id3_track.register_play_count(pc)
|
|
|
+ for play_count in expected_counts:
|
|
|
+ empty_id3_track.register_play_count(play_count)
|
|
|
assert expected_counts == list(empty_id3_track._get_play_counts())
|
|
|
|
|
|
|
|
@@ -87,8 +88,8 @@ def test__get_play_counts_filtered(empty_id3_track):
|
|
|
symuid.PlayCount('a', '0', utc_dt(1), 2),
|
|
|
symuid.PlayCount('a', '1', utc_dt(0), 3),
|
|
|
symuid.PlayCount('b', '2', utc_dt(1), 4)]
|
|
|
- for pc in counts:
|
|
|
- empty_id3_track.register_play_count(pc)
|
|
|
+ for play_count in counts:
|
|
|
+ empty_id3_track.register_play_count(play_count)
|
|
|
assert set(empty_id3_track._get_play_counts(player='a')) \
|
|
|
== set(filter(lambda pc: pc.player == 'a', counts))
|
|
|
assert set(empty_id3_track._get_play_counts(player='b')) \
|
|
@@ -105,8 +106,8 @@ def test__get_latest_play_counts(empty_id3_track):
|
|
|
symuid.PlayCount('a', '1', utc_dt(0), 3),
|
|
|
symuid.PlayCount('a', '1', utc_dt(2), 4),
|
|
|
symuid.PlayCount('b', '2', utc_dt(3), 5)]
|
|
|
- for pc in counts:
|
|
|
- empty_id3_track.register_play_count(pc)
|
|
|
+ for play_count in counts:
|
|
|
+ empty_id3_track.register_play_count(play_count)
|
|
|
assert set(empty_id3_track._get_latest_play_counts()) \
|
|
|
== set([counts[1], counts[3], counts[4]])
|
|
|
assert set(empty_id3_track._get_latest_play_counts(player='a')) \
|
|
@@ -121,31 +122,31 @@ def test_get_play_count_sum(empty_id3_track):
|
|
|
symuid.PlayCount('a', '1', utc_dt(0), 3),
|
|
|
symuid.PlayCount('a', '1', utc_dt(2), 4),
|
|
|
symuid.PlayCount('b', '2', utc_dt(3), 5)]
|
|
|
- for pc in counts:
|
|
|
- empty_id3_track.register_play_count(pc)
|
|
|
+ for play_count in counts:
|
|
|
+ empty_id3_track.register_play_count(play_count)
|
|
|
assert 2 + 4 + 5 == empty_id3_track.get_play_count_sum()
|
|
|
|
|
|
|
|
|
def test_increase_play_count(empty_id3_track):
|
|
|
init_count = symuid.PlayCount('a', '0', utc_dt(0), 3)
|
|
|
empty_id3_track.register_play_count(init_count)
|
|
|
- assert 3 == empty_id3_track.get_play_count_sum()
|
|
|
+ assert empty_id3_track.get_play_count_sum() == 3
|
|
|
empty_id3_track.increase_play_count('a', '0')
|
|
|
- dt = symuid._utc_dt_now()
|
|
|
- assert 4 == empty_id3_track.get_play_count_sum()
|
|
|
+ dt_now = symuid._utc_dt_now()
|
|
|
+ assert empty_id3_track.get_play_count_sum() == 4
|
|
|
counts = set(empty_id3_track._get_play_counts())
|
|
|
assert len(counts) == 2
|
|
|
counts.remove(init_count)
|
|
|
new_count = counts.pop()
|
|
|
assert new_count.player == 'a'
|
|
|
assert new_count.library_id == '0'
|
|
|
- assert abs(new_count.register_dt - dt).total_seconds() < 5
|
|
|
+ assert abs(new_count.register_dt - dt_now).total_seconds() < 5
|
|
|
assert new_count.count == 4
|
|
|
|
|
|
|
|
|
def test_increase_play_count_init(empty_id3_track):
|
|
|
empty_id3_track.increase_play_count('a', '0')
|
|
|
- assert 1 == empty_id3_track.get_play_count_sum()
|
|
|
+ assert empty_id3_track.get_play_count_sum() == 1
|
|
|
count, = empty_id3_track._get_play_counts()
|
|
|
assert count.player == 'a'
|
|
|
assert count.library_id == '0'
|
|
@@ -163,13 +164,13 @@ def test_increase_play_count_others(empty_id3_track):
|
|
|
empty_id3_track.register_play_count(
|
|
|
symuid.PlayCount('b', '0', utc_dt(0), 3),
|
|
|
)
|
|
|
- assert 6 == empty_id3_track.get_play_count_sum()
|
|
|
+ assert empty_id3_track.get_play_count_sum() == 6
|
|
|
empty_id3_track.increase_play_count('a', '1')
|
|
|
- assert 7 == empty_id3_track.get_play_count_sum()
|
|
|
- assert 1 == len(list(empty_id3_track._get_play_counts(player='b')))
|
|
|
- assert 1 == len(list(
|
|
|
+ assert empty_id3_track.get_play_count_sum() == 7
|
|
|
+ assert len(list(empty_id3_track._get_play_counts(player='b'))) == 1
|
|
|
+ assert len(list(
|
|
|
empty_id3_track._get_play_counts(player='a', library_id='0')
|
|
|
- ))
|
|
|
- assert 2 == len(list(
|
|
|
+ )) == 1
|
|
|
+ assert len(list(
|
|
|
empty_id3_track._get_play_counts(player='a', library_id='1')
|
|
|
- ))
|
|
|
+ )) == 2
|