|
@@ -1,5 +1,4 @@
|
|
|
import os
|
|
|
-import re
|
|
|
import shutil
|
|
|
import unittest.mock
|
|
|
|
|
@@ -7,28 +6,37 @@ import pytest
|
|
|
from symuid import PlayCount, Track
|
|
|
from symuid._datetime import unix_epoch_time_to_datetime_utc
|
|
|
from symuid._uuid import generate_uuid4_bytes
|
|
|
-from symuid.sync import _main, sync
|
|
|
-
|
|
|
-DUMMY_PATH_IGNORE_REGEX = re.compile(r'\.jpg$')
|
|
|
+from symuid.sync import _main, _walk_tracks, sync
|
|
|
|
|
|
|
|
|
def test_add_uuid(empty_ogg_opus_path):
|
|
|
assert Track(empty_ogg_opus_path).get_uuid() is None
|
|
|
- sync(os.path.dirname(empty_ogg_opus_path),
|
|
|
- path_ignore_regex=DUMMY_PATH_IGNORE_REGEX)
|
|
|
+ sync(_walk_tracks([os.path.dirname(empty_ogg_opus_path)]))
|
|
|
assert Track(empty_ogg_opus_path).get_uuid() is not None
|
|
|
|
|
|
|
|
|
def test_add_uuid_idempotent(empty_ogg_opus_path):
|
|
|
- sync(os.path.dirname(empty_ogg_opus_path),
|
|
|
- path_ignore_regex=DUMMY_PATH_IGNORE_REGEX)
|
|
|
+ sync(_walk_tracks([os.path.dirname(empty_ogg_opus_path)]))
|
|
|
uuid = Track(empty_ogg_opus_path).get_uuid()
|
|
|
- sync(os.path.dirname(empty_ogg_opus_path),
|
|
|
- path_ignore_regex=DUMMY_PATH_IGNORE_REGEX)
|
|
|
+ sync(_walk_tracks([os.path.dirname(empty_ogg_opus_path)]))
|
|
|
assert Track(empty_ogg_opus_path).get_uuid() == uuid
|
|
|
|
|
|
|
|
|
-def test_add_uuid_main(empty_ogg_opus_path):
|
|
|
+def test_add_uuid_main_file(empty_ogg_opus_path):
|
|
|
+ assert Track(empty_ogg_opus_path).get_uuid() is None
|
|
|
+ with unittest.mock.patch('sys.argv', ['', empty_ogg_opus_path]):
|
|
|
+ _main()
|
|
|
+ assert Track(empty_ogg_opus_path).get_uuid() is not None
|
|
|
+
|
|
|
+
|
|
|
+def test_add_uuid_main_multiple_files(empty_ogg_opus_path, empty_ogg_vorbis_path):
|
|
|
+ with unittest.mock.patch('sys.argv', ['', empty_ogg_opus_path, empty_ogg_vorbis_path]):
|
|
|
+ _main()
|
|
|
+ assert Track(empty_ogg_opus_path).get_uuid() is not None
|
|
|
+ assert Track(empty_ogg_vorbis_path).get_uuid() is not None
|
|
|
+
|
|
|
+
|
|
|
+def test_add_uuid_main_dir(empty_ogg_opus_path):
|
|
|
assert Track(empty_ogg_opus_path).get_uuid() is None
|
|
|
with unittest.mock.patch('sys.argv', ['', os.path.dirname(empty_ogg_opus_path)]):
|
|
|
_main()
|
|
@@ -92,7 +100,7 @@ def test_sync_play_count(tmpdir, tracks_dir_path):
|
|
|
register_dt=unix_epoch_time_to_datetime_utc(3),
|
|
|
count=4,
|
|
|
))
|
|
|
- sync(tmpdir, path_ignore_regex=DUMMY_PATH_IGNORE_REGEX)
|
|
|
+ sync((track_a1, track_a2, track_a3, track_b))
|
|
|
play_counts_a1 = set(Track(tmpdir.join('a1.mp3')).get_play_counts())
|
|
|
play_counts_a2 = set(Track(tmpdir.join('a2.ogg')).get_play_counts())
|
|
|
play_counts_a3 = set(Track(tmpdir.join('a3.opus')).get_play_counts())
|
|
@@ -129,7 +137,7 @@ def test_sync_play_count_callback(tmpdir, tracks_dir_path):
|
|
|
count=21,
|
|
|
))
|
|
|
play_count_added_cb = unittest.mock.MagicMock()
|
|
|
- sync(tmpdir, path_ignore_regex=DUMMY_PATH_IGNORE_REGEX,
|
|
|
+ sync(_walk_tracks([tmpdir]),
|
|
|
play_count_added_cb=play_count_added_cb)
|
|
|
play_count_added_cb.assert_called_once_with(
|
|
|
track_a2, ('symuid:pcnt:cmus:lib1:0', ['21']))
|