From 9d9b24e415df8bd6662595169f330038ee45d569 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 11:41:04 +1000 Subject: 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() -- cgit v1.2.3 From bae528e85629562c3382ed981b3357193cde142b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 11:53:40 +1000 Subject: tests: Integrate tests with setup.pu --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d6a8017..d0729b6 100644 --- a/setup.py +++ b/setup.py @@ -35,5 +35,6 @@ setup( entry_points={ "console_scripts": ["wal=pywal.__main__:main"] }, - python_requires=">=3.6" + python_requires=">=3.6", + test_suite="tests", ) -- cgit v1.2.3 From ce2d85d5d6ef321b5950d9728ee7204e5724a945 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 11:55:08 +1000 Subject: tests: Integrate tests with travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 46e5aaa..464bdf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,4 @@ install: script: - flake8 pywal setup.py - pylint --ignore-imports=yes pywal setup.py + - python setup.py test -- cgit v1.2.3 From 10c7099a27542d58a66e4fb8d740ec62db2904bf Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:02:42 +1000 Subject: tests: Fix comments --- setup.py | 2 +- tests/test_export_colors.py | 21 +++++++++++++++++++++ tests/test_util.py | 14 +++++++------- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100755 tests/test_export_colors.py diff --git a/setup.py b/setup.py index d0729b6..9e22fef 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,6 @@ setup( entry_points={ "console_scripts": ["wal=pywal.__main__:main"] }, - python_requires=">=3.6", + requires_python=">=3.6", test_suite="tests", ) diff --git a/tests/test_export_colors.py b/tests/test_export_colors.py new file mode 100755 index 0000000..ce6fe1e --- /dev/null +++ b/tests/test_export_colors.py @@ -0,0 +1,21 @@ +"""Test util functions.""" +import unittest +import pathlib +from pywal import export_colors +from pywal import util + + +class TestExportColors(unittest.TestCase): + """Test the export_colors functions.""" + + def test_save_colors(self): + """> Export colors to a file.""" + tmp_file = pathlib.Path("/tmp/test_file") + colors = util.read_file("tests/test_file") + export_colors.save_colors(colors, tmp_file, "plain colors") + result = tmp_file.is_file() + self.assertTrue(result) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_util.py b/tests/test_util.py index 3aebc78..0d72f01 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -8,41 +8,41 @@ class TestUtil(unittest.TestCase): """Test the util functions.""" def test_read_file_start(self): - """Test read_file().""" + """> Read colors from a file.""" result = util.read_file("tests/test_file") self.assertEqual(result[0], "#363442") def test_read_file_end(self): - """Test read_file().""" + """> Read colors from a file.""" result = util.read_file("tests/test_file") self.assertEqual(result[15], "#C9CFD0") def test_save_file(self): - """Test save_file().""" + """> 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): - """Test create_dir().""" + """> 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): - """Test hex_to_rgb() on #000000.""" + """> Convert #000000 to RGB.""" 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.""" + """> Convert #FFFFFF to RGB.""" 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.""" + """> Convert #98AEC2 to RGB.""" result = util.hex_to_rgb("#98AEC2") self.assertEqual(result, "152,174,194") -- cgit v1.2.3 From 081bb9066bf754aee23489a76f0d5e63bcb4935b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:14:47 +1000 Subject: tests: Added format_colors test. --- tests/test_format_colors.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 tests/test_format_colors.py diff --git a/tests/test_format_colors.py b/tests/test_format_colors.py new file mode 100755 index 0000000..fab7181 --- /dev/null +++ b/tests/test_format_colors.py @@ -0,0 +1,46 @@ +"""Test format functions.""" +import unittest +from pywal import format_color +from pywal import util + + +# Import colors. +COLORS = util.read_file("tests/test_file") + + +class TestExportColors(unittest.TestCase): + """Test the format_colors functions.""" + + def test_plain(self): + """> Convert colors to plain.""" + result = format_color.plain(COLORS) + self.assertEqual(result[0], "#363442\n") + + def test_shell(self): + """> Convert colors to shell variables.""" + result = format_color.shell(COLORS) + self.assertEqual(result[0], "color0='#363442'\n") + + def test_css(self): + """> Convert colors to css variables.""" + result = format_color.css(COLORS) + self.assertEqual(result[1], "\t--color0: #363442;\n") + + def test_scss(self): + """> Convert colors to scss variables.""" + result = format_color.scss(COLORS) + self.assertEqual(result[0], "$color0: #363442;\n") + + def test_putty(self): + """> Convert colors to putty theme.""" + result = format_color.putty(COLORS) + self.assertEqual(result[2], "\"colour0\"=\"54,52,66\"\n") + + def test_xrdb(self): + """> Convert colors to putty theme.""" + result = format_color.xrdb(COLORS) + self.assertEqual(result[6], "*.color0: #363442\n*color0: #363442\n") + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From 790ab71c50ad4d7e695d4e868933363c4be090fa Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:24:27 +1000 Subject: tests: Added set_colors tests. --- setup.py | 2 +- tests/test_export_colors.py | 5 +++++ tests/test_format_colors.py | 3 ++- tests/test_set_colors.py | 32 ++++++++++++++++++++++++++++++++ tests/test_util.py | 1 + 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100755 tests/test_set_colors.py diff --git a/setup.py b/setup.py index 9e22fef..d0729b6 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,6 @@ setup( entry_points={ "console_scripts": ["wal=pywal.__main__:main"] }, - requires_python=">=3.6", + python_requires=">=3.6", test_suite="tests", ) diff --git a/tests/test_export_colors.py b/tests/test_export_colors.py index ce6fe1e..5680dfc 100755 --- a/tests/test_export_colors.py +++ b/tests/test_export_colors.py @@ -1,10 +1,15 @@ """Test util functions.""" import unittest import pathlib + from pywal import export_colors from pywal import util +# Import colors. +COLORS = util.read_file("tests/test_file") + + class TestExportColors(unittest.TestCase): """Test the export_colors functions.""" diff --git a/tests/test_format_colors.py b/tests/test_format_colors.py index fab7181..ecee336 100755 --- a/tests/test_format_colors.py +++ b/tests/test_format_colors.py @@ -1,5 +1,6 @@ """Test format functions.""" import unittest + from pywal import format_color from pywal import util @@ -8,7 +9,7 @@ from pywal import util COLORS = util.read_file("tests/test_file") -class TestExportColors(unittest.TestCase): +class TestFormatColors(unittest.TestCase): """Test the format_colors functions.""" def test_plain(self): diff --git a/tests/test_set_colors.py b/tests/test_set_colors.py new file mode 100755 index 0000000..5ff6b5c --- /dev/null +++ b/tests/test_set_colors.py @@ -0,0 +1,32 @@ +"""Test set functions.""" +import unittest + +from pywal import set_colors +from pywal import util + + +# Import colors. +COLORS = util.read_file("tests/test_file") + + +class TestSetColors(unittest.TestCase): + """Test the format_colors functions.""" + + def test_set_special(self): + """> Create special escape sequence.""" + result = set_colors.set_special(11, COLORS[0]) + self.assertEqual(result, "\x1b]11;#363442\x07") + + def test_set_color(self): + """> Create color escape sequence.""" + result = set_colors.set_color(11, COLORS[0]) + self.assertEqual(result, "\033]4;11;#363442\007") + + def test_set_grey(self): + """> Create special escape sequence.""" + result = set_colors.set_grey(COLORS) + self.assertEqual(result, "#999999") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_util.py b/tests/test_util.py index 0d72f01..6aeef9b 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,7 @@ """Test util functions.""" import unittest import pathlib + from pywal import util -- cgit v1.2.3 From 9e2fb01222ddc06cc77675e8821eefe6c0101377 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:30:31 +1000 Subject: tests: Added gen_colors test. --- tests/test.jpg | 0 tests/test_gen_colors.py | 27 +++++++++++++++++++++++++++ tests/test_set_colors.py | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/test.jpg create mode 100755 tests/test_gen_colors.py diff --git a/tests/test.jpg b/tests/test.jpg new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_gen_colors.py b/tests/test_gen_colors.py new file mode 100755 index 0000000..e9fa5e2 --- /dev/null +++ b/tests/test_gen_colors.py @@ -0,0 +1,27 @@ +"""Test gen functions.""" +import unittest + +from pywal import gen_colors +from pywal import util + + +# Import colors. +COLORS = util.read_file("tests/test_file") + + +class TestGenColors(unittest.TestCase): + """Test the gen_colors functions.""" + + def test_get_img(self): + """> Validate image file.""" + result = gen_colors.get_image("tests/test.jpg") + self.assertEqual(result, "tests/test.jpg") + + def test_get_img_dir(self): + """> Validate image directory.""" + result = gen_colors.get_image("tests") + self.assertEqual(result, "tests/test.jpg") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_set_colors.py b/tests/test_set_colors.py index 5ff6b5c..3d3d800 100755 --- a/tests/test_set_colors.py +++ b/tests/test_set_colors.py @@ -10,7 +10,7 @@ COLORS = util.read_file("tests/test_file") class TestSetColors(unittest.TestCase): - """Test the format_colors functions.""" + """Test the set_colors functions.""" def test_set_special(self): """> Create special escape sequence.""" -- cgit v1.2.3 From dbba94976cee6ab155ab6fc1bcf3344c6228c516 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:34:34 +1000 Subject: tests: Move test files to other directory. --- .travis.yml | 4 ++-- tests/test.jpg | 0 tests/test_export_colors.py | 4 ++-- tests/test_file | 16 ---------------- tests/test_files/test.jpg | 0 tests/test_files/test_file | 16 ++++++++++++++++ tests/test_format_colors.py | 2 +- tests/test_gen_colors.py | 13 ++++--------- tests/test_set_colors.py | 2 +- tests/test_util.py | 4 ++-- 10 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 tests/test.jpg delete mode 100644 tests/test_file create mode 100644 tests/test_files/test.jpg create mode 100644 tests/test_files/test_file diff --git a/.travis.yml b/.travis.yml index 464bdf8..f3f35ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ install: - pip install flake8 pylint script: - - flake8 pywal setup.py - - pylint --ignore-imports=yes pywal setup.py + - flake8 pywal tests setup.py + - pylint --ignore-imports=yes pywal tests setup.py - python setup.py test diff --git a/tests/test.jpg b/tests/test.jpg deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_export_colors.py b/tests/test_export_colors.py index 5680dfc..09265c6 100755 --- a/tests/test_export_colors.py +++ b/tests/test_export_colors.py @@ -7,7 +7,7 @@ from pywal import util # Import colors. -COLORS = util.read_file("tests/test_file") +COLORS = util.read_file("tests/test_files/test_file") class TestExportColors(unittest.TestCase): @@ -16,7 +16,7 @@ class TestExportColors(unittest.TestCase): def test_save_colors(self): """> Export colors to a file.""" tmp_file = pathlib.Path("/tmp/test_file") - colors = util.read_file("tests/test_file") + colors = util.read_file("tests/test_files/test_file") export_colors.save_colors(colors, tmp_file, "plain colors") result = tmp_file.is_file() self.assertTrue(result) diff --git a/tests/test_file b/tests/test_file deleted file mode 100644 index 30eeeaa..0000000 --- a/tests/test_file +++ /dev/null @@ -1,16 +0,0 @@ -#363442 -#99A3B1 -#C5BDB6 -#98AEC2 -#A8B9C6 -#96C4CF -#B7C5CC -#C9CFD0 -#999999 -#99A3B1 -#C5BDB6 -#98AEC2 -#A8B9C6 -#96C4CF -#B7C5CC -#C9CFD0 diff --git a/tests/test_files/test.jpg b/tests/test_files/test.jpg new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_files/test_file b/tests/test_files/test_file new file mode 100644 index 0000000..30eeeaa --- /dev/null +++ b/tests/test_files/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_format_colors.py b/tests/test_format_colors.py index ecee336..63c1ce2 100755 --- a/tests/test_format_colors.py +++ b/tests/test_format_colors.py @@ -6,7 +6,7 @@ from pywal import util # Import colors. -COLORS = util.read_file("tests/test_file") +COLORS = util.read_file("tests/test_files/test_file") class TestFormatColors(unittest.TestCase): diff --git a/tests/test_gen_colors.py b/tests/test_gen_colors.py index e9fa5e2..8bab35a 100755 --- a/tests/test_gen_colors.py +++ b/tests/test_gen_colors.py @@ -2,11 +2,6 @@ import unittest from pywal import gen_colors -from pywal import util - - -# Import colors. -COLORS = util.read_file("tests/test_file") class TestGenColors(unittest.TestCase): @@ -14,13 +9,13 @@ class TestGenColors(unittest.TestCase): def test_get_img(self): """> Validate image file.""" - result = gen_colors.get_image("tests/test.jpg") - self.assertEqual(result, "tests/test.jpg") + result = gen_colors.get_image("tests/test_files/test.jpg") + self.assertEqual(result, "tests/test_files/test.jpg") def test_get_img_dir(self): """> Validate image directory.""" - result = gen_colors.get_image("tests") - self.assertEqual(result, "tests/test.jpg") + result = gen_colors.get_image("tests/test_files") + self.assertEqual(result, "tests/test_files/test.jpg") if __name__ == "__main__": diff --git a/tests/test_set_colors.py b/tests/test_set_colors.py index 3d3d800..43c6aed 100755 --- a/tests/test_set_colors.py +++ b/tests/test_set_colors.py @@ -6,7 +6,7 @@ from pywal import util # Import colors. -COLORS = util.read_file("tests/test_file") +COLORS = util.read_file("tests/test_files/test_file") class TestSetColors(unittest.TestCase): diff --git a/tests/test_util.py b/tests/test_util.py index 6aeef9b..b1a396b 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -10,12 +10,12 @@ class TestUtil(unittest.TestCase): def test_read_file_start(self): """> Read colors from a file.""" - result = util.read_file("tests/test_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_file") + result = util.read_file("tests/test_files/test_file") self.assertEqual(result[15], "#C9CFD0") def test_save_file(self): -- cgit v1.2.3 From 2cee85a15ed50a7ef3fc94b4fb47ba4d5cb44a51 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:43:14 +1000 Subject: tests: Add a real image file. --- tests/test_files/test.jpg | Bin 0 -> 8074 bytes tests/test_gen_colors.py | 5 +++++ 2 files changed, 5 insertions(+) diff --git a/tests/test_files/test.jpg b/tests/test_files/test.jpg index e69de29..b613ed0 100644 Binary files a/tests/test_files/test.jpg and b/tests/test_files/test.jpg differ diff --git a/tests/test_gen_colors.py b/tests/test_gen_colors.py index 8bab35a..18ba821 100755 --- a/tests/test_gen_colors.py +++ b/tests/test_gen_colors.py @@ -17,6 +17,11 @@ class TestGenColors(unittest.TestCase): result = gen_colors.get_image("tests/test_files") self.assertEqual(result, "tests/test_files/test.jpg") + def test_gen_colors(self): + """> Generate a colorscheme.""" + result = gen_colors.gen_colors("tests/test_files/test.jpg") + self.assertEqual(result[0], "#0F191A") + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 79346ca941ae019acabea2177a4c045565ac134a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:44:29 +1000 Subject: travis: Install imagemagick. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index f3f35ac..f924d60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: python python: - "3.6" +before_install: + - sudo apt-get -qq update + - sudo apt-get install -y imagemagick + install: - pip install flake8 pylint -- cgit v1.2.3 From 7c3676c809a06aafb4f6f3b8cdc289c946be7695 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 27 Jun 2017 17:46:55 +1000 Subject: tests: Fix comment. --- tests/test_export_colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_export_colors.py b/tests/test_export_colors.py index 09265c6..5ca04d9 100755 --- a/tests/test_export_colors.py +++ b/tests/test_export_colors.py @@ -1,4 +1,4 @@ -"""Test util functions.""" +"""Test export functions.""" import unittest import pathlib -- cgit v1.2.3