File: test_config.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 (79 lines) | stat: -rw-r--r-- 2,465 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
# 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 quodlibet import config
from quodlibet.config import RatingsPrefs
from tests import TestCase, mkstemp


class Tconfig(TestCase):
    def setUp(self):
        config.init()

    def test_init_garbage_file(self):
        config.quit()

        garbage = b"\xf1=\xab\xac"

        fd, filename = mkstemp()
        os.close(fd)
        with open(filename, "wb") as f:
            f.write(garbage)

        config.init(filename)
        assert config.options("player")

        invalid_filename = filename + ".not-valid"
        assert os.path.exists(invalid_filename)
        with open(invalid_filename, "rb") as f:
            assert f.read() == garbage

        os.remove(filename)
        os.remove(invalid_filename)

    def tearDown(self):
        config.quit()


class TRatingsPrefs(TestCase):
    initial_number = int(config.INITIAL["settings"]["ratings"])

    def setUp(self):
        config.init()
        self.prefs = RatingsPrefs()

    def test_getters(self):
        # A little pointless, and brittle, but still.
        assert self.prefs.number == self.initial_number
        assert self.prefs.precision == 1.0 / self.initial_number
        symbol_full = config.INITIAL["settings"]["rating_symbol_full"]
        assert self.prefs.full_symbol == symbol_full
        symbol_blank = config.INITIAL["settings"]["rating_symbol_blank"]
        assert self.prefs.blank_symbol == symbol_blank

    def test_caching(self):
        assert self.prefs.number == self.initial_number
        self.prefs.number = 10
        self.prefs.default = 0.1
        # Read it back, and it's fine
        assert self.prefs.number == 10
        assert self.prefs.default == 0.1
        # ... but modify behind the scenes (unsupported)...
        config.reset("settings", "ratings")
        config.reset("settings", "default_rating")
        # ...and caching will return the old one
        assert self.prefs.number == 10
        assert self.prefs.default == 0.1

    def test_all(self):
        self.prefs.number = 5
        # Remember zero is a possible rating too
        assert len(self.prefs.all) == 6
        assert self.prefs.all, [0, 0.2, 0.4, 0.6, 0.8 == 1.0]

    def tearDown(self):
        config.quit()