diff --git a/pywal/image.py b/pywal/image.py index e01c3d1..bb495b1 100644 --- a/pywal/image.py +++ b/pywal/image.py @@ -16,7 +16,7 @@ def get_random_image(img_dir): current_wall = os.path.basename(current_wall) file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif") - images = [img for img in os.scandir(str(img_dir)) + images = [img for img in os.scandir(img_dir) if img.name.endswith(file_types) and img.name != current_wall] if not images: diff --git a/pywal/util.py b/pywal/util.py index 832ac5f..55be6c2 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -35,14 +35,14 @@ class Color: def read_file(input_file): """Read data from a file and trim newlines.""" - with open(str(input_file), "r") as file: + with open(input_file, "r") as file: data = file.read().splitlines() return data def read_file_json(input_file): """Read data from a json file.""" - with open(str(input_file), "r") as json_file: + with open(input_file, "r") as json_file: data = json.load(json_file) return data @@ -51,17 +51,17 @@ def read_file_json(input_file): def read_file_raw(input_file): """Read data from a file as is, don't strip newlines or other special characters..""" - with open(str(input_file), "r") as file: + with open(input_file, "r") as file: data = file.readlines() return data def save_file(data, export_file): """Write data to a file.""" - create_dir(os.path.dirname(str(export_file))) + create_dir(os.path.dirname(export_file)) try: - with open(str(export_file), "w") as file: + with open(export_file, "w") as file: file.write(data) except PermissionError: print("warning: Couldn't write to %s." % export_file) @@ -69,9 +69,9 @@ def save_file(data, export_file): def save_file_json(data, export_file): """Write data to a json file.""" - create_dir(os.path.dirname(str(export_file))) + create_dir(os.path.dirname(export_file)) - with open(str(export_file), "w") as file: + with open(export_file, "w") as file: json.dump(data, file, indent=4) 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):