File: test_util_logging.py

package info (click to toggle)
quodlibet 4.6.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,016 kB
  • sloc: python: 85,817; sh: 385; xml: 110; makefile: 91
file content (61 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download | duplicates (3)
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
# Copyright 2014 Christoph Reiter
#
# 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.

from tests import TestCase

from quodlibet.util.logging import Logs


class TLogging(TestCase):

    def test_logging(self):
        l = Logs()
        self.assertEqual(l.get_content(), [])
        l.log("foo")
        l.log("bar")
        self.assertEqual(l.get_content(), ["foo", "bar"])
        l.log("quux")
        self.assertEqual(l.get_content(), ["foo", "bar", "quux"])

    def test_binary(self):
        l = Logs()
        l.log(b"\xff")
        self.assertEqual(l.get_content(), [u"\ufffd"])

    def test_max_logs(self):
        l = Logs(2)
        l.log("foo")
        l.log("bar")
        self.assertEqual(l.get_content(), ["foo", "bar"])
        l.log("quux")
        self.assertEqual(l.get_content(), ["bar", "quux"])

    def test_limit(self):
        l = Logs()
        l.log("foo")
        l.log("bar")
        self.assertEqual(l.get_content(limit=1), ["bar"])
        self.assertEqual(l.get_content(limit=2), ["foo", "bar"])

    def test_clear(self):
        l = Logs(2)
        l.log("foo")
        l.log("bar")
        l.clear()
        self.assertEqual(l.get_content(), [])
        l.clear()
        self.assertEqual(l.get_content(), [])

    def test_cat(self):
        l = Logs()
        l.log("foo")
        l.log("bar", "cat5")
        l.log("quux", "cat5")
        self.assertEqual(l.get_content(), ["foo", "bar", "quux"])
        self.assertEqual(l.get_content("cat5"), ["bar", "quux"])
        self.assertEqual(l.get_content("cat5", limit=2), ["bar", "quux"])
        self.assertEqual(l.get_content("cat5", limit=1), ["quux"])