mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Python] List data files from subdirectories
This commit is contained in:
parent
9ec376ec06
commit
0c5fa1b201
@ -7,19 +7,19 @@ from ._utils import get_data_directories, add_directory
|
|||||||
|
|
||||||
def list_data_files(ext=".yaml"):
|
def list_data_files(ext=".yaml"):
|
||||||
"""
|
"""
|
||||||
Lists input data files.
|
Lists input data files. Includes files in subdirectories, except for subdirectories
|
||||||
|
of the current working directory.
|
||||||
|
|
||||||
:param ext:
|
:param ext:
|
||||||
Extension of files to be displayed.
|
Extension of files to be displayed.
|
||||||
:return:
|
:return:
|
||||||
List of input data files.
|
List of input data files.
|
||||||
"""
|
"""
|
||||||
data_files = []
|
data_files = set()
|
||||||
for folder in get_data_directories():
|
for folder in get_data_directories():
|
||||||
here = Path(folder)
|
here = Path(folder)
|
||||||
if here.is_dir():
|
if folder == ".":
|
||||||
files = [x.name for x in here.iterdir() if x.name.endswith(ext)]
|
data_files.update(f.name for f in here.glob(f"*{ext}"))
|
||||||
data_files.extend(files)
|
elif here.is_dir():
|
||||||
data_files = list(set(data_files))
|
data_files.update(str(f.relative_to(here)) for f in here.glob(f"**/*{ext}"))
|
||||||
data_files.sort()
|
return sorted(data_files)
|
||||||
return data_files
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from pathlib import Path
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
from pytest import approx
|
from pytest import approx
|
||||||
@ -322,3 +323,8 @@ class TestAnyMap(utilities.CanteraTest):
|
|||||||
outer.set_activation_energy('cheese', 12, 'V/m')
|
outer.set_activation_energy('cheese', 12, 'V/m')
|
||||||
with pytest.raises(ct.CanteraError):
|
with pytest.raises(ct.CanteraError):
|
||||||
_py_to_anymap_to_py(outer)
|
_py_to_anymap_to_py(outer)
|
||||||
|
|
||||||
|
def test_list_data_files():
|
||||||
|
data_files = ct.list_data_files()
|
||||||
|
assert "gri30.yaml" in data_files
|
||||||
|
assert str(Path("example_data/oxygen-plasma-itikawa.yaml")) in data_files
|
||||||
|
Loading…
Reference in New Issue
Block a user