pywal/tests/test_util.py

55 lines
1.5 KiB
Python
Raw Normal View History

2017-06-27 03:41:04 +02:00
"""Test util functions."""
import unittest
import pathlib
from pywal import util
class TestUtil(unittest.TestCase):
"""Test the util functions."""
def test_read_file_start(self):
2017-06-27 09:02:42 +02:00
"""> Read colors from a file."""
2017-06-27 03:41:04 +02:00
result = util.read_file("tests/test_file")
self.assertEqual(result[0], "#363442")
def test_read_file_end(self):
2017-06-27 09:02:42 +02:00
"""> Read colors from a file."""
2017-06-27 03:41:04 +02:00
result = util.read_file("tests/test_file")
self.assertEqual(result[15], "#C9CFD0")
def test_save_file(self):
2017-06-27 09:02:42 +02:00
"""> Save colors to a file."""
2017-06-27 03:41:04 +02:00
tmp_file = pathlib.Path("/tmp/test_file")
util.save_file("Hello, world", tmp_file)
result = tmp_file.is_file()
self.assertTrue(result)
def test_create_dir(self):
2017-06-27 09:02:42 +02:00
"""> Create a directoru."""
2017-06-27 03:41:04 +02:00
tmp_dir = pathlib.Path("/tmp/test_dir")
util.create_dir(tmp_dir)
result = tmp_dir.is_dir()
self.assertTrue(result)
def test_hex_to_rgb_black(self):
2017-06-27 09:02:42 +02:00
"""> Convert #000000 to RGB."""
2017-06-27 03:41:04 +02:00
result = util.hex_to_rgb("#000000")
self.assertEqual(result, "0,0,0")
def test_hex_to_rgb_white(self):
2017-06-27 09:02:42 +02:00
"""> Convert #FFFFFF to RGB."""
2017-06-27 03:41:04 +02:00
result = util.hex_to_rgb("#FFFFFF")
self.assertEqual(result, "255,255,255")
def test_hex_to_rgb_rand(self):
2017-06-27 09:02:42 +02:00
"""> Convert #98AEC2 to RGB."""
2017-06-27 03:41:04 +02:00
result = util.hex_to_rgb("#98AEC2")
self.assertEqual(result, "152,174,194")
# Figure out how to test this.
# def test_disown(self):
if __name__ == "__main__":
unittest.main()