diff options
author | bright <mmh1989@foxmail.com> | 2024-05-18 07:38:46 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-09-12 16:15:06 +0000 |
commit | d8b4101eae8d7b650c9fd27d4f6495a032187279 (patch) | |
tree | b484eb66fa2800b0cdbca16c4e7c3b1314725bb9 /tests/test_color.py | |
parent | 1c53b0fa444d66076a0c364a41864474b9b0d6c5 (diff) | |
download | git-repo-d8b4101eae8d7b650c9fd27d4f6495a032187279.tar.gz |
color: fix have_fg not re assign to true
In method _parse the value of this variable 'have_fg ' is always
False, Maybe reassign it to True is lost.
I guess the author’s original intention was:
if set some value in gitconfig file(for ex: text = black red ul),
the first is bg color, the second is fg color, and the last one is attr.
Change-Id: I372698fe625db4c1fdaa94ea7f193a80a850ecb9
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/425997
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Bright Ma <mmh1989@foxmail.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Diffstat (limited to 'tests/test_color.py')
-rw-r--r-- | tests/test_color.py | 74 |
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 | |||
17 | import os | ||
18 | import unittest | ||
19 | |||
20 | import color | ||
21 | import git_config | ||
22 | |||
23 | |||
24 | def fixture(*paths): | ||
25 | """Return a path relative to test/fixtures.""" | ||
26 | return os.path.join(os.path.dirname(__file__), "fixtures", *paths) | ||
27 | |||
28 | |||
29 | class 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) | ||