pywal/tests/test_template.py

52 lines
1.4 KiB
Python
Raw Normal View History

2017-06-27 09:46:55 +02:00
"""Test export functions."""
2017-06-27 09:02:42 +02:00
import unittest
import pathlib
2017-06-27 09:24:27 +02:00
2017-07-22 14:26:49 +02:00
from pywal import template
2017-06-27 09:02:42 +02:00
from pywal import util
2017-06-27 09:24:27 +02:00
# Import colors.
COLORS = util.read_file_json("tests/test_files/test_file.json")
2017-07-22 15:48:47 +02:00
OUTPUT_DIR = pathlib.Path("/tmp/wal")
util.create_dir("/tmp/wal")
2017-06-27 09:24:27 +02:00
2017-06-27 09:02:42 +02:00
class TestExportColors(unittest.TestCase):
"""Test the export functions."""
2017-06-27 09:02:42 +02:00
2017-07-22 15:48:47 +02:00
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"])
2017-07-22 15:48:47 +02:00
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)
2017-07-22 15:48:47 +02:00
result = pathlib.Path("/tmp/colors.css").is_file()
2017-06-27 09:02:42 +02:00
self.assertTrue(result)
2017-07-22 15:48:47 +02:00
content = pathlib.Path("/tmp/colors.css").read_text()
content = content.split("\n")[6]
self.assertEqual(content, " --background: #1F211E;")
2017-06-27 09:02:42 +02:00
if __name__ == "__main__":
unittest.main()