Skip to content

Commit

Permalink
🧪 Allow glob patterns in retrieve_temporary input
Browse files Browse the repository at this point in the history
The `generate_calc_job_node` fixture has a `retrieve_temporary` input that allows the
user to specify a list of files in the fixture test folder that should be copied to
the temporary retrieved folder (as defined by the `_retrieve_temporary_list` class
attribute in the corresponding calculation job). Here we extend this functionality to
allow the user to specify glob patterns in the `retrieve_temporary` input.

Second, we also adapt the code to use the `pathlib` module for handling paths. While
doing so, we also revert a change in 0874d95 that
introduced a try-except to handle the case where the XML is not in the fixture test
folder. This is no longer necessary, because the `glob` call will only return files that
are actually present in the fixture test folder.
  • Loading branch information
mbercx committed Jan 24, 2025
1 parent c84ef21 commit ac99984
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import os
import pathlib
from pathlib import Path
import shutil
import tempfile

Expand Down Expand Up @@ -287,23 +288,22 @@ def _generate_calc_job_node(

if retrieve_temporary:
dirpath, filenames = retrieve_temporary
dirpath = Path(dirpath)
filepaths = []
for filename in filenames:
try:
shutil.copy(os.path.join(filepath_folder, filename), os.path.join(dirpath, filename))
except FileNotFoundError:
pass # To test the absence of files in the retrieve_temporary folder
filepaths.extend(Path(filepath_folder).glob(filename))

for filepath in filepaths:
shutil.copy(filepath, dirpath / filepath.name)

if filepath_folder:
retrieved = orm.FolderData()
retrieved.base.repository.put_object_from_tree(filepath_folder)

# Remove files that are supposed to be only present in the retrieved temporary folder
if retrieve_temporary:
for filename in filenames:
try:
retrieved.base.repository.delete_object(filename)
except OSError:
pass # To test the absence of files in the retrieve_temporary folder
for filepath in filepaths:
retrieved.delete_object(filepath.name)

retrieved.base.links.add_incoming(node, link_type=LinkType.CREATE, link_label='retrieved')
retrieved.store()
Expand Down

0 comments on commit ac99984

Please sign in to comment.