Skip to content

Commit

Permalink
Merge pull request #88 from lisc-tools/paths
Browse files Browse the repository at this point in the history
[MNT] - Update check_directory to handle path inputs
  • Loading branch information
TomDonoghue authored Aug 28, 2023
2 parents a6089da + 2357bbf commit 1255f14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lisc/tests/utils/test_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for lisc.core.db"""

from pathlib import Path

from lisc.utils.db import *

###################################################################################################
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 8 additions & 6 deletions lisc/utils/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Database structure object for LISC."""

import os
from pathlib import Path

###################################################################################################
###################################################################################################
Expand Down Expand Up @@ -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
Expand All @@ -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 = ''
Expand Down

0 comments on commit 1255f14

Please sign in to comment.