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 io
|
2017-06-27 09:02:42 +02:00
|
|
|
import pathlib
|
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
|
|
|
|
|
|
|
|
|
2017-06-27 09:24:27 +02:00
|
|
|
# Import colors.
|
2017-06-29 04:15:41 +02:00
|
|
|
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
|
|
|
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):
|
2017-06-30 01:54:10 +02:00
|
|
|
"""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):
|
2017-06-29 11:52:43 +02:00
|
|
|
"""> Test substitutions in template file."""
|
2017-07-23 03:50:46 +02:00
|
|
|
export.every(COLORS, OUTPUT_DIR)
|
2017-07-22 15:48:47 +02:00
|
|
|
|
2017-07-22 15:57:18 +02:00
|
|
|
result = pathlib.Path("/tmp/wal/colors.sh").is_file()
|
2017-07-22 15:48:47 +02:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
2017-07-22 15:57:18 +02:00
|
|
|
content = pathlib.Path("/tmp/wal/colors.sh").read_text()
|
2017-07-22 15:48:47 +02:00
|
|
|
content = content.split("\n")[6]
|
|
|
|
self.assertEqual(content, "foreground='#F5F1F4'")
|
|
|
|
|
|
|
|
def test_css_template(self):
|
|
|
|
"""> Test substitutions in template file (css)."""
|
2017-07-23 03:50:46 +02:00
|
|
|
export.color(COLORS, "css", OUTPUT_DIR / "test.css")
|
2017-06-29 11:52:43 +02:00
|
|
|
|
2017-07-23 03:50:46 +02:00
|
|
|
result = pathlib.Path("/tmp/wal/test.css").is_file()
|
2017-06-27 09:02:42 +02:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
2017-07-23 03:50:46 +02:00
|
|
|
content = pathlib.Path("/tmp/wal/test.css").read_text()
|
2017-07-22 15:48:47 +02:00
|
|
|
content = content.split("\n")[6]
|
|
|
|
self.assertEqual(content, " --background: #1F211E;")
|
2017-06-29 16:47:13 +02:00
|
|
|
|
2017-07-23 12:53:33 +02:00
|
|
|
def test_invalid_template(self):
|
|
|
|
"""> Test template validation."""
|
|
|
|
error_msg = "[!] warning: template 'dummy' doesn't exist."
|
|
|
|
|
|
|
|
# Since this function prints a message on fail we redirect
|
|
|
|
# it's output so that we can read it.
|
|
|
|
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
|
|
|
|
export.color(COLORS, "dummy", OUTPUT_DIR / "test.css")
|
|
|
|
self.assertEqual(fake_out.getvalue().strip(), error_msg)
|
|
|
|
|
2017-06-27 09:02:42 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|