Skip to content
Snippets Groups Projects
Select Git revision
  • 876d7cea80ee8217c5d60dc0cdef3160c7043eb3
  • main default protected
  • dev
  • f-spss-value-label-name
  • f-unmod
  • f-checkidentical
  • f-simple-breakpoint
  • f-new-debug-tree
  • f-existing-file-id
  • f-no-ident
  • f-collect-problems
  • f-refactor-debug-tree
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.1
  • v0.10.0
  • v0.9.1
  • v0.9.0
  • v0.8.0
  • v0.7.1
  • v0.7.0
  • v0.6.0
  • v0.5.0
  • v0.4.0
  • v0.3.0
  • v0.2.0
  • v0.1.0
28 results

test_variable_substitutions.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_variable_substitutions.py 2.03 KiB
    #!/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(element_type, *pathcomponents):
        """
        Return the debug tree identifier for a given path.
        """
        return "newcrawler.structure_elements." + element_type + ": " + 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):
        for i in range(2):
            subd = crawler.debug_tree[dircheckstr("File", "ExperimentalData", "220512_data.dat")]
            assert subd[i]["Experiment"].get_property("date").value == "2022-05-12"
            assert isinstance(subd[i]["ExperimentSeries"].get_property("Experiment").value, db.Record)
    
            subd = crawler.debug_tree[dircheckstr("Directory", "ExperimentalData")]
            assert subd[i]["Project"].name == "project"
            assert isinstance(subd[i]["Project"].get_property("Experiments").value, list)
            assert isinstance(subd[i]["Project"].get_property("Experiments").value[0], db.Record)
    
            assert isinstance(subd[i]["Project"].get_property("dates").value, list)
            assert subd[i]["Project"].get_property("dates").value[0] == "2022-05-12"