pywal/tests/test_export.py

57 lines
1.5 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
2017-07-23 12:53:33 +02:00
import unittest.mock
import shutil
2017-08-10 01:17:11 +02:00
import os
2017-06-27 09:24:27 +02:00
2017-07-23 03:50:46 +02:00
from pywal import export
2017-06-27 09:02:42 +02:00
from pywal import util
COLORS = util.read_file_json("tests/test_files/test_file.json")
2017-07-22 15:50:40 +02:00
COLORS["colors"].update(COLORS["special"])
2017-07-22 15:48:47 +02:00
TMP_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
def setUp(self):
"""> Setup export tests."""
util.create_dir(TMP_DIR)
2017-07-22 15:48:47 +02:00
def tearDown(self):
"""> Clean up export tests."""
shutil.rmtree(TMP_DIR, ignore_errors=True)
def is_file(self, tmp_file):
"""> Test is something is a file."""
result = os.path.isfile(tmp_file)
2017-07-22 15:48:47 +02:00
self.assertTrue(result)
def is_file_contents(self, tmp_file, pattern):
"""> Check for pattern in file."""
content = util.read_file(tmp_file)
2017-08-15 13:47:02 +02:00
self.assertEqual(content[6], pattern)
2017-08-10 01:17:11 +02:00
def test_all_templates(self):
"""> Test substitutions in template file."""
tmp_file = os.path.join(TMP_DIR, "colors.sh")
export.every(COLORS, TMP_DIR)
self.is_file(tmp_file)
self.is_file_contents(tmp_file, "foreground='#F5F1F4'")
2017-07-22 15:48:47 +02:00
def test_css_template(self):
"""> Test substitutions in template file (css)."""
tmp_file = os.path.join(TMP_DIR, "test.css")
export.color(COLORS, "css", tmp_file)
self.is_file(tmp_file)
self.is_file_contents(tmp_file, " --background: #1F211E;")
2017-06-27 09:02:42 +02:00
2017-08-10 01:17:11 +02:00
2017-06-27 09:02:42 +02:00
if __name__ == "__main__":
unittest.main()