diff --git a/picard/cluster.py b/picard/cluster.py index 966ab02c8..4681e2daa 100644 --- a/picard/cluster.py +++ b/picard/cluster.py @@ -26,12 +26,12 @@ from heapq import ( import ntpath from operator import itemgetter import re -import sys from PyQt5 import QtCore from picard import config from picard.const import QUERY_LIMIT +from picard.const.sys import IS_WIN from picard.metadata import Metadata from picard.similarity import similarity from picard.util import ( @@ -248,7 +248,7 @@ class Cluster(QtCore.QObject, Item): @staticmethod def cluster(files, threshold): - win_compat = config.setting["windows_compatibility"] or sys.platform == "win32" + win_compat = config.setting["windows_compatibility"] or IS_WIN artist_dict = ClusterDict() album_dict = ClusterDict() tracks = [] diff --git a/picard/file.py b/picard/file.py index a41962a35..33c50e8d7 100644 --- a/picard/file.py +++ b/picard/file.py @@ -26,7 +26,6 @@ import os import os.path import re import shutil -import sys import unicodedata from PyQt5 import QtCore @@ -37,6 +36,10 @@ from picard import ( log, ) from picard.const import QUERY_LIMIT +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) from picard.metadata import Metadata from picard.util import ( decode_filename, @@ -351,14 +354,14 @@ class File(QtCore.QObject, Item): # TODO: move following logic under util.filenaming # (and reconsider its necessity) # win32 compatibility fixes - if settings['windows_compatibility'] or sys.platform == 'win32': + if settings['windows_compatibility'] or IS_WIN: new_filename = new_filename.replace('./', '_/').replace('.\\', '_\\') # replace . at the beginning of file and directory names new_filename = new_filename.replace('/.', '/_').replace('\\.', '\\_') if new_filename and new_filename[0] == '.': new_filename = '_' + new_filename[1:] # Fix for precomposed characters on OSX - if sys.platform == "darwin": + if IS_MACOS: new_filename = unicodedata.normalize("NFD", new_filename) new_path = os.path.join(new_dirname, new_filename) diff --git a/picard/i18n.py b/picard/i18n.py index 949b255da..c2a6ff890 100644 --- a/picard/i18n.py +++ b/picard/i18n.py @@ -21,10 +21,14 @@ import builtins import gettext import locale import os.path -import sys from PyQt5.QtCore import QLocale +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) + builtins.__dict__['N_'] = lambda a: a @@ -40,7 +44,7 @@ def setup_gettext(localedir, ui_language=None, logger=None): except Exception as e: logger(e) else: - if sys.platform == 'win32': + if IS_WIN: from ctypes import windll try: current_locale = locale.windows_locale[windll.kernel32.GetUserDefaultUILanguage()] @@ -53,7 +57,7 @@ def setup_gettext(localedir, ui_language=None, logger=None): logger(e) except Exception as e: logger(e) - elif sys.platform == 'darwin': + elif IS_MACOS: try: import Foundation defaults = Foundation.NSUserDefaults.standardUserDefaults() diff --git a/picard/tagger.py b/picard/tagger.py index 3b2dd3c51..cb65f4085 100644 --- a/picard/tagger.py +++ b/picard/tagger.py @@ -58,6 +58,10 @@ from picard.cluster import ( ) from picard.collection import load_user_collections from picard.config_upgrade import upgrade_config +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) from picard.const import ( USER_DIR, USER_PLUGIN_DIR, @@ -130,7 +134,7 @@ class Tagger(QtWidgets.QApplication): # Use the new fusion style from PyQt5 for a modern and consistent look # across all OSes. - if sys.platform != "darwin": + if not IS_MACOS: self.setStyle('Fusion') # Set the WM_CLASS to 'MusicBrainz-Picard' so desktop environments @@ -171,7 +175,7 @@ class Tagger(QtWidgets.QApplication): self.save_thread_pool = QtCore.QThreadPool(self) self.save_thread_pool.setMaxThreadCount(1) - if not sys.platform == "win32": + if not IS_WIN: # Set up signal handling # It's not possible to call all available functions from signal # handlers, therefore we need to set up a QSocketNotifier to listen @@ -194,7 +198,7 @@ class Tagger(QtWidgets.QApplication): signal.signal(signal.SIGINT, self.signal) signal.signal(signal.SIGTERM, self.signal) - if sys.platform == "darwin": + if IS_MACOS: # On macOS it is not common that the global menu shows icons self.setAttribute(QtCore.Qt.AA_DontShowIconsInMenus) diff --git a/picard/ui/filebrowser.py b/picard/ui/filebrowser.py index c2d962e1b..1c4420aa3 100644 --- a/picard/ui/filebrowser.py +++ b/picard/ui/filebrowser.py @@ -19,7 +19,6 @@ # import os -import sys from PyQt5 import ( QtCore, @@ -28,6 +27,7 @@ from PyQt5 import ( from PyQt5.QtCore import QStandardPaths from picard import config +from picard.const.sys import IS_MACOS from picard.formats import supported_formats from picard.util import find_existing_path @@ -73,7 +73,7 @@ class FileBrowser(QtWidgets.QTreeView): self.model.setNameFilterDisables(False) self.model.sort(0, QtCore.Qt.AscendingOrder) self.setModel(self.model) - if sys.platform == "darwin": + if IS_MACOS: self.setRootIndex(self.model.index("/Volumes")) header = self.header() header.hideSection(1) diff --git a/picard/ui/mainwindow.py b/picard/ui/mainwindow.py index 7d10ffe1b..58de4dfe2 100644 --- a/picard/ui/mainwindow.py +++ b/picard/ui/mainwindow.py @@ -21,7 +21,6 @@ from collections import OrderedDict import datetime from functools import partial import os.path -import sys from PyQt5 import ( QtCore, @@ -36,6 +35,9 @@ from picard import ( from picard.album import Album from picard.cluster import Cluster from picard.const import PROGRAM_UPDATE_LEVELS +from picard.const.sys import ( + IS_MACOS, +) from picard.file import File from picard.formats import supported_formats from picard.plugin import ExtensionPoint @@ -122,14 +124,14 @@ class MainWindow(QtWidgets.QMainWindow, PreserveGeometry): icon.addFile(":/images/256x256/org.musicbrainz.Picard.png", QtCore.QSize(256, 256)) self.setWindowIcon(icon) - self.show_close_window = sys.platform == "darwin" + self.show_close_window = IS_MACOS self.create_actions() self.create_statusbar() self.create_toolbar() self.create_menus() - if sys.platform == "darwin": + if IS_MACOS: self.setUnifiedTitleAndToolBarOnMac(True) self.toolbar.setMovable(False) self.search_toolbar.setMovable(False) @@ -174,7 +176,7 @@ class MainWindow(QtWidgets.QMainWindow, PreserveGeometry): def keyPressEvent(self, event): # On macOS Command+Backspace triggers the so called "Forward Delete". # It should be treated the same as the Delete button. - is_forward_delete = sys.platform == 'darwin' and \ + is_forward_delete = IS_MACOS and \ event.key() == QtCore.Qt.Key_Backspace and \ event.modifiers() & QtCore.Qt.ControlModifier if event.matches(QtGui.QKeySequence.Delete) or is_forward_delete: diff --git a/picard/ui/options/plugins.py b/picard/ui/options/plugins.py index 073b3ef59..a3d04f16e 100644 --- a/picard/ui/options/plugins.py +++ b/picard/ui/options/plugins.py @@ -23,7 +23,6 @@ from functools import partial from operator import attrgetter import os.path -import sys from PyQt5 import ( QtCore, @@ -36,10 +35,12 @@ from picard import ( config, log, ) + from picard.const import ( PLUGINS_API, USER_PLUGIN_DIR, ) +from picard.const.sys import IS_WIN from picard.util import reconnect from picard.ui import HashableTreeWidgetItem @@ -633,7 +634,7 @@ class PluginsOptionsPage(OptionsPage): @staticmethod def open_plugin_dir(): - if sys.platform == 'win32': + if IS_WIN: url = 'file:///' + USER_PLUGIN_DIR else: url = 'file://' + USER_PLUGIN_DIR diff --git a/picard/ui/options/releases.py b/picard/ui/options/releases.py index 117391fc7..8cecef0d6 100644 --- a/picard/ui/options/releases.py +++ b/picard/ui/options/releases.py @@ -19,7 +19,6 @@ from locale import strxfrm from operator import itemgetter -import sys from PyQt5 import ( QtCore, @@ -27,12 +26,14 @@ from PyQt5 import ( ) from picard import config + from picard.const import ( RELEASE_COUNTRIES, RELEASE_FORMATS, RELEASE_PRIMARY_GROUPS, RELEASE_SECONDARY_GROUPS, ) +from picard.const.sys import IS_WIN from picard.i18n import gettext_attr from picard.ui.options import ( @@ -67,12 +68,12 @@ class TipSlider(QtWidgets.QSlider): def showEvent(self, event): super().showEvent(event) - if sys.platform != 'win32': + if not IS_WIN: self.valueChanged.connect(self.show_tip) def hideEvent(self, event): super().hideEvent(event) - if sys.platform != 'win32': + if not IS_WIN: self.valueChanged.disconnect(self.show_tip) def show_tip(self, value): diff --git a/picard/ui/options/renaming.py b/picard/ui/options/renaming.py index 2cd22b834..1c34940ad 100644 --- a/picard/ui/options/renaming.py +++ b/picard/ui/options/renaming.py @@ -20,7 +20,6 @@ from functools import partial import os.path -import sys from PyQt5 import QtWidgets from PyQt5.QtCore import QStandardPaths @@ -28,6 +27,7 @@ from PyQt5.QtGui import QPalette from picard import config from picard.const import PICARD_URLS +from picard.const.sys import IS_WIN from picard.file import File from picard.script import ( ScriptError, @@ -125,7 +125,7 @@ class RenamingOptionsPage(OptionsPage): self.ui.file_naming_format_default.setEnabled(state) self.ui.ascii_filenames.setEnabled(state) self.ui.file_naming_format_group.setEnabled(state) - if not sys.platform == "win32": + if not IS_WIN: self.ui.windows_compatibility.setEnabled(state) if self.ui.file_naming_format.isEnabled(): @@ -171,7 +171,7 @@ class RenamingOptionsPage(OptionsPage): self.ui.example_filename_va.setText(example2) def load(self): - if sys.platform == "win32": + if IS_WIN: self.ui.windows_compatibility.setChecked(True) self.ui.windows_compatibility.setEnabled(False) else: diff --git a/picard/ui/util.py b/picard/ui/util.py index 7e2eea4b1..b943c3e8c 100644 --- a/picard/ui/util.py +++ b/picard/ui/util.py @@ -17,8 +17,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import sys - from PyQt5 import ( QtCore, QtGui, @@ -26,6 +24,10 @@ from PyQt5 import ( ) from picard import config +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) from picard.util import ( find_existing_path, icontheme, @@ -49,7 +51,7 @@ class StandardButton(QtWidgets.QPushButton): def __init__(self, btntype): label = _(self.__types[btntype][0]) args = [label] - if sys.platform != 'win32' and sys.platform != 'darwin': + if not IS_WIN and not IS_MACOS: iconname = self.__types[btntype][1] if hasattr(QtWidgets.QStyle, iconname): icon = self.tagger.style().standardIcon(getattr(QtWidgets.QStyle, iconname)) @@ -87,7 +89,7 @@ class MultiDirsSelectDialog(QtWidgets.QFileDialog): super().__init__(*args) self.setFileMode(self.Directory) self.setOption(self.ShowDirsOnly) - if sys.platform in ["darwin", "win32"]: + if IS_WIN or IS_MACOS: # The native dialog doesn't allow selecting >1 directory self.setOption(self.DontUseNativeDialog) for view in self.findChildren((QtWidgets.QListView, QtWidgets.QTreeView)): diff --git a/picard/util/__init__.py b/picard/util/__init__.py index 2f30a7375..af14af339 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -31,8 +31,13 @@ from PyQt5 import QtCore # Required for compatibility with lastfmplus which imports this from here rather than loading it direct. from picard.const import MUSICBRAINZ_SERVERS +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) -if sys.platform == 'win32': + +if IS_WIN: from ctypes import windll @@ -142,7 +147,7 @@ def replace_win32_incompat(string, repl="_"): """Replace win32 filename incompatible characters from ``string`` by ``repl``.""" # Don't replace : with _ for windows drive - if sys.platform == "win32" and os.path.isabs(string): + if IS_WIN and os.path.isabs(string): drive, rest = ntpath.splitdrive(string) return drive + _re_win32_incompat.sub(repl, rest) else: @@ -200,7 +205,7 @@ def find_existing_path(path): def find_executable(*executables): - if sys.platform == 'win32': + if IS_WIN: executables = [e + '.exe' for e in executables] paths = [os.path.dirname(sys.executable)] if sys.executable else [] paths += os.environ.get('PATH', '').split(os.pathsep) @@ -317,7 +322,7 @@ def tracknum_from_filename(base_filename): # Provide os.path.samefile equivalent which is missing in Python under Windows -if sys.platform == 'win32': +if IS_WIN: def os_path_samefile(p1, p2): ap1 = os.path.abspath(p1) ap2 = os.path.abspath(p2) @@ -332,12 +337,12 @@ def is_hidden(filepath): on non-Windows systems or if it has the "hidden" flag set on Windows.""" name = os.path.basename(os.path.abspath(filepath)) - return (name.startswith('.') and sys.platform != 'win32') \ + return (not IS_WIN and name.startswith('.')) \ or _has_hidden_attribute(filepath) def _has_hidden_attribute(filepath): - if sys.platform != 'win32': + if not IS_WIN: return False # FIXME: On OSX detecting hidden files involves more # than just checking for dot files, see diff --git a/picard/util/cdrom.py b/picard/util/cdrom.py index c1b1f934c..fde00b2ef 100644 --- a/picard/util/cdrom.py +++ b/picard/util/cdrom.py @@ -18,17 +18,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import sys - from PyQt5.QtCore import ( QFile, QIODevice, ) from picard import config +from picard.const.sys import ( + IS_LINUX, + IS_WIN, +) from picard.util import uniqify -if sys.platform == 'win32': +if IS_WIN: from ctypes import windll @@ -50,9 +52,9 @@ if discid is not None: LINUX_CDROM_INFO = '/proc/sys/dev/cdrom/info' # if get_cdrom_drives() lists ALL drives available on the machine -if sys.platform == 'win32': +if IS_WIN: AUTO_DETECT_DRIVES = True -elif sys.platform == 'linux' and QFile.exists(LINUX_CDROM_INFO): +elif IS_LINUX and QFile.exists(LINUX_CDROM_INFO): AUTO_DETECT_DRIVES = True else: # There might be more drives we couldn't detect @@ -66,7 +68,7 @@ def get_cdrom_drives(): # add default drive from libdiscid to the list drives = list(DEFAULT_DRIVES) - if sys.platform == 'win32': + if IS_WIN: GetLogicalDrives = windll.kernel32.GetLogicalDrives GetDriveType = windll.kernel32.GetDriveTypeW DRIVE_CDROM = 5 @@ -77,7 +79,7 @@ def get_cdrom_drives(): if GetDriveType(drive) == DRIVE_CDROM: drives.append(drive) - elif sys.platform == 'linux' and QFile.exists(LINUX_CDROM_INFO): + elif IS_LINUX and QFile.exists(LINUX_CDROM_INFO): # Read info from /proc/sys/dev/cdrom/info cdinfo = QFile(LINUX_CDROM_INFO) if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text): diff --git a/picard/util/filenaming.py b/picard/util/filenaming.py index 01c54033b..4a32d8dd9 100644 --- a/picard/util/filenaming.py +++ b/picard/util/filenaming.py @@ -25,6 +25,10 @@ import unicodedata from PyQt5.QtCore import QStandardPaths +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) from picard.util import ( _io_encoding, decode_filename, @@ -324,7 +328,7 @@ def make_short_filename(basedir, relpath, win_compat=False, relative_to=""): # always strip the relpath parts relpath = os.path.join(*[part.strip() for part in relpath.split(os.path.sep)]) # if we're on windows, delegate the work to a windows-specific function - if sys.platform == "win32": + if IS_WIN: reserved = len(basedir) if not basedir.endswith(os.path.sep): reserved += 1 @@ -345,7 +349,7 @@ def make_short_filename(basedir, relpath, win_compat=False, relative_to=""): relpath = _make_win_short_filename(relpath, reserved) # on *nix we can consider there is no path limit, but there is # a filename length limit. - if sys.platform == "darwin": + if IS_MACOS: # on OS X (i.e. HFS+), this is expressed in UTF-16 code points, # in NFD normalization form relpath = shorten_path(relpath, 255, mode=SHORTEN_UTF16_NFD) diff --git a/picard/util/icontheme.py b/picard/util/icontheme.py index 855b281ae..ffcb91105 100644 --- a/picard/util/icontheme.py +++ b/picard/util/icontheme.py @@ -18,11 +18,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import os.path -import sys from PyQt5 import QtGui -if sys.platform == 'win32': +from picard.const.sys import IS_WIN + + +if IS_WIN: _search_paths = [] else: _search_paths = [ diff --git a/picard/util/scripttofilename.py b/picard/util/scripttofilename.py index 94a240158..8b588036a 100644 --- a/picard/util/scripttofilename.py +++ b/picard/util/scripttofilename.py @@ -19,9 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import sys - from picard import config +from picard.const.sys import IS_WIN from picard.script import ScriptParser from picard.util import ( replace_win32_incompat, @@ -42,7 +41,7 @@ def script_to_filename(naming_format, metadata, file=None, settings=None): if settings["ascii_filenames"]: filename = replace_non_ascii(filename, pathsave=True) # replace incompatible characters - if settings["windows_compatibility"] or sys.platform == "win32": + if settings["windows_compatibility"] or IS_WIN: filename = replace_win32_incompat(filename) # remove null characters filename = filename.replace("\x00", "") diff --git a/setup.py b/setup.py index 2d67b071a..6da68fa96 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,6 @@ import glob from io import StringIO import os from os import path -import platform import re import sys import tempfile @@ -27,6 +26,11 @@ from picard import ( PICARD_VERSION, __version__, ) +from picard.const.sys import ( + IS_LINUX, + IS_WIN, +) + if sys.version_info < (3, 5): sys.exit("ERROR: You need Python 3.5 or higher to use Picard.") @@ -213,7 +217,7 @@ class picard_build(build): def run(self): log.info('generating scripts/%s from scripts/picard.in', PACKAGE_NAME) generate_file('scripts/picard.in', 'scripts/' + PACKAGE_NAME, {'localedir': self.localedir, 'autoupdate': not self.disable_autoupdate}) - if platform.system() == 'Windows': + if IS_WIN: # Temporarily setting it to this value to generate a nice name for Windows app args['name'] = 'MusicBrainz Picard' file_version = PICARD_VERSION[0:3] + PICARD_VERSION[4:] @@ -225,7 +229,7 @@ class picard_build(build): } generate_file('win-version-info.txt.in', 'win-version-info.txt', {**args, **version_args}) args['name'] = 'picard' - elif platform.system() == 'Linux': + elif IS_LINUX: self.run_command('build_appdata') build.run(self) @@ -734,7 +738,7 @@ args['data_files'] = [ ('share/applications', ('org.musicbrainz.Picard.desktop',)), ] -if platform.system() == 'Linux': +if IS_LINUX: args['data_files'].append(('share/metainfo', ['org.musicbrainz.Picard.appdata.xml'])) setup(**args) diff --git a/tagger.py b/tagger.py index 8b417507a..1827f3363 100755 --- a/tagger.py +++ b/tagger.py @@ -4,11 +4,14 @@ import os.path import sys +from picard.const.sys import ( + IS_WIN, +) # On Windows try to attach to the console as early as possible in order # to get stdout / stderr logged to console. This needs to happen before # logging gets imported. # See https://stackoverflow.com/questions/54536/win32-gui-app-that-writes-usage-text-to-stdout-when-invoked-as-app-exe-help -if sys.platform == "win32": +if IS_WIN: from ctypes import windll if windll.kernel32.AttachConsole(-1): sys.stdout = open('CON', 'w') diff --git a/test/test_scripttofilename.py b/test/test_scripttofilename.py index 5795390a7..ab2e4ba6a 100644 --- a/test/test_scripttofilename.py +++ b/test/test_scripttofilename.py @@ -1,8 +1,7 @@ -import sys - from test.picardtestcase import PicardTestCase from picard import config +from picard.const.sys import IS_WIN from picard.file import File from picard.metadata import Metadata from picard.script import register_script_function @@ -68,7 +67,7 @@ class ScriptToFilenameTest(PicardTestCase): expect_orig = '*:?' expect_compat = '___' filename = script_to_filename('%artist%?', metadata, settings=settings) - self.assertEqual(expect_compat if sys.platform == 'win32' else expect_orig, filename) + self.assertEqual(expect_compat if IS_WIN else expect_orig, filename) settings['windows_compatibility'] = True filename = script_to_filename('%artist%?', metadata, settings=settings) self.assertEqual(expect_compat, filename) diff --git a/test/test_util_filenaming.py b/test/test_util_filenaming.py index c7f6a9b63..5dcb7fd68 100644 --- a/test/test_util_filenaming.py +++ b/test/test_util_filenaming.py @@ -6,28 +6,30 @@ import sys from test.picardtestcase import PicardTestCase import unittest +from picard.const.sys import ( + IS_MACOS, + IS_WIN, +) from picard.util.filenaming import make_short_filename - class ShortFilenameTest(PicardTestCase): def __init__(self, *args, **kwargs): self.maxDiff = None - is_win32 = sys.platform == "win32" - self.root = os.path.join(is_win32 and "X:\\" or "/", "x" * 10) - if is_win32: + self.root = os.path.join(IS_WIN and "X:\\" or "/", "x" * 10) + if IS_WIN: self.max_len = 255 else: self.max_len = os.statvfs("/").f_namemax super().__init__(*args, **kwargs) - @unittest.skipUnless(sys.platform in ("win32", "darwin"), "windows / os x test") + @unittest.skipUnless(IS_WIN or IS_MACOS, "windows / os x test") def test_bmp_unicode_on_unicode_fs(self): char = u"\N{LATIN SMALL LETTER SHARP S}" fn = make_short_filename(self.root, os.path.join(*[char * 120] * 2)) self.assertEqual(fn, os.path.join(*[char * 120] * 2)) - @unittest.skipUnless(sys.platform not in ("win32", "darwin"), "non-windows, non-osx test") + @unittest.skipUnless(not IS_WIN and not IS_MACOS, "non-windows, non-osx test") def test_bmp_unicode_on_nix(self): char = u"\N{LATIN SMALL LETTER SHARP S}" max_len = self.max_len @@ -35,28 +37,28 @@ class ShortFilenameTest(PicardTestCase): fn = make_short_filename(self.root, os.path.join(*[char * 200] * 2)) self.assertEqual(fn, os.path.join(*[char * (max_len // divisor)] * 2)) - @unittest.skipUnless(sys.platform == "darwin", "os x test") + @unittest.skipUnless(IS_MACOS, "os x test") def test_precomposed_unicode_on_osx(self): char = u"\N{LATIN SMALL LETTER A WITH BREVE}" max_len = self.max_len fn = make_short_filename(self.root, os.path.join(*[char * 200] * 2)) self.assertEqual(fn, os.path.join(*[char * (max_len // 2)] * 2)) - @unittest.skipUnless(sys.platform == "win32", "windows test") + @unittest.skipUnless(IS_WIN, "windows test") def test_nonbmp_unicode_on_windows(self): char = u"\N{MUSICAL SYMBOL G CLEF}" remaining = 259 - (3 + 10 + 1 + 200 + 1) fn = make_short_filename(self.root, os.path.join(*[char * 100] * 2)) self.assertEqual(fn, os.path.join(char * 100, char * (remaining // 2))) - @unittest.skipUnless(sys.platform == "darwin", "os x test") + @unittest.skipUnless(IS_MACOS, "os x test") def test_nonbmp_unicode_on_osx(self): char = u"\N{MUSICAL SYMBOL G CLEF}" max_len = self.max_len fn = make_short_filename(self.root, os.path.join(*[char * 200] * 2)) self.assertEqual(fn, os.path.join(*[char * (max_len // 2)] * 2)) - @unittest.skipUnless(sys.platform not in ("win32", "darwin"), "non-windows, non-osx test") + @unittest.skipUnless(not IS_WIN and not IS_MACOS, "non-windows, non-osx test") def test_nonbmp_unicode_on_nix(self): char = u"\N{MUSICAL SYMBOL G CLEF}" max_len = self.max_len @@ -64,7 +66,7 @@ class ShortFilenameTest(PicardTestCase): fn = make_short_filename(self.root, os.path.join(*[char * 100] * 2)) self.assertEqual(fn, os.path.join(*[char * (max_len // divisor)] * 2)) - @unittest.skipUnless(sys.platform not in ("win32", "darwin"), "non-windows, non-osx test") + @unittest.skipUnless(not IS_WIN and not IS_MACOS, "non-windows, non-osx test") def test_nonbmp_unicode_on_nix_with_windows_compat(self): char = u"\N{MUSICAL SYMBOL G CLEF}" max_len = self.max_len @@ -77,7 +79,7 @@ class ShortFilenameTest(PicardTestCase): fn = make_short_filename(self.root, os.path.join("a" * 200, "b" * 200, "c" * 200 + ".ext"), win_compat=True) self.assertEqual(fn, os.path.join("a" * 116, "b" * 116, "c" * 7 + ".ext")) - @unittest.skipUnless(sys.platform != "win32", "non-windows test") + @unittest.skipUnless(not IS_WIN, "non-windows test") def test_windows_shortening_with_ancestor_on_nix(self): root = os.path.join(self.root, "w" * 10, "x" * 10, "y" * 9, "z" * 9) fn = make_short_filename( diff --git a/test/test_utils.py b/test/test_utils.py index 87bd3be66..c69eeda02 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -2,11 +2,11 @@ import builtins import os.path -import sys from test.picardtestcase import PicardTestCase import unittest from picard import util +from picard.const.sys import IS_WIN from picard.util import imageinfo # ensure _() is defined @@ -16,14 +16,14 @@ if '_' not in builtins.__dict__: class ReplaceWin32IncompatTest(PicardTestCase): - @unittest.skipUnless(sys.platform == "win32", "windows test") + @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(sys.platform != "win32", "non-windows test") + @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") @@ -89,7 +89,7 @@ class FormatTimeTest(PicardTestCase): class HiddenFileTest(PicardTestCase): - @unittest.skipUnless(sys.platform != "win32", "non-windows test") + @unittest.skipUnless(not IS_WIN, "non-windows test") def test(self): self.assertTrue(util.is_hidden('/a/b/.c.mp3')) self.assertTrue(util.is_hidden('/a/.b/.c.mp3'))