2017-06-30 02:21:20 +02:00
|
|
|
"""Test imagemagick functions."""
|
2017-06-27 09:30:31 +02:00
|
|
|
import unittest
|
2017-07-23 13:09:02 +02:00
|
|
|
import unittest.mock
|
|
|
|
import io
|
2017-07-23 13:29:38 +02:00
|
|
|
import pathlib
|
2017-06-27 09:30:31 +02:00
|
|
|
|
2017-07-22 14:26:49 +02:00
|
|
|
from pywal import colors
|
2017-07-23 13:36:58 +02:00
|
|
|
from pywal import util
|
2017-07-23 13:29:38 +02:00
|
|
|
|
|
|
|
|
2017-06-27 09:30:31 +02:00
|
|
|
class TestGenColors(unittest.TestCase):
|
|
|
|
"""Test the gen_colors functions."""
|
|
|
|
|
2017-06-27 09:43:14 +02:00
|
|
|
def test_gen_colors(self):
|
|
|
|
"""> Generate a colorscheme."""
|
2017-07-23 13:36:58 +02:00
|
|
|
result = colors.get("tests/test_files/test.jpg")
|
2017-07-23 09:50:18 +02:00
|
|
|
self.assertEqual(len(result["colors"]["color0"]), 7)
|
2017-06-27 09:43:14 +02:00
|
|
|
|
2017-07-23 13:01:01 +02:00
|
|
|
def test_gen_colors_fail(self):
|
|
|
|
"""> Generate a colorscheme and fail."""
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
colors.get("tests/test_files/test.png")
|
|
|
|
|
2017-07-23 13:09:02 +02:00
|
|
|
def test_color_cache(self):
|
|
|
|
"""> Test importing a cached scheme."""
|
2017-07-23 13:36:58 +02:00
|
|
|
# Create the file to import.
|
|
|
|
cache_dir = pathlib.Path("/tmp/wal2/")
|
|
|
|
util.save_file("true", cache_dir / "schemes"
|
|
|
|
/ "tests_test_files_test_jpg.json")
|
|
|
|
|
2017-07-23 13:09:02 +02:00
|
|
|
# Since this function just prints a message we redirect
|
|
|
|
# it's output so that we can read it.
|
|
|
|
message = "colors: Found cached colorscheme."
|
|
|
|
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
|
2017-07-23 13:36:58 +02:00
|
|
|
colors.get("tests/test_files/test.jpg", cache_dir)
|
2017-07-23 13:09:02 +02:00
|
|
|
self.assertEqual(fake_out.getvalue().strip(), message)
|
|
|
|
|
2017-07-23 13:14:02 +02:00
|
|
|
def test_color_import(self):
|
|
|
|
"""> Read colors from a file."""
|
|
|
|
result = colors.file("tests/test_files/test_file.json")
|
|
|
|
self.assertEqual(result["colors"]["color0"], "#1F211E")
|
|
|
|
|
2017-07-23 13:42:30 +02:00
|
|
|
def test_color_import_no_wallpaper(self):
|
|
|
|
"""> Read colors from a file without a wallpaper."""
|
|
|
|
result = colors.file("tests/test_files/test_file2.json")
|
|
|
|
self.assertEqual(result["wallpaper"], "None")
|
|
|
|
|
2017-06-27 09:30:31 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|