File: test_visual_color.py

package info (click to toggle)
python-plumbum 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,300 kB
  • sloc: python: 10,016; makefile: 130; sh: 8
file content (85 lines) | stat: -rw-r--r-- 2,322 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
#!/usr/bin/env python3
from __future__ import annotations

import os
import unittest

from plumbum import colors

# This is really intended to be run manually, so the output can be observed, rather than with py.test


class TestVisualColor(unittest.TestCase):
    def setUp(self):
        if os.name == "nt":
            try:
                import colorama

                colorama.init()
                self.colorama = colorama
                colors.use_color = 1
                print()
                print("Colorama initialized")
            except ImportError:
                self.colorama = None
        else:
            self.colorama = None

    def tearDown(self):
        if self.colorama:
            self.colorama.deinit()

    def testVisualColors(self):
        print()
        for c in colors.fg[:16]:
            with c:
                print("Cycle color test", end=" ")
            print(" - > back to normal")
        with colors:
            print(
                colors.fg.green
                + "Green "
                + colors.bold
                + "Bold "
                + ~colors.bold
                + "Normal"
            )
        print("Reset all")

    def testToggleColors(self):
        print()
        print(colors.fg.red["This is in red"], "but this is not")
        print(
            colors.fg.green
            + "Hi, "
            + colors.bg[23]
            + "This is on a BG"
            + ~colors.bg
            + " and this is not but is still green."
        )
        colors.yellow.print("This is printed from color.")
        colors.reset()

        for attr in colors._style.attribute_names:
            print("This is", attr | getattr(colors, attr), "and this is not.")
            colors.reset()

    def testLimits(self):
        print()
        cval = colors.use_color
        colors.use_color = 4
        c = colors.rgb(123, 40, 200)
        print("True", repr(str(c)), repr(c))
        colors.use_color = 3
        print("Full", repr(str(c)), repr(c))
        colors.use_color = 2
        print("Simple", repr(str(c)), repr(c))
        colors.use_color = 1
        print("Basic", repr(str(c)), repr(c))
        colors.use_color = 0
        print("None", repr(str(c)), repr(c))
        colors.use_color = cval


if __name__ == "__main__":
    unittest.main()