summaryrefslogtreecommitdiffstats
path: root/tests/test_color.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_color.py')
-rw-r--r--tests/test_color.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test_color.py b/tests/test_color.py
new file mode 100644
index 00000000..91a1bf25
--- /dev/null
+++ b/tests/test_color.py
@@ -0,0 +1,74 @@
1# Copyright (C) 2024 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Unittests for the color.py module."""
16
17import os
18import unittest
19
20import color
21import git_config
22
23
24def fixture(*paths):
25 """Return a path relative to test/fixtures."""
26 return os.path.join(os.path.dirname(__file__), "fixtures", *paths)
27
28
29class ColoringTests(unittest.TestCase):
30 """tests of the Coloring class."""
31
32 def setUp(self):
33 """Create a GitConfig object using the test.gitconfig fixture."""
34 config_fixture = fixture("test.gitconfig")
35 self.config = git_config.GitConfig(config_fixture)
36 color.SetDefaultColoring("true")
37 self.color = color.Coloring(self.config, "status")
38
39 def test_Color_Parse_all_params_none(self):
40 """all params are None"""
41 val = self.color._parse(None, None, None, None)
42 self.assertEqual("", val)
43
44 def test_Color_Parse_first_parameter_none(self):
45 """check fg & bg & attr"""
46 val = self.color._parse(None, "black", "red", "ul")
47 self.assertEqual("\x1b[4;30;41m", val)
48
49 def test_Color_Parse_one_entry(self):
50 """check fg"""
51 val = self.color._parse("one", None, None, None)
52 self.assertEqual("\033[33m", val)
53
54 def test_Color_Parse_two_entry(self):
55 """check fg & bg"""
56 val = self.color._parse("two", None, None, None)
57 self.assertEqual("\033[35;46m", val)
58
59 def test_Color_Parse_three_entry(self):
60 """check fg & bg & attr"""
61 val = self.color._parse("three", None, None, None)
62 self.assertEqual("\033[4;30;41m", val)
63
64 def test_Color_Parse_reset_entry(self):
65 """check reset entry"""
66 val = self.color._parse("reset", None, None, None)
67 self.assertEqual("\033[m", val)
68
69 def test_Color_Parse_empty_entry(self):
70 """check empty entry"""
71 val = self.color._parse("none", "blue", "white", "dim")
72 self.assertEqual("\033[2;34;47m", val)
73 val = self.color._parse("empty", "green", "white", "bold")
74 self.assertEqual("\033[1;32;47m", val)