Skip to content

Commit

Permalink
test(import): Add test for _paths_from_logfile method
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jun 27, 2022
1 parent 5128bcd commit 47cb273
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import platform
import sys
import unittest
import textwrap

from unittest.mock import patch, Mock
from test import _common
Expand Down Expand Up @@ -729,6 +730,41 @@ def test_quiet_timid_disallowed(self):
self.assertRaises(ui.UserError, commands.import_files, None, [],
None)

def test_parse_paths_from_logfile(self):
if os.path.__name__ == 'ntpath':
logfile_content = """
import started Wed Jun 15 23:08:26 2022
asis C:\\music\\Beatles, The\\The Beatles; C:\\music\\Beatles, The\\The Beatles\\CD 01; C:\\music\\Beatles, The\\The Beatles\\CD 02
duplicate-replace C:\\music\\Bill Evans\\Trio '65
skip C:\\music\\Michael Jackson\\Bad
skip C:\\music\\Soulwax\\Any Minute Now
"""
expected_paths = [
"C:\\music\\Beatles, The\\The Beatles",
"C:\\music\\Michael Jackson\\Bad",
"C:\\music\\Soulwax\\Any Minute Now",
]
else:
logfile_content = """
import started Wed Jun 15 23:08:26 2022
asis /music/Beatles, The/The Beatles; /music/Beatles, The/The Beatles/CD 01; /music/Beatles, The/The Beatles/CD 02
duplicate-replace /music/Bill Evans/Trio '65
skip /music/Michael Jackson/Bad
skip /music/Soulwax/Any Minute Now
"""
expected_paths = [
"/music/Beatles, The/The Beatles",
"/music/Michael Jackson/Bad",
"/music/Soulwax/Any Minute Now",
]

logfile = os.path.join(self.temp_dir, b"logfile.log")
with open(logfile, mode="w") as fp:
fp.write(textwrap.dedent(logfile_content).strip("\n"))
actual_paths = list(commands._paths_from_logfile(logfile))

self.assertEqual(actual_paths, expected_paths)


@_common.slow_test()
class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
Expand Down

0 comments on commit 47cb273

Please sign in to comment.