Skip to content
Snippets Groups Projects
Select Git revision
  • 4c64a8da9d0bca78469ef4824a74537c070326ed
  • 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.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test.py 3.25 KiB
    #!/usr/bin/env python3
    # encoding: utf-8
    #
    # ** header v3.0
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2021 Indiscale GmbH <info@indiscale.com>
    #               2021 Henrik tom Wörden <h.tomwoerden@indiscale.com>
    #               2021 Alexander Schlemmer
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <https://www.gnu.org/licenses/>.
    #
    # ** end header
    #
    
    """
    module description
    """
    
    import argparse
    import sys
    from argparse import RawTextHelpFormatter
    from newcrawler import Crawler
    from unittest.mock import Mock
    import caosdb as db
    from newcrawler.identifiable_adapters import CaosDBIdentifiableAdapter
    
    import os
    
    
    def rfp(*pathcomponents):
        """
        Return full path.
        Shorthand convenience function.
        """
        return os.path.join(os.path.dirname(__file__), *pathcomponents)
    
    
    def main(args):
        ident_adapt = CaosDBIdentifiableAdapter()
        # TODO place this definition of identifiables elsewhere
        ident_adapt.register_identifiable(
            "Person", db.RecordType()
            .add_parent(name="Person")
            #.add_property(name="first_name")
            .add_property(name="last_name"))
        ident_adapt.register_identifiable(
            "Measurement", db.RecordType()
            .add_parent(name="Measurement")
            #.add_property(name="identifier")
            .add_property(name="date")
            .add_property(name="project"))
        ident_adapt.register_identifiable(
            "Project", db.RecordType()
            .add_parent(name="Project")
            .add_property(name="date")
            .add_property(name="identifier"))
    
        crawler = Crawler(debug=True, identifiableAdapter=ident_adapt)
        crawler.copy_attributes = Mock()
        crawler.crawl_directory(rfp("../unittests/test_directories", "examples_article"),
                                rfp("../unittests/scifolder_cfood.yml"))
        ins, ups = crawler.synchronize()
        assert len(ins) == 18
        assert len(ups) == 0
    
        # Do a second run on the same data, there should be no changes:
        crawler = Crawler(debug=True, identifiableAdapter=ident_adapt)
        crawler.copy_attributes = Mock()
        crawler.crawl_directory(rfp("../unittests/test_directories", "examples_article"),
                                rfp("../unittests/scifolder_cfood.yml"))
        ins, ups = crawler.synchronize()
        assert len(ins) == 0
        assert len(ups) == 0
    
    
    def parse_args():
        parser = argparse.ArgumentParser(description=__doc__,
                                         formatter_class=RawTextHelpFormatter)
        # parser.add_argument("path",
        #                    help="the subtree of files below the given path will "
        #                    "be considered. Use '/' for everything.")
    
        return parser.parse_args()
    
    
    if __name__ == "__main__":
        args = parse_args()
        sys.exit(main(args))