File: test_util_library.py

package info (click to toggle)
quodlibet 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,228 kB
  • sloc: python: 89,728; sh: 381; xml: 110; makefile: 91
file content (88 lines) | stat: -rw-r--r-- 2,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright 2014 Nick Boultbee
#
# 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.

import os

from senf import fsnative

from quodlibet import config
from quodlibet.util.library import (
    split_scan_dirs,
    set_scan_dirs,
    get_exclude_dirs,
    get_scan_dirs,
)
from quodlibet.util import is_windows
from quodlibet.util.path import get_home_dir, unexpand

from tests import TestCase


STANDARD_PATH = fsnative("/home/user/Music")
OTHER_PATH = fsnative("/opt/party")
GVFS_PATH = fsnative(
    "/run/user/12345/gvfs/smb-share:server=12.23.34.45,share=/foo/bar/baz/path"
)
GVFS_PATH_ESCAPED = fsnative(
    "/run/user/12345/gvfs/smb-share\\:server=12.23.34.45,share=/foo/bar/baz/path"
)


class Tlibrary_utils(TestCase):
    def test_basic(self):
        if is_windows():
            res = split_scan_dirs(":Z:\\foo:C:/windows:")
            self.assertEqual(res, ["Z:\\foo", "C:/windows"])
        else:
            res = split_scan_dirs(f":{STANDARD_PATH}:{OTHER_PATH}:")
            self.assertEqual(res, [STANDARD_PATH, OTHER_PATH])

    def test_colon_paths(self):
        if not is_windows():
            res = split_scan_dirs(f":{STANDARD_PATH}:{GVFS_PATH_ESCAPED}")
            self.assertEqual(res, [STANDARD_PATH, GVFS_PATH])

    def test_get_exclude_dirs(self):
        some_path = os.path.join(get_home_dir(), "foo")
        if os.name != "nt":
            some_path = unexpand(some_path)
        config.set("library", "exclude", some_path)
        assert os.path.expanduser(some_path) in get_exclude_dirs()

        assert all(isinstance(p, fsnative) for p in get_exclude_dirs())

    def test_get_scan_dirs(self):
        some_path = os.path.join(get_home_dir(), "foo")
        if os.name != "nt":
            some_path = unexpand(some_path)
        config.set("settings", "scan", some_path)
        assert os.path.expanduser(some_path) in get_scan_dirs()

        assert all(isinstance(p, fsnative) for p in get_scan_dirs())


class Tset_scan_dirs(TestCase):
    @property
    def scan_dirs(self):
        return config.get("settings", "scan")

    def test_set_scan_dirs_empty(self):
        set_scan_dirs([])
        self.assertEqual(self.scan_dirs, "")

    def test_set_scan_dirs_single(self):
        set_scan_dirs([STANDARD_PATH])
        self.assertEqual(self.scan_dirs, STANDARD_PATH)

    def test_set_scan_dirs_multiple(self):
        set_scan_dirs([OTHER_PATH, STANDARD_PATH])
        self.assertEqual(self.scan_dirs, f"{OTHER_PATH}:{STANDARD_PATH}")

    def test_set_scan_dirs_colons(self):
        set_scan_dirs([STANDARD_PATH, GVFS_PATH])
        expected = GVFS_PATH if is_windows() else GVFS_PATH_ESCAPED
        self.assertEqual(self.scan_dirs, f"{STANDARD_PATH}:{expected}")