mirror of
https://github.com/dylanaraps/pywal.git
synced 2024-11-25 09:23:08 +01:00
43 lines
1.3 KiB
Python
Executable File
43 lines
1.3 KiB
Python
Executable File
"""Test imagemagick functions."""
|
|
import unittest
|
|
import unittest.mock
|
|
import io
|
|
import pathlib
|
|
|
|
from pywal import colors
|
|
|
|
|
|
CACHE_DIR = pathlib.Path("/tmp/wal")
|
|
|
|
|
|
class TestGenColors(unittest.TestCase):
|
|
"""Test the gen_colors functions."""
|
|
|
|
def test_gen_colors(self):
|
|
"""> Generate a colorscheme."""
|
|
result = colors.get("tests/test_files/test.jpg", CACHE_DIR)
|
|
self.assertEqual(len(result["colors"]["color0"]), 7)
|
|
|
|
def test_gen_colors_fail(self):
|
|
"""> Generate a colorscheme and fail."""
|
|
with self.assertRaises(SystemExit):
|
|
colors.get("tests/test_files/test.png")
|
|
|
|
def test_color_cache(self):
|
|
"""> Test importing a cached scheme."""
|
|
# 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:
|
|
colors.get("tests/test_files/test.jpg", CACHE_DIR)
|
|
self.assertEqual(fake_out.getvalue().strip(), message)
|
|
|
|
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")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|