diff --git a/unittests/test_directories/example_substitutions/ExperimentalData/220512_data.dat b/unittests/test_directories/example_substitutions/ExperimentalData/220512_data.dat new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/unittests/test_directories/example_substitutions/substitutions.yml b/unittests/test_directories/example_substitutions/substitutions.yml new file mode 100644 index 0000000000000000000000000000000000000000..9bb5f1639791579099694025005a557cd74084bb --- /dev/null +++ b/unittests/test_directories/example_substitutions/substitutions.yml @@ -0,0 +1,12 @@ + +ExperimentalData: # name of the converter + type: Directory + match: ExperimentalData + subtree: + File: # name of the converter + type: SimpleFile + match: (?P<year>[0-9]{2,2})(?P<month>[0-9]{2,2})(?P<day>[0-9]{2,2})_data.dat + records: + Experiment: + date: 20$year-$month-$day + diff --git a/unittests/test_variable_substitutions.py b/unittests/test_variable_substitutions.py new file mode 100644 index 0000000000000000000000000000000000000000..14067b4cf2c1b28201328674c258e8a5dd0fa4f2 --- /dev/null +++ b/unittests/test_variable_substitutions.py @@ -0,0 +1,44 @@ +#!/bin/python +# Tests for variable substitutions +# A. Schlemmer, 05/2022 + +from newcrawler import Crawler +from newcrawler.structure_elements import File, DictTextElement, DictListElement +from newcrawler.identifiable_adapters import IdentifiableAdapter, LocalStorageIdentifiableAdapter +from functools import partial +from copy import deepcopy +from unittest.mock import MagicMock, Mock +from os.path import join, dirname, basename +import yaml +import caosdb as db +from caosdb.apiutils import compare_entities + +import pytest +from pytest import raises + + +def rfp(*pathcomponents): + """ + Return full path. + Shorthand convenience function. + """ + return join(dirname(__file__), *pathcomponents) + +def dircheckstr(*pathcomponents): + """ + Return the debug tree identifier for a given path. + """ + return "newcrawler.structure_elements.Directory: " + basename(join(*pathcomponents)) + ", " + rfp("test_directories", "example_substitutions", *pathcomponents) + + +@pytest.fixture +def crawler(): + crawler = Crawler(debug=True) + crawler.crawl_directory(rfp("test_directories", "example_substitutions", "ExperimentalData"), + rfp("test_directories", "example_substitutions", "substitutions.yml")) + return crawler + + +def test_substitutions(crawler): + subd = crawler.debug_tree[dircheckstr("ExperimentalData")] + breakpoint()