From d98be353ecd5deff97804312ec798fb227adfbc1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 9 Aug 2017 11:22:51 +1000 Subject: general: Make pywal compatible with python 3.5 --- tests/test_export.py | 2 +- tests/test_main.py | 4 +++- tests/test_sequences.py | 3 ++- tests/test_util.py | 5 ++--- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_export.py b/tests/test_export.py index 2323c69..e2838fe 100755 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -43,7 +43,7 @@ class TestExportColors(unittest.TestCase): def test_invalid_template(self): """> Test template validation.""" - error_msg = "[!] warning: template 'dummy' doesn't exist." + error_msg = "warning: template 'dummy' doesn't exist." # Since this function prints a message on fail we redirect # it's output so that we can read it. diff --git a/tests/test_main.py b/tests/test_main.py index 9262c8f..7f1a1bb 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,6 +2,8 @@ import unittest from unittest.mock import MagicMock +import os + from pywal import __main__ from pywal import reload from pywal.settings import CACHE_DIR @@ -14,7 +16,7 @@ class TestMain(unittest.TestCase): """> Test arg parsing (-c)""" args = __main__.get_args(["-c"]) __main__.process_args(args) - self.assertFalse((CACHE_DIR / "schemes").is_dir()) + self.assertFalse(os.path.isdir(str(CACHE_DIR / "schemes"))) def test_args_e(self): """> Test arg parsing (-e)""" diff --git a/tests/test_sequences.py b/tests/test_sequences.py index 66f4084..392abc7 100755 --- a/tests/test_sequences.py +++ b/tests/test_sequences.py @@ -32,7 +32,8 @@ class Testsequences(unittest.TestCase): def test_set_iterm_tab_color(self): """> Create iterm tab color sequences""" result = sequences.set_iterm_tab_color(COLORS["special"]["background"]) - self.assertEqual(len(result), 3) + print(result) + self.assertEqual(len(result), 104) if __name__ == "__main__": diff --git a/tests/test_util.py b/tests/test_util.py index bc551ef..aae0356 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -49,10 +49,9 @@ class TestUtil(unittest.TestCase): def test_create_dir(self): """> Create a directory.""" - tmp_dir = pathlib.Path("/tmp/test_dir") + tmp_dir = "/tmp/test_dir" util.create_dir(tmp_dir) - result = tmp_dir.is_dir() - self.assertTrue(result) + self.assertTrue(os.path.isdir(tmp_dir)) os.rmdir(tmp_dir) def test_hex_to_rgb_black(self): -- cgit v1.2.3 From cbbb5a5b6a317dd2d8790afb8aa6b26d1d61a179 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 10 Aug 2017 01:08:28 +1000 Subject: tests: Fix print --- tests/test_sequences.py | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/test_sequences.py b/tests/test_sequences.py index 392abc7..7a21c11 100755 --- a/tests/test_sequences.py +++ b/tests/test_sequences.py @@ -32,7 +32,6 @@ class Testsequences(unittest.TestCase): def test_set_iterm_tab_color(self): """> Create iterm tab color sequences""" result = sequences.set_iterm_tab_color(COLORS["special"]["background"]) - print(result) self.assertEqual(len(result), 104) -- cgit v1.2.3 From 05c271c3a7faf0e31c28df4a7743c8ce4369c670 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 10 Aug 2017 09:17:11 +1000 Subject: general: Remove all pathlib usage --- tests/test_export.py | 27 ++++++++++++++------------- tests/test_main.py | 3 ++- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/test_export.py b/tests/test_export.py index e2838fe..7cb0bb4 100755 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -2,7 +2,7 @@ import unittest import unittest.mock import io -import pathlib +import os from pywal import export from pywal import util @@ -11,7 +11,6 @@ from pywal import util # Import colors. COLORS = util.read_file_json("tests/test_files/test_file.json") COLORS["colors"].update(COLORS["special"]) -OUTPUT_DIR = pathlib.Path("/tmp/wal") util.create_dir("/tmp/wal") @@ -21,25 +20,27 @@ class TestExportColors(unittest.TestCase): def test_all_templates(self): """> Test substitutions in template file.""" - export.every(COLORS, OUTPUT_DIR) + export.every(COLORS, "/tmp/wal") - result = pathlib.Path("/tmp/wal/colors.sh").is_file() + result = os.path.isfile("/tmp/wal/colors.sh") self.assertTrue(result) - content = pathlib.Path("/tmp/wal/colors.sh").read_text() - content = content.split("\n")[6] - self.assertEqual(content, "foreground='#F5F1F4'") + with open("/tmp/wal/colors.sh") as file: + content = file.read().splitlines() + + self.assertEqual(content[6], "foreground='#F5F1F4'") def test_css_template(self): """> Test substitutions in template file (css).""" - export.color(COLORS, "css", OUTPUT_DIR / "test.css") + export.color(COLORS, "css", "/tmp/wal/test.css") - result = pathlib.Path("/tmp/wal/test.css").is_file() + result = os.path.isfile("/tmp/wal/test.css") self.assertTrue(result) - content = pathlib.Path("/tmp/wal/test.css").read_text() - content = content.split("\n")[6] - self.assertEqual(content, " --background: #1F211E;") + with open("/tmp/wal/test.css") as file: + content = file.read().splitlines() + + self.assertEqual(content[6], " --background: #1F211E;") def test_invalid_template(self): """> Test template validation.""" @@ -48,7 +49,7 @@ class TestExportColors(unittest.TestCase): # Since this function prints a message on fail we redirect # it's output so that we can read it. with unittest.mock.patch('sys.stdout', new=io.StringIO()) as fake_out: - export.color(COLORS, "dummy", OUTPUT_DIR / "test.css") + export.color(COLORS, "dummy", "/tmp/wal/test.css") self.assertEqual(fake_out.getvalue().strip(), error_msg) diff --git a/tests/test_main.py b/tests/test_main.py index 7f1a1bb..daf9cab 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -16,7 +16,8 @@ class TestMain(unittest.TestCase): """> Test arg parsing (-c)""" args = __main__.get_args(["-c"]) __main__.process_args(args) - self.assertFalse(os.path.isdir(str(CACHE_DIR / "schemes"))) + scheme_dir = os.path.join(CACHE_DIR, "schemes") + self.assertFalse(os.path.isdir(scheme_dir)) def test_args_e(self): """> Test arg parsing (-e)""" -- cgit v1.2.3 From c61960722d28373a4668814d996a248819e220c0 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 10 Aug 2017 09:23:50 +1000 Subject: general: Remove all pathlib usage --- tests/test_util.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_util.py b/tests/test_util.py index aae0356..79b6b96 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,7 +1,6 @@ """Test util functions.""" import unittest import os -import pathlib from pywal import util @@ -35,16 +34,16 @@ class TestUtil(unittest.TestCase): def test_save_file(self): """> Save colors to a file.""" - tmp_file = pathlib.Path("/tmp/test_file") + tmp_file = "/tmp/test_file" util.save_file("Hello, world", tmp_file) - result = tmp_file.is_file() + result = os.path.isfile(tmp_file) self.assertTrue(result) def test_save_file_json(self): """> Save colors to a file.""" - tmp_file = pathlib.Path("/tmp/test_file.json") + tmp_file = "/tmp/test_file.json" util.save_file_json(COLORS, tmp_file) - result = tmp_file.is_file() + result = os.path.isfile(tmp_file) self.assertTrue(result) def test_create_dir(self): -- cgit v1.2.3 From c743cab4f0b74e928496c2a5052906da52acc8f7 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 12 Aug 2017 12:21:22 +1000 Subject: tests: Add a test for sequence order. --- tests/test_sequences.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/test_sequences.py b/tests/test_sequences.py index 7a21c11..8034da7 100755 --- a/tests/test_sequences.py +++ b/tests/test_sequences.py @@ -34,6 +34,13 @@ class Testsequences(unittest.TestCase): result = sequences.set_iterm_tab_color(COLORS["special"]["background"]) self.assertEqual(len(result), 104) + def test_sequence_order(self): + """> Test that the sequences are in order.""" + result = sequences.create_sequences(COLORS, vte=False).split("\007") + self.assertEqual(result[2], "\x1b]4;2;#CC6A93") + self.assertEqual(result[15], "\x1b]4;15;#F5F1F4") + self.assertEqual(result[8], "\x1b]4;8;#666666") + if __name__ == "__main__": unittest.main() -- cgit v1.2.3