From 3ada1d355c6fdb896b78e8c9a636e7e396459b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Mon, 28 Oct 2019 15:37:41 +0100 Subject: [PATCH] update tests --- integrationtests/full_test/crawl.py | 2 +- .../TestProject/2019-02-03/README.md | 2 +- .../2019-02-03_something/README.md | 9 +- .../2019-02-03_really_cool_finding/README.md | 6 +- .../datafile.dat | 0 .../2019_paper_on_exciting_stuff/README.md | 5 +- .../2019_paper_on_exciting_stuff/usefull.xlsx | 0 .../2019_paper_on_exciting_stuff/useless.xlsx | 0 .../TestProject/2019-02-03/README.md | 5 +- .../2019-02-03_something/README.md | 14 +- integrationtests/full_test/test_crawler.py | 143 ++++++++++++++++-- 11 files changed, 162 insertions(+), 24 deletions(-) delete mode 100644 integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/datafile.dat delete mode 100644 integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/usefull.xlsx delete mode 100644 integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/useless.xlsx diff --git a/integrationtests/full_test/crawl.py b/integrationtests/full_test/crawl.py index fd162731..62ca8eac 100755 --- a/integrationtests/full_test/crawl.py +++ b/integrationtests/full_test/crawl.py @@ -56,7 +56,7 @@ if __name__ == "__main__": print("Query done...") config = db.configuration.get_config() c = Crawler(use_cache=True, access=access, - verbosity=INFO, + verbosity=DEBUG, food=[ProjectCFood, AnalysisCFood, ExperimentCFood, PublicationCFood, SimulationCFood, diff --git a/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03/README.md b/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03/README.md index e557f203..1c3d6935 100644 --- a/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03/README.md +++ b/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03/README.md @@ -3,7 +3,7 @@ responsible: - Only Responsible description: A description of another example analysis. -data: +source: - filename: "/ExperimentalData/TestProject/2019-02-03/*.dat" description: an example reference to a results file diff --git a/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03_something/README.md b/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03_something/README.md index c342053a..c62e216b 100644 --- a/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03_something/README.md +++ b/integrationtests/full_test/extroot/DataAnalysis/TestProject/2019-02-03_something/README.md @@ -7,9 +7,12 @@ results: - filename: "images/*.png" description: an example reference to a results file -data: -- filename: /ExperimentalData/TestProject/2019-02-03_something/use*.xlsx - description: an example reference to data files +source: +- filename: /ExperimentalData/TestProject/2019-02-03_something/ + description: an example reference to an experiment + +revisionOf: +- ../2019-02-03 scripts: - analyse.py diff --git a/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md b/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md index 348a6fec..68bebf70 100644 --- a/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md +++ b/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md @@ -3,7 +3,9 @@ responsible: - Only Responsible description: A description of another example experiment. +source: +- /home/professional/CaosDB/caosdb-deploy/profiles/empty/custom/extroot/DataAnalysis/TestProject/2019-02-03/results.pdf + results: -- filename: "/ExperimentalData/TestProject/2019-02-03/*.dat" - description: an example reference to a results file +- "*.pdf" ... diff --git a/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/datafile.dat b/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/datafile.dat deleted file mode 100644 index e69de29b..00000000 diff --git a/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/README.md b/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/README.md index 9e63c07c..5bd4e273 100644 --- a/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/README.md +++ b/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/README.md @@ -1,12 +1,9 @@ --- responsible: - First Person -- Second Person description: A description of an example experiment. -results: -- filename: "*.xlsx" - description: an example reference to a results file + tags: - collagen diff --git a/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/usefull.xlsx b/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/usefull.xlsx deleted file mode 100644 index e69de29b..00000000 diff --git a/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/useless.xlsx b/integrationtests/full_test/extroot/Publications/Theses/2019_paper_on_exciting_stuff/useless.xlsx deleted file mode 100644 index e69de29b..00000000 diff --git a/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03/README.md b/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03/README.md index 348a6fec..048b64e8 100644 --- a/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03/README.md +++ b/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03/README.md @@ -4,6 +4,9 @@ responsible: description: A description of another example experiment. results: -- filename: "/ExperimentalData/TestProject/2019-02-03/*.dat" +- filename: "*.dat" description: an example reference to a results file + +scripts: +- sim.py ... diff --git a/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03_something/README.md b/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03_something/README.md index 9e63c07c..3c984cb2 100644 --- a/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03_something/README.md +++ b/integrationtests/full_test/extroot/SimulationData/TestProject/2019-02-03_something/README.md @@ -5,8 +5,18 @@ responsible: description: A description of an example experiment. results: -- filename: "*.xlsx" - description: an example reference to a results file +- filename: "*.npy" + description: time series + +scripts: +- "parameters.p" +- "large_sim.py" + +revisonOf: +- ../2019-02-03 + +source: +- /extroot/ExperimentalData/TestProject/2019-02-03 tags: - collagen diff --git a/integrationtests/full_test/test_crawler.py b/integrationtests/full_test/test_crawler.py index d610d621..70821deb 100755 --- a/integrationtests/full_test/test_crawler.py +++ b/integrationtests/full_test/test_crawler.py @@ -30,8 +30,19 @@ class CrawlerTest(unittest.TestCase): # There should be a datafile as result attached with path datafile.dat datfile_id = exp.get_property("results").value[0] datfile = get_entity_with_id(datfile_id) + self.assertEqual("A description of another example experiment.", + datfile.description) assert os.path.basename(datfile.path) == "datafile.dat" + # Should have a responsible person + self.assertIsNotNone(exp.get_property("Responsible")) + person = db.Record(id=exp.get_property("Responsible").value) + person.retrieve() + self.assertEqual("Only", person.get_property("FirstName").value) + + # Should have a description + self.assertIsNotNone(exp.description) + ######################### # # second experiment # # ######################### @@ -75,6 +86,28 @@ class CrawlerTest(unittest.TestCase): datfile = get_entity_with_id(datfile_id) assert os.path.basename(datfile.path) == "plot.py" + # There should be a file as script attached with path plot.py + datfile_id = ana.get_property("source").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "datafile.dat" + self.assertEqual(datfile.description, + "an example reference to a results file") + + # Should have a responsible person + self.assertIsNotNone(ana.get_property("Responsible")) + person = db.Record(id=ana.get_property("Responsible").value) + person.retrieve() + self.assertEqual("Only", person.get_property("FirstName").value) + + # Should have a description + self.assertIsNotNone(ana.description) + + # Should reference an experiment + self.assertIsNotNone(ana.get_property("Experiment")) + person = db.Record(id=ana.get_property("Responsible").value) + person.retrieve() + self.assertEqual("2019-02-03", person.get_property("date").value) + ####################### # # second analysis # # ####################### @@ -85,30 +118,120 @@ class CrawlerTest(unittest.TestCase): # Should be the same project assert project_id == ana.get_property("Project").value - # Should have two data files - datfile_ids = ana.get_property("results").value - datafile_names = [] + # There should be a file as script attached with path plot.py + datfile_id = ana.get_property("scripts").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "analyse.py" - for did in datfile_ids: - datfile = get_entity_with_id(did) - datafile_names.append(os.path.basename(datfile.path)) - assert "lol1.png" in datafile_names - assert "lol2.png" in datafile_names + # Should reference an experiment + self.assertIsNotNone(ana.get_property("Experiment")) + person = db.Record(id=ana.get_property("Responsible").value) + person.retrieve() + self.assertEqual("2019-02-03", person.get_property("date").value) + + def test_simulation(self): + ###################### + # # first simulation # # + ###################### + sim = db.execute_query( + "FIND Simulation with date=2019-02-03 and identifier='empty_identifier'", + unique=True) + + # There should be a Project with name TestProject which is referenced + project_id = sim.get_property("Project").value + project = get_entity_with_id(project_id) + assert "Project" in [p.name for p in project.get_parents()] + + # There should be a file as result attached with path results.pdf + datfile_id = sim.get_property("results").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "snapshots.dat" # There should be a file as script attached with path plot.py - datfile_id = ana.get_property("scripts").value[0] + datfile_id = sim.get_property("scripts").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "sim.py" + + # Should have a responsible person + self.assertIsNotNone(sim.get_property("Responsible")) + person = db.Record(id=sim.get_property("Responsible").value) + person.retrieve() + self.assertEqual("Only", person.get_property("FirstName").value) + + # Should have a description + self.assertIsNotNone(sim.description) + + ######################### + # # second simulation # # + ######################### + sim = db.execute_query( + "FIND Simulation with date=2019-02-03 and identifier='something'", + unique=True) + + # There should be a file as script attached with path plot.py + exp = get_entity_with_id(sim.get_property("source").value) + self.assertEqual(exp.parents[0].name, "Experiment") + + # Should be the same project + assert project_id == sim.get_property("Project").value + + # Should have two responsible persons + self.assertIsNotNone(sim.get_property("Responsible")) + self.assertEqual(len(sim.get_property("Responsible").value), 2) + + # Should have revision + osim = get_entity_with_id(sim.get_property("revisionOf").value[0]) + self.assertEqual(osim.parents[0].name, "Simulation") + self.assertNotEqual(osim.id, sim.id) + + # Should have data file + datfile_id = sim.get_property("results").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "timeseries.npy" + + # There should be a file as script attached with path plot.py + datfile_id = sim.get_property("scripts").value[0] datfile = get_entity_with_id(datfile_id) assert os.path.basename(datfile.path) == "analyse.py" + # Should have two scritps files + datfile_ids = exp.get_property("scripts").value + datafile_names = [] + + for did in datfile_ids: + datfile = get_entity_with_id(did) + datafile_names.append(os.path.basename(datfile.path)) + assert "parameters.p" in datafile_names + assert "large_sim.py" in datafile_names + def test_publication(self): ######################### # # first publication # # ######################### pub = db.execute_query("FIND *really_cool_finding", unique=True) - # There should be a Project with name TestProject which is referenced + # There should be a file as result attached with path results.pdf + datfile_id = pub.get_property("results").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "poster.pdf" + + # There should be a file as data attached with path plot.py + datfile_id = pub.get_property("sources").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "results.pdf" + + # Test type + self.assertEqual(pub.parents[0].name, "Poster") ########################## # # second publication # # ########################## pub = db.execute_query("FIND *paper_on_exciting_stuff ", unique=True) + + # There should be a file as data attached with path plot.py + datfile_id = pub.get_property("sources").value[0] + datfile = get_entity_with_id(datfile_id) + assert os.path.basename(datfile.path) == "results.pdf" + + # Test type + self.assertEqual(pub.parents[0].name, "Poster") -- GitLab