Skip to content
Snippets Groups Projects
Select Git revision
  • 5b04b6d874610f8ada4edc2107e7dc1b38ac9083
  • main default protected
  • dev
  • f-docs-pylib
  • f-parse-value
  • f-compare
  • f-string-ids
  • f-217-set-special-property
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-check-merge-entities
  • f-compare-enid
  • f-select-subproperties
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • linkahead-rename-step-2
  • linkahead-rename-step-1
  • v0.12.0
  • v0.11.2
  • v0.11.1
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.4
  • v0.7.3
36 results

test_query.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_scalars_cfood.py 1.92 KiB
    #!/bin/python
    # Tests for:
    # https://gitlab.com/caosdb/caosdb-crawler/-/issues/9
    # A. Schlemmer, 06/2021
    
    import pytest
    
    # The main function that is affected by this issue:
    from caoscrawler.converters import handle_value
    from caoscrawler.crawl import Crawler
    # We need the store for the above function
    from caoscrawler.stores import GeneralStore
    
    from test_tool import dircheckstr, rfp
    
    
    @pytest.fixture
    def crawler():
        crawler = Crawler(debug=True)
        crawler.crawl_directory(rfp("test_directories", "examples_article"),
                                rfp("cfoods_scalar.yml"))
        return crawler
    
    
    def test_handle_value():
        # Note that we will need this store only, if we also want to test variables substitution:
        store = GeneralStore()
    
        # This one should work:
        assert handle_value("bla", store) == ("bla", "single")
    
        # These failed:
        assert handle_value(4, store) == (4, "single")
        assert handle_value(4.2, store) == (4.2, "single")
        assert handle_value(True, store) == (True, "single")
    
        # List test:
        assert handle_value([4, 3, 2], store) == ([4, 3, 2], "single")
    
    
    def test_record_structure_generation(crawler):
        subd = crawler.debug_tree[dircheckstr("DataAnalysis")]
        assert len(subd) == 2
        # variables store on Data Analysis node of debug tree
        if "Data" in subd[0]:
            subddata = subd[0]
            subdRTGPL = subd[1]
        else:
            subddata = subd[1]
            subdRTGPL = subd[0]
        assert len(subddata) == 5
        assert "DataAnalysis" in subddata
        assert "DataAnalysis.path" in subddata
        assert "Data.path" in subddata
        assert "RecordThatGetsParentsLater" in subddata
    
        prop = subddata["RecordThatGetsParentsLater"].get_property("someId")
        assert type(prop.value) == int
        assert prop.value == 23
    
        # record store on Data Analysis node of debug tree
        assert len(subdRTGPL) == 1
        prop2 = subdRTGPL["RecordThatGetsParentsLater"].get_property("someId")
        assert prop == prop2