# -*- coding: utf-8 -*- # # Picard, the next-generation MusicBrainz tagger # # Copyright (C) 2006-2007 Lukáš Lalinský # Copyright (C) 2010 fatih # Copyright (C) 2010-2011, 2014, 2018-2021 Philipp Wolfer # Copyright (C) 2012, 2014, 2018 Wieland Hoffmann # Copyright (C) 2013 Ionuț Ciocîrlan # Copyright (C) 2013-2014, 2018-2021 Laurent Monin # Copyright (C) 2014, 2017 Sophist-UK # Copyright (C) 2016 Frederik “Freso” S. Olesen # Copyright (C) 2017 Sambhav Kothari # Copyright (C) 2017 Shen-Ta Hsieh # Copyright (C) 2021 Bob Swift # Copyright (C) 2021 Vladislav Karbovskii # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import builtins from collections import namedtuple from collections.abc import Iterator import re import subprocess # nosec: B404 from tempfile import NamedTemporaryFile import unittest from unittest.mock import Mock from test.picardtestcase import PicardTestCase from picard import util from picard.const import MUSICBRAINZ_SERVERS from picard.const.sys import ( IS_MACOS, IS_WIN, ) from picard.util import ( album_artist_from_path, build_qurl, extract_year_from_date, find_best_match, is_absolute_path, iter_files_from_objects, iter_unique, limited_join, make_filename_from_title, pattern_as_regex, sort_by_similarity, tracknum_and_title_from_filename, tracknum_from_filename, uniqify, wildcards_to_regex_pattern, ) # ensure _() is defined if '_' not in builtins.__dict__: builtins.__dict__['_'] = lambda a: a class ReplaceWin32IncompatTest(PicardTestCase): @unittest.skipUnless(IS_WIN, "windows test") def test_correct_absolute_win32(self): self.assertEqual(util.replace_win32_incompat("c:\\test\\te\"st/2"), "c:\\test\\te_st/2") self.assertEqual(util.replace_win32_incompat("c:\\test\\d:/2"), "c:\\test\\d_/2") @unittest.skipUnless(not IS_WIN, "non-windows test") def test_correct_absolute_non_win32(self): self.assertEqual(util.replace_win32_incompat("/test/te\"st/2"), "/test/te_st/2") self.assertEqual(util.replace_win32_incompat("/test/d:/2"), "/test/d_/2") def test_correct_relative(self): self.assertEqual(util.replace_win32_incompat("A\"*:<>?|b"), "A_______b") self.assertEqual(util.replace_win32_incompat("d:tes