Skip to content
Snippets Groups Projects
Select Git revision
  • f71d820edf3b46b009e87269524c69298370c239
  • main default protected
  • dev
  • 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
27 results

test_scalars_cfood.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