From 0e6a43dc9a62da243bcde0101b1743da4c8a12ed Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <alexander@mail-schlemmer.de> Date: Tue, 7 Dec 2021 09:50:08 +0100 Subject: [PATCH] TST: updated test file records xml and corresponding unit test --- unittests/records.xml | 350 ++++++++++++++++++----------------------- unittests/test_tool.py | 95 ++++++----- 2 files changed, 211 insertions(+), 234 deletions(-) diff --git a/unittests/records.xml b/unittests/records.xml index 1dcbd636..635f22bb 100644 --- a/unittests/records.xml +++ b/unittests/records.xml @@ -1,210 +1,168 @@ <Entities> - <Record id="-1"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorA</Property> - </Record> - <Record id="-2"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-01-04</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">average-all-exp</Property> - <Property name="project" importance="FIX" flag="inheritance:FIX">-5</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-1</Value> + <Record id="109"> + <Version id="f83969a8655440054a322e9d371bce728c030f40" head="true"/> + <Parent id="100" name="Person"/> + <Property id="101" name="first_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="102" name="last_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX">AuthorA</Property> + </Record> + <Record id="110"> + <Version id="698791344c26b48101c23a2c07746a79039c8266" head="true"/> + <Parent id="103" name="Project"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">SpeedOfLight</Property> + </Record> + <Record id="111"> + <Version id="7a52266b776ad26c471e21ed05d0d2e397526d27" head="true"/> + <Parent id="100" name="Person"/> + <Property id="101" name="first_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="102" name="last_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX">AuthorD</Property> + </Record> + <Record id="112"> + <Version id="7753ede1808e20fc958f0a113dd1ec3fef7fca13" head="true"/> + <Parent id="103" name="Project"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">climate-model-predict</Property> + </Record> + <Record id="113"> + <Version id="3a49980c61ad722f3e827cf822bc37d9246cfe54" head="true"/> + <Parent id="100" name="Person"/> + <Property id="101" name="first_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="102" name="last_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX">AuthorB</Property> + </Record> + <Record id="114"> + <Version id="f59a362efab99d729c7365af27447579ff676b1a" head="true"/> + <Parent id="100" name="Person"/> + <Property id="101" name="first_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="102" name="last_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX">AuthorC</Property> + </Record> + <Record id="115"> + <Version id="a4137cf9d2c48991aa51abba59dffdabfeb366d7" head="true"/> + <Parent id="100" name="Person"/> + <Property id="101" name="first_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="102" name="last_name" datatype="TEXT" importance="FIX" flag="inheritance:FIX">AuthorE</Property> + </Record> + <Record id="116"> + <Version id="790f5e3b165816448cd7221f1170f91781da9d25" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-01-04</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">average-all-exp</Property> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">110</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>109</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Average over all data of each type of experiment separately and comined.</Property> - </Record> - <Record id="-3"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorA</Property> - </Record> - <Record id="-4"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-01-05</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">average-all-exp-corr</Property> - <Property name="project" importance="FIX" flag="inheritance:FIX">-5</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-3</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Average over all data of each type of experiment separately and comined.</Property> + </Record> + <Record id="118"> + <Version id="520e3e1ab113002c26051652e169f4e2c3273cea" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-01-05</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">average-all-exp-corr</Property> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">110</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>109</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Average over all data of each type of experiment separately and comined.</Property> - </Record> - <Record id="-5"> - <Parent name="Project"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">SpeedOfLight</Property> - </Record> - <Record id="-6"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorD</Property> - </Record> - <Record id="-7"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-02-08</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">prediction-errors</Property> - <Property name="project" importance="FIX" flag="inheritance:FIX">-8</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-6</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Average over all data of each type of experiment separately and comined.</Property> + </Record> + <Record id="119"> + <Version id="3383403dc3080d1b566b3b39063d61c110260cb0" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-02-08</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">prediction-errors</Property> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">112</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>111</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">comparison between predicted and measured temperatures for 2010 to 2019</Property> - </Record> - <Record id="-8"> - <Parent name="Project"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">climate-model-predict</Property> - </Record> - <Record id="-9"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorA</Property> - </Record> - <Record id="-10"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorB</Property> - </Record> - <Record id="-11"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-01-01</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">TimeOfFlight</Property> - <Property name="project" importance="FIX" flag="inheritance:FIX">-18</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-9</Value> - <Value>-10</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">comparison between predicted and measured temperatures for 2010 to 2019</Property> + </Record> + <Record id="120"> + <Version id="5da5ef24abcdec5be0f24fb9977f4c574d463768" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-01-01</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">TimeOfFlight</Property> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">110</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>109</Value> + <Value>113</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Time-of-flight measurements to determine the speed of light</Property> - </Record> - <Record id="-12"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorA</Property> - </Record> - <Record id="-13"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorC</Property> - </Record> - <Record id="-14"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-01-02</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">Cavity</Property> - <Property name="project" importance="FIX" flag="inheritance:FIX">-18</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-12</Value> - <Value>-13</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Time-of-flight measurements to determine the speed of light</Property> + </Record> + <Record id="121"> + <Version id="7efa963b3663818aee4f9438cbbe26f8565af1e9" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-01-02</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX">Cavity</Property> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">110</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>109</Value> + <Value>114</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Cavity resonance measurements for determining the speed of light</Property> - </Record> - <Record id="-15"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorA</Property> - </Record> - <Record id="-16"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorB</Property> - </Record> - <Record id="-17"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-01-03</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX"/> - <Property name="project" importance="FIX" flag="inheritance:FIX">-18</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-15</Value> - <Value>-16</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Cavity resonance measurements for determining the speed of light</Property> + </Record> + <Record id="122"> + <Version id="244cda0358bc6937ee0944a86a0e0580c7b41781" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-01-03</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">110</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>109</Value> + <Value>113</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Radio interferometry measurements to determine the speed of light</Property> - </Record> - <Record id="-18"> - <Parent name="Project"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">SpeedOfLight</Property> - </Record> - <Record id="-19"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorD</Property> - </Record> - <Record id="-20"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">1980-01-01</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX"/> - <Property name="project" importance="FIX" flag="inheritance:FIX">-27</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-19</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Radio interferometry measurements to determine the speed of light</Property> + </Record> + <Record id="123"> + <Version id="656558b1a926824b98a733c1fdd9d0444c75745f" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">1980-01-01</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">112</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>111</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 1980-1989 as obtained from wheatherdata.example</Property> - </Record> - <Record id="-21"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorD</Property> - </Record> - <Record id="-22"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">1990-01-01</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX"/> - <Property name="project" importance="FIX" flag="inheritance:FIX">-27</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-21</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 1980-1989 as obtained from wheatherdata.example</Property> + </Record> + <Record id="124"> + <Version id="971900b83171b89787aa26a0a7b543d096ee1ebc" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">1990-01-01</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">112</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>111</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 1990-1999 as obtained from wheatherdata.example</Property> - </Record> - <Record id="-23"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorD</Property> - </Record> - <Record id="-24"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2000-01-01</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX"/> - <Property name="project" importance="FIX" flag="inheritance:FIX">-27</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-23</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 1990-1999 as obtained from wheatherdata.example</Property> + </Record> + <Record id="125"> + <Version id="deeb78862ae1ccdc831532e51bd225976af67807" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2000-01-01</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">112</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>111</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 2000-2009 as obtained from wheatherdata.example</Property> - </Record> - <Record id="-25"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorD</Property> - </Record> - <Record id="-26"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2010-01-01</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX"/> - <Property name="project" importance="FIX" flag="inheritance:FIX">-27</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-25</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 2000-2009 as obtained from wheatherdata.example</Property> + </Record> + <Record id="126"> + <Version id="133832dd2b528ab4a83a189dc8fca9d1d7c541fa" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2010-01-01</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">112</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>111</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 2010-2019 as obtained from wheatherdata.example</Property> - </Record> - <Record id="-27"> - <Parent name="Project"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">climate-model-predict</Property> - </Record> - <Record id="-28"> - <Parent name="Person"/> - <Property name="first_name" importance="FIX" flag="inheritance:FIX"/> - <Property name="last_name" importance="FIX" flag="inheritance:FIX">AuthorE</Property> - </Record> - <Record id="-29"> - <Parent name="Measurement"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020-02-01</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX"/> - <Property name="project" importance="FIX" flag="inheritance:FIX">-30</Property> - <Property name="responsible" importance="FIX" flag="inheritance:FIX"> - <Value>-28</Value> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Average temperatures of the years 2010-2019 as obtained from wheatherdata.example</Property> + </Record> + <Record id="127"> + <Version id="865aebd7662341f8582b4f0b32bd96fd986eb815" head="true"/> + <Parent id="106" name="Measurement"/> + <Property id="104" name="date" datatype="DATETIME" importance="FIX" flag="inheritance:FIX">2020-02-01</Property> + <Property id="105" name="identifier" datatype="TEXT" importance="FIX" flag="inheritance:FIX"/> + <Property id="103" name="project" datatype="Project" importance="FIX" flag="inheritance:FIX">112</Property> + <Property id="107" name="responsible" datatype="LIST<Person>" importance="FIX" flag="inheritance:FIX"> + <Value>115</Value> </Property> - <Property name="description" importance="FIX" flag="inheritance:FIX">Code for fitting the predictive model to the training data and for predicting the average annual temperature for all measurement stations for the years 2010 to 2019</Property> - </Record> - <Record id="-30"> - <Parent name="Project"/> - <Property name="date" importance="FIX" flag="inheritance:FIX">2020</Property> - <Property name="identifier" importance="FIX" flag="inheritance:FIX">climate-model-predict</Property> + <Property id="24" name="description" description="Description of an entity." datatype="TEXT" importance="FIX" flag="inheritance:FIX">Code for fitting the predictive model to the training data and for predicting the average annual temperature for all measurement stations for the years 2010 to 2019</Property> </Record> </Entities> diff --git a/unittests/test_tool.py b/unittests/test_tool.py index 5b13c879..0a5a5f67 100755 --- a/unittests/test_tool.py +++ b/unittests/test_tool.py @@ -157,19 +157,19 @@ def test_markdown_converter(): assert children[0].name == "responsible" assert children[0].value.__class__ == list -def prepare_test_record_file(): - ident = LocalStorageIdentifiableAdapter() - crawler = Crawler(debug=True, identifiableAdapter=ident) - crawler.crawl_directory(rfp("test_directories", "examples_article"), - rfp("scifolder_cfood.yml")) +# def prepare_test_record_file(): +# ident = LocalStorageIdentifiableAdapter() +# crawler = Crawler(debug=True, identifiableAdapter=ident) +# crawler.crawl_directory(rfp("test_directories", "examples_article"), +# rfp("scifolder_cfood.yml")) - # clean record list: - recordlist = ident.get_records() - for i in range(len(recordlist)-1, 1, -1): - if recordlist[i].parents[0].name == "Person": - del recordlist[i] +# # clean record list: +# recordlist = ident.get_records() +# for i in range(len(recordlist)-1, 1, -1): +# if recordlist[i].parents[0].name == "Person": +# del recordlist[i] - ident.store_state(rfp("records.xml")) +# ident.store_state(rfp("records.xml")) def test_ambigious_records(): ident = LocalStorageIdentifiableAdapter() @@ -197,7 +197,18 @@ def test_crawler_update_list(): rfp("scifolder_cfood.yml")) ident.restore_state(rfp("records.xml")) - assert len(ident.get_records()) == len(crawler.updateList) + # The records.xml file is constructed as follows: + # To a full run of the crawler, resolve all identifiables and insert all resulting entities. + # See: test-setup/datamodel/generate_test_data.py for details. + # If the following assertions fail, that is a hint, that the test file records.xml is + # incorrect: + assert len(ident.get_records()) == 18 + assert len([r for r in ident.get_records() if r.parents[0].name == "Person"]) == 5 + assert len([r for r in ident.get_records() if r.parents[0].name == "Measurement"]) == 11 + assert len([r for r in ident.get_records() if r.parents[0].name == "Project"]) == 2 + + # The crawler contains lots of duplicates, because identifiables have not been resolved yet: + assert len(ident.get_records()) != len(crawler.updateList) ident.register_identifiable( "Person", db.RecordType() @@ -215,49 +226,57 @@ def test_crawler_update_list(): .add_parent(name="Project") .add_property(name="date") .add_property(name="identifier")) - - curind = 0 - r = ident.get_records() - id_r0 = ident.get_identifiable(r[curind]) - assert r[curind].parents[0].name == id_r0.parents[0].name - assert r[curind].get_property("first_name").value == id_r0.get_property("first_name").value - assert r[curind].get_property("last_name").value == id_r0.get_property("last_name").value - assert len(r[curind].parents) == 1 + # Check consistency: + # Check whether identifiables retrieved from current identifiable store return the same results. + + # take the first person in the list of records: + for r in ident.get_records(): + if r.parents[0].name == "Person": + r_cur = r + break + + id_r0 = ident.get_identifiable(r_cur) + assert r_cur.parents[0].name == id_r0.parents[0].name + assert r_cur.get_property("first_name").value == id_r0.get_property("first_name").value + assert r_cur.get_property("last_name").value == id_r0.get_property("last_name").value + assert len(r_cur.parents) == 1 assert len(id_r0.parents) == 1 - assert len(r[curind].properties) == 2 + assert len(r_cur.properties) == 2 assert len(id_r0.properties) == 2 idr_r0_test = ident.retrieve_identified_record(id_r0) - idr_r0 = ident.retrieve_identifiable(r[curind]) + idr_r0 = ident.retrieve_identifiable(r_cur) assert idr_r0 == idr_r0_test - curind = 0 - r = ident.get_records() - id_r1 = ident.get_identifiable(r[curind]) - # print(r[curind]) - # print(id_r1) - assert r[curind].parents[0].name == id_r1.parents[0].name - assert r[curind].get_property("identifier").value == id_r1.get_property("identifier").value - assert r[curind].get_property("date").value == id_r1.get_property("date").value - assert r[curind].get_property("project").value == id_r1.get_property("project").value - assert len(r[curind].parents) == 1 + # take the first measurement in the list of records: + for r in ident.get_records(): + if r.parents[0].name == "Measurement": + r_cur = r + break + + id_r1 = ident.get_identifiable(r_cur) + assert r_cur.parents[0].name == id_r1.parents[0].name + assert r_cur.get_property("identifier").value == id_r1.get_property("identifier").value + assert r_cur.get_property("date").value == id_r1.get_property("date").value + assert r_cur.get_property("project").value == id_r1.get_property("project").value + assert len(r_cur.parents) == 1 assert len(id_r1.parents) == 1 - assert len(r[curind].properties) == 5 + assert len(r_cur.properties) == 5 assert len(id_r1.properties) == 3 idr_r1_test = ident.retrieve_identified_record(id_r1) - idr_r1 = ident.retrieve_identifiable(r[curind]) + idr_r1 = ident.retrieve_identifiable(r_cur) assert idr_r1 == idr_r1_test assert idr_r1 != idr_r0 assert idr_r1_test != idr_r0_test assert len(idr_r1.properties) == 5 - assert r[curind].get_property("responsible").value == idr_r1.get_property("responsible").value - assert r[curind].get_property("description").value == idr_r1.get_property("description").value + assert r_cur.get_property("responsible").value == idr_r1.get_property("responsible").value + assert r_cur.get_property("description").value == idr_r1.get_property("description").value # test whether compare_entites function works in this context: - comp = compare_entities(r[curind], id_r1) + comp = compare_entities(r_cur, id_r1) assert len(comp[0]["parents"]) == 0 assert len(comp[1]["parents"]) == 0 assert len(comp[0]["properties"]) == 2 @@ -265,7 +284,7 @@ def test_crawler_update_list(): assert "responsible" in comp[0]["properties"] assert "description" in comp[0]["properties"] - comp = compare_entities(r[curind], idr_r1) + comp = compare_entities(r_cur, idr_r1) assert len(comp[0]["parents"]) == 0 assert len(comp[1]["parents"]) == 0 assert len(comp[0]["properties"]) == 0 -- GitLab