From 676f5325e11cfc12d6080f6cdb27be2e697a88a8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 22 Jul 2017 23:48:47 +1000 Subject: tests: Add new template test. --- tests/test_files/templates/test_template | 3 --- tests/test_template.py | 33 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) delete mode 100644 tests/test_files/templates/test_template (limited to 'tests') diff --git a/tests/test_files/templates/test_template b/tests/test_files/templates/test_template deleted file mode 100644 index af40ce7..0000000 --- a/tests/test_files/templates/test_template +++ /dev/null @@ -1,3 +0,0 @@ -test1 {color0} -test2 {background} -test3 {background.rgb} diff --git a/tests/test_template.py b/tests/test_template.py index ef71b8b..9b9870d 100755 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -8,28 +8,43 @@ from pywal import util # Import colors. COLORS = util.read_file_json("tests/test_files/test_file.json") +OUTPUT_DIR = pathlib.Path("/tmp/wal") + +util.create_dir("/tmp/wal") class TestExportColors(unittest.TestCase): """Test the export functions.""" - def test_template(self): + def test_all_templates(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(COLORS, output_dir, template_dir) + template.export_all(COLORS, OUTPUT_DIR) + + result = pathlib.Path("/tmp/colors.sh").is_file() + self.assertTrue(result) + + content = pathlib.Path("/tmp/colors.sh").read_text() + content = content.split("\n")[6] + self.assertEqual(content, "foreground='#F5F1F4'") + + def test_css_template(self): + """> Test substitutions in template file (css).""" + # Merge both dicts so we can access their + # values simpler. + COLORS["colors"].update(COLORS["special"]) + + template.export(COLORS, "colors.css", OUTPUT_DIR) - result = pathlib.Path("/tmp/test_template").is_file() + result = pathlib.Path("/tmp/colors.css").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", ""])) + content = pathlib.Path("/tmp/colors.css").read_text() + content = content.split("\n")[6] + self.assertEqual(content, " --background: #1F211E;") if __name__ == "__main__": -- cgit v1.2.3