From 4ad9f79db2cdb45d5899b84a27d75f1ebe23a6d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:16:00 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- brainglobe_utils/general/list.py | 2 ++ brainglobe_utils/general/system.py | 3 ++- tests/tests/test_general/test_list.py | 6 ++++-- tests/tests/test_general/test_system.py | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/brainglobe_utils/general/list.py b/brainglobe_utils/general/list.py index a2faaa7..60b9a6e 100644 --- a/brainglobe_utils/general/list.py +++ b/brainglobe_utils/general/list.py @@ -1,5 +1,6 @@ from natsort import natsorted + def remove_empty_string(str_list): """ Removes any empty strings from a list of strings @@ -13,6 +14,7 @@ def unique_elements_lists(list_in): """return the unique elements in a list""" return list(dict.fromkeys(list_in)) + def check_unique_list(in_list, natural_sort=True): """ Checks if all the items in a list are unique or not diff --git a/brainglobe_utils/general/system.py b/brainglobe_utils/general/system.py index e2fea8c..2684818 100644 --- a/brainglobe_utils/general/system.py +++ b/brainglobe_utils/general/system.py @@ -12,8 +12,8 @@ from slurmio import slurmio from tqdm import tqdm -from brainglobe_utils.general.string import get_text_lines from brainglobe_utils.general.exceptions import CommandLineInputError +from brainglobe_utils.general.string import get_text_lines # On Windows, max_workers must be less than or equal to 61 # https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor @@ -351,6 +351,7 @@ def delete_directory_contents(directory, progress=False): for f in files: os.remove(os.path.join(directory, f)) + def check_path_exists(file): """ Returns True is a file exists, otherwise throws a FileNotFoundError diff --git a/tests/tests/test_general/test_list.py b/tests/tests/test_general/test_list.py index 3dad0ac..6572560 100644 --- a/tests/tests/test_general/test_list.py +++ b/tests/tests/test_general/test_list.py @@ -1,4 +1,5 @@ from brainglobe_utils.general import list as list_tools + a = [1, "a", 10, 30] b = [30, 10, "c", "d"] @@ -7,7 +8,6 @@ list_without_empty = ["test1", "test 2", " ", "test4"] - def test_remove_empty_string(): assert ( list_tools.remove_empty_string(list_with_empty) == list_without_empty @@ -19,11 +19,13 @@ def test_unique_elements_list(): unique_list = [1, 2, "a", "b", "dog"] assert list_tools.unique_elements_lists(list_in) == unique_list + def test_check_unique_list(): a = [1, "a", 10, 30] assert (True, []) == list_tools.check_unique_list(a) repeating_list = [1, 2, 3, 3, "dog", "cat", "dog"] assert (False, [3, "dog"]) == list_tools.check_unique_list(repeating_list) + def test_common_member(): - assert (True, [10, 30]) == list_tools.common_member(a, b) \ No newline at end of file + assert (True, [10, 30]) == list_tools.common_member(a, b) diff --git a/tests/tests/test_general/test_system.py b/tests/tests/test_general/test_system.py index 77909e4..c59036f 100644 --- a/tests/tests/test_general/test_system.py +++ b/tests/tests/test_general/test_system.py @@ -8,8 +8,8 @@ import pytest from brainglobe_utils.general import system -from brainglobe_utils.general.string import get_text_lines from brainglobe_utils.general.exceptions import CommandLineInputError +from brainglobe_utils.general.string import get_text_lines data_dir = Path("tests", "data") cubes_dir = data_dir / "cubes" @@ -328,10 +328,12 @@ def test_delete_directory_contents(tmp_path): system.delete_directory_contents(delete_dir, progress=False) assert os.listdir(delete_dir) == [] + def write_file_single_size(directory, file_size): with open(os.path.join(directory, str(file_size)), "wb") as fout: fout.write(os.urandom(file_size)) + def test_check_path_exists(tmpdir): num = 10 tmpdir = str(tmpdir)