From 9d9b24e415df8bd6662595169f330038ee45d569 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 11:41:04 +1000 Subject: [PATCH] General: Add initial test. --- pywal/util.py | 4 +++- tests/__init__.py | 4 ++++ tests/test_file | 16 ++++++++++++++ tests/test_util.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 tests/__init__.py create mode 100644 tests/test_file create mode 100755 tests/test_util.py diff --git a/pywal/util.py b/pywal/util.py index bc385d9..67baa6a 100755 --- a/pywal/util.py +++ b/pywal/util.py @@ -8,7 +8,9 @@ import subprocess def read_file(input_file): """Read colors from a file.""" - return open(input_file).read().splitlines() + with open(input_file) as file: + colors = file.read().splitlines() + return colors def save_file(colors, export_file): diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100755 index 0000000..af433d7 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,4 @@ +""" +wal - Generate and change colorschemes on the fly. +Created by Dylan Araps. +""" diff --git a/tests/test_file b/tests/test_file new file mode 100644 index 0000000..30eeeaa --- /dev/null +++ b/tests/test_file @@ -0,0 +1,16 @@ +#363442 +#99A3B1 +#C5BDB6 +#98AEC2 +#A8B9C6 +#96C4CF +#B7C5CC +#C9CFD0 +#999999 +#99A3B1 +#C5BDB6 +#98AEC2 +#A8B9C6 +#96C4CF +#B7C5CC +#C9CFD0 diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100755 index 0000000..3aebc78 --- /dev/null +++ b/tests/test_util.py @@ -0,0 +1,54 @@ +"""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): + """Test read_file().""" + result = util.read_file("tests/test_file") + self.assertEqual(result[0], "#363442") + + def test_read_file_end(self): + """Test read_file().""" + result = util.read_file("tests/test_file") + self.assertEqual(result[15], "#C9CFD0") + + def test_save_file(self): + """Test save_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): + """Test create_dir().""" + 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): + """Test hex_to_rgb() on #000000.""" + result = util.hex_to_rgb("#000000") + self.assertEqual(result, "0,0,0") + + def test_hex_to_rgb_white(self): + """Test hex_to_rgb() on #FFFFFF.""" + result = util.hex_to_rgb("#FFFFFF") + self.assertEqual(result, "255,255,255") + + def test_hex_to_rgb_rand(self): + """Test hex_to_rgb() on #98AEC2.""" + 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()