From c8dd8f4d03fc79b5594e8d873e0aba77e360796a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 22 Jul 2017 10:01:14 +1000 Subject: general: Fixes. --- pywal/export.py | 31 ------------------------------- pywal/template.py | 31 +++++++++++++++++++++++++++++++ pywal/wal.py | 4 ++-- tests/test_export.py | 36 ------------------------------------ tests/test_files/test2.jpg | 1 + tests/test_image.py | 2 +- tests/test_magic.py | 2 +- tests/test_template.py | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 72 insertions(+), 71 deletions(-) delete mode 100644 pywal/export.py create mode 100644 pywal/template.py delete mode 100755 tests/test_export.py create mode 120000 tests/test_files/test2.jpg create mode 100755 tests/test_template.py diff --git a/pywal/export.py b/pywal/export.py deleted file mode 100644 index 1dc72bf..0000000 --- a/pywal/export.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Export colors in various formats. -""" -import os - -from pywal import util - - -def template(colors, input_file, output_dir): - """Read template file, substitute markers and - save the file elsewhere.""" - template_data = util.read_file_raw(input_file) - template_data = "".join(template_data).format(**colors) - template_name = os.path.basename(input_file) - util.save_file(template_data, output_dir / template_name) - print(f"export: Exported {template_name}.") - - -def export_all_templates(colors, output_dir, template_dir=None): - """Export all template files.""" - template_dir = template_dir or \ - os.path.join(os.path.dirname(__file__), "templates") - - all_colors = {"wallpaper": colors["wallpaper"], - **colors["special"], - **colors["colors"]} - all_colors = {k: util.Color(v) for k, v in all_colors.items()} - - # pylint: disable=W0106 - [template(all_colors, file.path, output_dir) - for file in os.scandir(template_dir)] diff --git a/pywal/template.py b/pywal/template.py new file mode 100644 index 0000000..1dc72bf --- /dev/null +++ b/pywal/template.py @@ -0,0 +1,31 @@ +""" +Export colors in various formats. +""" +import os + +from pywal import util + + +def template(colors, input_file, output_dir): + """Read template file, substitute markers and + save the file elsewhere.""" + template_data = util.read_file_raw(input_file) + template_data = "".join(template_data).format(**colors) + template_name = os.path.basename(input_file) + util.save_file(template_data, output_dir / template_name) + print(f"export: Exported {template_name}.") + + +def export_all_templates(colors, output_dir, template_dir=None): + """Export all template files.""" + template_dir = template_dir or \ + os.path.join(os.path.dirname(__file__), "templates") + + all_colors = {"wallpaper": colors["wallpaper"], + **colors["special"], + **colors["colors"]} + all_colors = {k: util.Color(v) for k, v in all_colors.items()} + + # pylint: disable=W0106 + [template(all_colors, file.path, output_dir) + for file in os.scandir(template_dir)] diff --git a/pywal/wal.py b/pywal/wal.py index 6d10278..fa0eb3e 100644 --- a/pywal/wal.py +++ b/pywal/wal.py @@ -4,11 +4,11 @@ Created by Dylan Araps. """ import pathlib -from pywal import export from pywal import image from pywal import magic from pywal import reload from pywal import sequences +from pywal import template from pywal import wallpaper @@ -42,7 +42,7 @@ def reload_env(cache_dir=CACHE_DIR): def export_all_templates(colors, output_dir=CACHE_DIR, template_dir=None): """Export all templates.""" - export.export_all_templates(colors, output_dir, template_dir) + template.export_all_templates(colors, output_dir, template_dir) def set_wallpaper(img): diff --git a/tests/test_export.py b/tests/test_export.py deleted file mode 100755 index 167d3ed..0000000 --- a/tests/test_export.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Test export functions.""" -import unittest -import pathlib - -from pywal import export -from pywal import util - - -# Import colors. -COLORS = util.read_file_json("tests/test_files/test_file.json") - - -class TestExportColors(unittest.TestCase): - """Test the export functions.""" - - def test_template(self): - """> Test substitutions in template file.""" - # Merge both dicts so we can access their - # values simpler. - COLORS["colors"].update(COLORS["special"]) - - output_dir = pathlib.Path("/tmp") - template_dir = pathlib.Path("tests/test_files/templates") - export.export_all_templates(COLORS, template_dir, output_dir) - - result = pathlib.Path("/tmp/test_template").is_file() - self.assertTrue(result) - - content = pathlib.Path("/tmp/test_template").read_text() - self.assertEqual(content, '\n'.join(["test1 #1F211E", - "test2 #1F211E", - "test3 31,33,30", ""])) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_files/test2.jpg b/tests/test_files/test2.jpg new file mode 120000 index 0000000..0e8c5b6 --- /dev/null +++ b/tests/test_files/test2.jpg @@ -0,0 +1 @@ +test.jpg \ No newline at end of file diff --git a/tests/test_image.py b/tests/test_image.py index 7dacecb..bcf3b4d 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -14,7 +14,7 @@ class TestImage(unittest.TestCase): def test_get_img_dir(self): """> Validate image directory.""" result = wal.get_image("tests/test_files") - self.assertEqual(result, "tests/test_files/test.jpg") + self.assertEqual(result, "tests/test_files/test2.jpg") if __name__ == "__main__": diff --git a/tests/test_magic.py b/tests/test_magic.py index 852f8b3..a3434df 100755 --- a/tests/test_magic.py +++ b/tests/test_magic.py @@ -10,7 +10,7 @@ class TestGenColors(unittest.TestCase): def test_gen_colors(self): """> Generate a colorscheme.""" result = wal.create_palette("tests/test_files/test.jpg") - self.assertEqual(result[0], "#0F191A") + self.assertEqual(result["colors"]["color0"], "#0F191A") if __name__ == "__main__": diff --git a/tests/test_template.py b/tests/test_template.py new file mode 100755 index 0000000..9040348 --- /dev/null +++ b/tests/test_template.py @@ -0,0 +1,36 @@ +"""Test export functions.""" +import unittest +import pathlib + +from pywal import template +from pywal import util + + +# Import colors. +COLORS = util.read_file_json("tests/test_files/test_file.json") + + +class TestExportColors(unittest.TestCase): + """Test the export functions.""" + + def test_template(self): + """> Test substitutions in template file.""" + # Merge both dicts so we can access their + # values simpler. + COLORS["colors"].update(COLORS["special"]) + + output_dir = pathlib.Path("/tmp") + template_dir = pathlib.Path("tests/test_files/templates") + template.export_all_templates(COLORS, output_dir, template_dir) + + result = pathlib.Path("/tmp/test_template").is_file() + self.assertTrue(result) + + content = pathlib.Path("/tmp/test_template").read_text() + self.assertEqual(content, '\n'.join(["test1 #1F211E", + "test2 #1F211E", + "test3 31,33,30", ""])) + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3