diff --git a/lisc/tests/utils/test_db.py b/lisc/tests/utils/test_db.py index 5f94ef0..aa80755 100755 --- a/lisc/tests/utils/test_db.py +++ b/lisc/tests/utils/test_db.py @@ -1,5 +1,7 @@ """Tests for lisc.core.db""" +from pathlib import Path + from lisc.utils.db import * ################################################################################################### @@ -76,8 +78,9 @@ def test_scdb_check_file_structure(tdb): def test_check_directory(): - assert check_directory(None, '') == '' - assert check_directory('string', '') == 'string' + assert check_directory(None) == '' + assert check_directory('/path/to/file') == '/path/to/file' + assert check_directory(Path('path/to/file')) == Path('path/to/file') assert isinstance(check_directory(SCDB(), 'terms'), str) def test_check_file_structure(tdb): diff --git a/lisc/utils/db.py b/lisc/utils/db.py index 2b776a7..e88a6fe 100644 --- a/lisc/utils/db.py +++ b/lisc/utils/db.py @@ -1,6 +1,7 @@ """Database structure object for LISC.""" import os +from pathlib import Path ################################################################################################### ################################################################################################### @@ -204,19 +205,20 @@ def check_file_structure(self): ################################################################################################### ################################################################################################### -def check_directory(directory, folder): +def check_directory(directory, folder=None): """Check and extract a file path. Parameters ---------- - directory : SCDB or str or None + directory : SCDB or str or Path or None A string or object containing a file path. - folder : str - Which folder path to extract, if it's a SCDB object. + folder : str, optional + Which folder path to extract. + Only used if `directory` is a SCDB object. Returns ------- - path : str + path : str or Path File path for the desired folder. Notes @@ -230,7 +232,7 @@ def check_directory(directory, folder): if isinstance(directory, SCDB): path = directory.get_folder_path(folder) - elif isinstance(directory, str): + elif isinstance(directory, (str, Path)): path = directory elif directory is None: path = ''