summaryrefslogtreecommitdiff
path: root/tests/test_util.py
diff options
context:
space:
mode:
authorDylan Araps <dylanaraps@users.noreply.github.com>2017-06-27 17:57:14 +1000
committerGitHub <noreply@github.com>2017-06-27 17:57:14 +1000
commitea160a42dec139148845aeb3043db5ba23bd9a6c (patch)
tree24ebf656944839f6328b1bef09a46a56800a1ca6 /tests/test_util.py
parent277c27c98a819c8e8de9dffde07192791a0d16d4 (diff)
parent7c3676c809a06aafb4f6f3b8cdc289c946be7695 (diff)
Merge pull request #11 from dylanaraps/tests
Tests: Start writing tests.
Diffstat (limited to 'tests/test_util.py')
-rwxr-xr-xtests/test_util.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_util.py b/tests/test_util.py
new file mode 100755
index 0000000..b1a396b
--- /dev/null
+++ b/tests/test_util.py
@@ -0,0 +1,55 @@
+"""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):
+ """> Read colors from a file."""
+ result = util.read_file("tests/test_files/test_file")
+ self.assertEqual(result[0], "#363442")
+
+ def test_read_file_end(self):
+ """> Read colors from a file."""
+ result = util.read_file("tests/test_files/test_file")
+ self.assertEqual(result[15], "#C9CFD0")
+
+ def test_save_file(self):
+ """> Save colors to a file."""
+ 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):
+ """> Create a directoru."""
+ 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):
+ """> Convert #000000 to RGB."""
+ result = util.hex_to_rgb("#000000")
+ self.assertEqual(result, "0,0,0")
+
+ def test_hex_to_rgb_white(self):
+ """> Convert #FFFFFF to RGB."""
+ result = util.hex_to_rgb("#FFFFFF")
+ self.assertEqual(result, "255,255,255")
+
+ def test_hex_to_rgb_rand(self):
+ """> Convert #98AEC2 to RGB."""
+ 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()