Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hSaria committed Feb 6, 2022
1 parent 07cd68b commit 980f48f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions chromaterm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def color(self, value):
color_reset = COLOR_TYPES[style]['reset'] + color_reset
color_types.append((style, COLOR_TYPES[style]['code']))

self._color = ' '.join(dict.fromkeys(color.lower().split()))
self._color = ' '.join(dict.fromkeys(color.split()))
self.color_code = color_code
self.color_reset = color_reset
self.color_types = color_types
Expand Down Expand Up @@ -201,14 +201,14 @@ def decode_sgr(source_color_code, is_reset=False):
else:
return [[source_color_code, False, None]]

colors.append([make_sgr(code), False or is_reset, color_type])
colors.append([make_sgr(code), is_reset, color_type])
# Single-code SGR
else:
color = [make_sgr(b'%d' % int(code)), False, None]

for name, color_type in COLOR_TYPES.items():
if color_type['re'].search(color[0]):
color[1] = color[0] == color_type['reset'] or is_reset
color[1] = is_reset or color[0] == color_type['reset']
color[2] = name

# Types don't overlap; only one can match
Expand Down Expand Up @@ -309,10 +309,10 @@ def add_color(self, name, value):

if not re.fullmatch(r'[a-z0-9-_]+', name):
raise ValueError('name accepts alphanumerics, dashes, and '
'underscores only.')
'underscores only')

if not re.fullmatch(r'#[0-9a-f]{6}', value):
raise ValueError('color value must be in the format of `#123abc`')
raise ValueError('palette color must be in `#123abc` format')

self.colors[name] = value

Expand Down Expand Up @@ -469,7 +469,7 @@ def set_color(self, color, group=0):
raise TypeError('color must be a chromaterm.Color')

if group > self._regex.groups:
raise ValueError(f'regex only has {self._regex.groups} group(s); '
raise ValueError(f'regex has {self._regex.groups} group(s); '
f'{group} is invalid')

self.colors[group] = color
Expand Down
8 changes: 3 additions & 5 deletions chromaterm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def eprint(*args, **kwargs):

def get_default_config_location():
'''Returns the first location in `CONFIG_LOCATIONS` that points to a file,
defaulting to the first item in the list.
'''
defaulting to the first item in the list.'''
resolve = lambda x: os.path.expanduser(os.path.expandvars(x))

for location in CONFIG_LOCATIONS:
Expand Down Expand Up @@ -409,7 +408,6 @@ def reload_chromaterm_instances():
if process.cmdline()[:2] == current_process.cmdline()[:2]:
os.kill(process.pid, signal.SIGUSR1)
count += 1
# As per the docs, expect those errors when accessing the process methods
except (psutil.AccessDenied, psutil.NoSuchProcess):
pass

Expand Down Expand Up @@ -531,8 +529,8 @@ def main(args=None, max_wait=None, write_default=True):

# Write default config if not there
if write_default and not os.access(args.config, os.F_OK):
from chromaterm.default_config import write_default_config
write_default_config(args.config)
import chromaterm.default_config
chromaterm.default_config.write_default_config(args.config)

config = Config(benchmark=args.benchmark)

Expand Down
4 changes: 2 additions & 2 deletions tests/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_palette_add_color_invalid_value_name_reserved():

def test_palette_add_color_invalid_value_value():
'''Add a color with an invalid value value.'''
with pytest.raises(ValueError, match='must be in the format of `#123abc`'):
with pytest.raises(ValueError, match='must be in `#123abc` format'):
chromaterm.Palette().add_color('red', 'h#ff0000')


Expand Down Expand Up @@ -574,7 +574,7 @@ def test_rule_set_color_invalid_value_group_index(pcre):
'''Reference the index of a group that doesn't exist.'''
rule = chromaterm.Rule(r'he(llo)\1', pcre=pcre)

with pytest.raises(ValueError, match='regex only has 1 group'):
with pytest.raises(ValueError, match='regex has 1 group'):
rule.set_color(chromaterm.Color('bold'), group=2)


Expand Down
2 changes: 1 addition & 1 deletion tests/test__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def test_parse_rule_group_type_error():

def test_parse_rule_group_out_of_bounds():
'''Parse a rule with `group` number not in the regex.'''
msg_re = r'regex only has .* group\(s\); .* is invalid'
msg_re = r'regex has .* group\(s\); .* is invalid'

rule = {'regex': 'x(y)z', 'color': {2: 'b#fffaaa'}}
assert re.search(msg_re, chromaterm.__main__.parse_rule(rule))
Expand Down

0 comments on commit 980f48f

Please sign in to comment.