mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-02-08 14:30:25 +01:00
tests: Fix linting and tests.
This commit is contained in:
parent
d865a5fd3c
commit
6ca3fa2763
@ -31,13 +31,14 @@ def export_all_templates(colors, template_dir=None, output_dir=CACHE_DIR):
|
|||||||
"""Export all template files."""
|
"""Export all template files."""
|
||||||
|
|
||||||
# Add the template dir to module path.
|
# Add the template dir to module path.
|
||||||
template_dir = template_dir or os.path.join(os.path.dirname(__file__), "templates")
|
template_dir = template_dir or \
|
||||||
|
os.path.join(os.path.dirname(__file__), "templates")
|
||||||
|
|
||||||
# Merge all colors (specials and normals) into one dict so we can access
|
# Merge all colors (specials and normals) into one dict so we can access
|
||||||
# their values simpler.
|
# their values simpler.
|
||||||
all_colors = dict()
|
all_colors = {}
|
||||||
for v in colors.values():
|
# pylint: disable=W0106
|
||||||
all_colors.update(v)
|
[all_colors.update(value) for value in colors.values()]
|
||||||
|
|
||||||
# Turn all those colors into util.Color instances for accessing the
|
# Turn all those colors into util.Color instances for accessing the
|
||||||
# .hex and .rgb formats
|
# .hex and .rgb formats
|
||||||
|
@ -7,6 +7,21 @@ import pathlib
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
class Color(object):
|
||||||
|
"""Color formats."""
|
||||||
|
def __init__(self, hex_color):
|
||||||
|
self.hex_color = hex_color
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.hex_color
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rgb(self):
|
||||||
|
"""Convert a hex color to rgb."""
|
||||||
|
return hex_to_rgb(self.hex_color)
|
||||||
|
|
||||||
|
|
||||||
def read_file(input_file):
|
def read_file(input_file):
|
||||||
"""Read colors from a file."""
|
"""Read colors from a file."""
|
||||||
with open(input_file) as file:
|
with open(input_file) as file:
|
||||||
@ -51,14 +66,3 @@ def disown(*cmd):
|
|||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
preexec_fn=os.setpgrp)
|
preexec_fn=os.setpgrp)
|
||||||
|
|
||||||
class Color(object):
|
|
||||||
def __init__(self, hex):
|
|
||||||
self.hex = hex
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.hex
|
|
||||||
|
|
||||||
@property
|
|
||||||
def rgb(self):
|
|
||||||
return hex_to_rgb(self.hex)
|
|
||||||
|
@ -20,13 +20,16 @@ class TestExportColors(unittest.TestCase):
|
|||||||
COLORS["colors"].update(COLORS["special"])
|
COLORS["colors"].update(COLORS["special"])
|
||||||
|
|
||||||
output_dir = pathlib.Path("/tmp")
|
output_dir = pathlib.Path("/tmp")
|
||||||
export_colors.export_all_templates(COLORS, pathlib.Path("tests/test_files/templates"), output_dir)
|
template_dir = pathlib.Path("tests/test_files/templates")
|
||||||
|
export_colors.export_all_templates(COLORS, template_dir, output_dir)
|
||||||
|
|
||||||
result = pathlib.Path("/tmp/test_template").is_file()
|
result = pathlib.Path("/tmp/test_template").is_file()
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
content = pathlib.Path("/tmp/test_template").read_text()
|
content = pathlib.Path("/tmp/test_template").read_text()
|
||||||
self.assertEqual(content, '\n'.join(["test1 #3A5130", "test2 #3A5130", "test3 58,81,48", ""]))
|
self.assertEqual(content, '\n'.join(["test1 #3A5130",
|
||||||
|
"test2 #3A5130",
|
||||||
|
"test3 58,81,48", ""]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user