Skip to content
Snippets Groups Projects
Commit d3e313d5 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

MAINT: cleaned up test directory

parent 3f7dd02b
No related branches found
No related tags found
1 merge request!53Release 0.1
experiment-directory:
type: directory #type defines that certain values are set; e.g. dir name
match: ".*"
recordtypes:
Experiment:
properties:
date: $date #in order to set property values, keys from this dict can be used
super: something.$date
valuegenerators:
- datepattern:
regexp: "8\d"
key: date #the value is stored under the key in the dict of this level
childrengenerators:
create_children_from_directory
subtree:
readme-file:
match: "README.md"
type: file
recordtypes:
Experiment:
properties:
responsible: responsible
valuegenerators:
- jsonloader:
regexp: "8\d"
value: date
#!/usr/bin/env python3
# encoding: utf-8
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Henrik tom Wörden
#
# 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
#
"""
This file tests the behavoir of the crawler using small definitions and yml
structures.
Dictionaries in the yaml are StructureElements. Key value pairs of the
dictionary are transfered to the value dict of the StructureElement.
"""
import unittest
class BasicExperimentTest(unittest.TestCase):
# def setUp(self):
def test_single(self):
# There is one dictionary, that is treated entirely as an experiment
structure = """
stuff: 5
"""
definition = """
experiment:
type: dictionary
match: always
recordtypes:
Experiment:
properties:
stuff: $stuff """
result = crawl() # dummy line
# 1 record
assert len(result) == 1
# only parent is experiment
assert len(result[0].parents) == 1
self.assertEqual(result[0].parents, "Experiment")
# name is set correctly
self.assertEqual(result[0].name, "cool-exp")
def test_multiple(self):
# multiple dicts that each shall represent an experiment
structure = """
cool-exp:
stuff: 5
second-exp:
another-exp:
stuff: 5
"""
# The outermost dictionary does not represent an entity. Therefore we
# need an additional level that creates child-nodes for each
# experiment.
definition = """
toplevel:
type: dictionary
match: ".*"
subtree:
experiment:
type: dictionary
match: ".*"
recordtypes:
Experiment:
properties:
name: $name
stuff: $stuff """
result = crawl() # dummy line
# 1 record
assert len(result) == 3
for r in result:
# only parent is experiment
assert len(r.parents) == 1
self.assertEqual(r.parents, "Experiment")
# names are set correctly
self.assertTrue(
r.name in ["cool-exp", "second-exp", "another-exp"])
# second-exp shall not have a value for stuff
if r.name == "second-exp":
self.assertEqual(r.get_property("stuff"), None)
def test_three_level(self):
# multiple dicts that each shall represent an experiment
structure = """
inter1:
cool-exp:
stuff: 5
inter2:
second-exp:
another-exp:
stuff: 5
"""
# The two outermost dictionaries do not represent an entity. We want to
# use the names of the intermediate levels in the Records.
definition = """
toplevel:
type: dictionary
match: ".*"
subtree:
interlevel:
type: dictionary
match: ".*"
subtree:
experiment:
type: dictionary
match: ".*"
recordtypes:
Experiment:
properties:
name: $name
intermediate: $interlevel.name
stuff: $stuff """
result = crawl() # dummy line
# 1 record
assert len(result) == 3
for r in result:
# only parent is experiment
assert len(r.parents) == 1
self.assertEqual(r.parents, "Experiment")
# names are set correctly
self.assertTrue(
r.name in ["cool-exp", "second-exp", "another-exp"])
# second-exp shall not have a value for stuff
if r.name == "second-exp":
self.assertEqual(r.get_property("stuff"), None)
def test_three_level(self):
definition = """
experiment:
type: dictionary
match: ".*"
recordtypes:
Experiment:
properties:
name: $date #in order to set property values, keys from this dict can be used
valuegenerators:
childrengenerators:
create_children_from_dictionaries
subtree:
"""
definition = """
toplevel:
type: dictionary
match: ".*"
subtree:
experiment:
type: dictionary
match: ".*"
recordtypes:
Experiment:
properties:
stuff: $stuff
valuegenerators:
childrengenerators:
subtree: """
#!/bin/python
# Tests for main functions of crawler
# A. Schlemmer, 07/2021
#from newcrawler import match_complete
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment