Skip to content
Snippets Groups Projects
Commit 59e05ba6 authored by George Marchment's avatar George Marchment
Browse files

Added more automatic tests

parent a34c9b51
No related branches found
No related tags found
No related merge requests found
Pipeline #14381 failed with stage
in 2 minutes and 28 seconds
Showing
with 339 additions and 56 deletions
......@@ -29,8 +29,7 @@ class TestWorkflows(unittest.TestCase):
def test_wf{num}_simple_duplicate(self):
w = Workflow(f"tests/ressources/workflows/{num}", display_info=False, duplicate=True)
w.initialise()
json_files = glob.glob(f'tests/ressources/workflows/{num}/*.json', recursive=False)
self.assertTrue(w.check_if_equal(json_files[0]))
self.assertTrue(w.check_if_equal('tests/ressources/workflows/{num}/specification_graph.json'))
"""
script+=text
......@@ -38,8 +37,153 @@ class TestWorkflows(unittest.TestCase):
with open("./tests/test_workflows_simple_duplicate.py", "w") as text_file:
text_file.write(script)
def write_executions_extraction_test():
#I'm gonna automatically write the tests before running them
script = """import unittest
import json
import glob
from src.workflow import Workflow
class Test_All_Executors_Extraction(unittest.TestCase):
"""
workflows = glob.glob(f'./tests/ressources/workflows/*', recursive=False)
for wf in workflows:
num = wf.split("/")[-1]
text=f"""
def test_{num}_extraction(self):
w = Workflow(f"tests/ressources/workflows/{num}", display_info=False, duplicate=True)
w.initialise()
with open('tests/ressources/workflows/{num}/all_executors.json') as json_file:
saved = json.load(json_file)
executors = w.get_workflow_main().get_all_executors_in_workflow()
dico= {{}}
for e in executors:
dico[str(e)] = e.get_code(get_OG = True)
self.assertTrue(set(dico.values())==set(saved.values()))
"""
script+=text
with open("./tests/test_workflows_all_executors.py", "w") as text_file:
text_file.write(script)
def write_process_extraction_test():
#I'm gonna automatically write the tests before running them
script = """import unittest
import json
import glob
from src.workflow import Workflow
class Test_Process_Extraction(unittest.TestCase):
"""
workflows = glob.glob(f'./tests/ressources/workflows/*', recursive=False)
for wf in workflows:
num = wf.split("/")[-1]
text=f"""
def test_{num}_extraction(self):
w = Workflow(f"tests/ressources/workflows/{num}", display_info=False, duplicate=True)
w.initialise()
with open('tests/ressources/workflows/{num}/all_processes.json') as json_file:
saved = json.load(json_file)
processes = w.get_processes_called()
dico= {{}}
for e in processes:
dico[str(e)] = e.get_code(get_OG = True)
self.assertTrue(set(dico.values())==set(saved.values()))
"""
script+=text
with open("./tests/test_process_extraction.py", "w") as text_file:
text_file.write(script)
def write_subworkflow_extraction_test():
#I'm gonna automatically write the tests before running them
script = """import unittest
import json
import glob
from src.workflow import Workflow
class Test_Subworkflow_Extraction(unittest.TestCase):
"""
workflows = glob.glob(f'./tests/ressources/workflows/*', recursive=False)
for wf in workflows:
num = wf.split("/")[-1]
text=f"""
def test_{num}_extraction(self):
w = Workflow(f"tests/ressources/workflows/{num}", display_info=False, duplicate=True)
w.initialise()
with open('tests/ressources/workflows/{num}/all_subworkflows.json') as json_file:
saved = json.load(json_file)
subworkflows = w.get_subworkflows_called()
dico= {{}}
for e in subworkflows:
dico[str(e)] = e.get_code(get_OG = True)
self.assertTrue(set(dico.values())==set(saved.values()))
"""
script+=text
with open("./tests/test_subworkflow_extraction.py", "w") as text_file:
text_file.write(script)
def write_executor_extraction_per_subworkflow_test():
#I'm gonna automatically write the tests before running them
script = """import unittest
import json
import glob
from src.workflow import Workflow
class Test_Executor_Extraction_Per_Subworkflow(unittest.TestCase):
"""
workflows = glob.glob(f'./tests/ressources/workflows/*', recursive=False)
for wf in workflows:
num = wf.split("/")[-1]
text=f"""
def test_{num}_extraction(self):
w = Workflow(f"tests/ressources/workflows/{num}", display_info=False, duplicate=True)
w.initialise()
with open('tests/ressources/workflows/{num}/executors_per_subworkflows.json') as json_file:
saved = json.load(json_file)
saved_sets = []
for sub in saved:
saved_sets.append(set(saved[sub].values()))
subs = w.get_subworkflows_called()
dico= {{}}
for s in subs:
executors = s.get_all_executors_in_workflow()
executors_vals = []
for e in executors:
executors_vals.append(e.get_code(get_OG = True))
self.assertTrue(set(executors_vals) in saved_sets)
"""
script+=text
with open("./tests/test_executor_extraction_per_subworkflow.py", "w") as text_file:
text_file.write(script)
if __name__ == '__main__':
write_duplicate_test()
write_executions_extraction_test()
write_process_extraction_test()
write_subworkflow_extraction_test()
write_executor_extraction_per_subworkflow_test()
sys.exit(0 if main(*sys.argv[1:]) else 1)
......@@ -90,6 +90,9 @@ class Graph():
self.dico_flattened["subworkflows"] = []
def get_full_dico(self):
return self.full_dico
def is_initialised(self):
return self.initialised
......@@ -136,8 +139,8 @@ class Graph():
if(self.link_dico==None):
self.link_dico = initia_link_dico_rec(self.full_dico)
def get_specification_graph(self, filename = "specification_graph", render_graphs = True):
generate_graph(self.get_output_dir()/'graphs'/filename, self.full_dico, render_graphs = render_graphs)
def get_specification_graph(self, dirc = 'graphs', filename = "specification_graph", render_graphs = True):
generate_graph(self.get_output_dir()/ dirc /filename, self.full_dico, render_graphs = render_graphs)
def get_specification_graph_wo_labels(self, filename = "specification_graph_wo_labels", render_graphs = True):
generate_graph(self.get_output_dir()/'graphs'/filename, self.full_dico, label_edge=False, label_node=False, render_graphs = render_graphs)
......
......@@ -164,8 +164,8 @@ class Root(Nextflow_Building_Blocks):
b.get_inside_executors_rec(dico)
return list(dico.keys())
def get_all_executors_from_workflow(self):
return self.get_executors_same_level()+self.get_inside_executors()
#def get_all_executors_from_workflow(self):
# return self.get_executors_same_level()+self.get_inside_executors()
#def get_calls(self):
# tab = []
......
......@@ -201,7 +201,59 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
self.iniatilise_tab_processes_2_remove()
return self.graph.check_if_equal(file, processes_2_remove = self.processes_2_remove)
###########################
# Generate test data
###########################
#These are the methods which generate the test data
def generate_test_specification_graph(self):
dico = self.graph.get_full_dico()
with open(self.get_output_dir()/ 'test' /"specification_graph.json", "w") as outfile:
json.dump(dico, outfile, indent = 4)
def generate_all_executors(self):
executors = self.get_workflow_main().get_all_executors_in_workflow()
dico= {}
for e in executors:
dico[str(e)] = e.get_code(get_OG = True)
with open(self.get_output_dir()/ 'test' /"all_executors.json", "w") as outfile:
json.dump(dico, outfile, indent = 4)
def generate_executors_per_subworkflows(self):
subs = self.get_subworkflows_called()
dico= {}
for s in subs:
dico[str(s)]= {}
executors = s.get_all_executors_in_workflow()
for e in executors:
dico[str(s)][str(e)] = e.get_code(get_OG = True)
with open(self.get_output_dir()/ 'test' /"executors_per_subworkflows.json", "w") as outfile:
json.dump(dico, outfile, indent = 4)
def generate_all_processes(self):
processes = self.get_processes_called()
dico= {}
for p in processes:
dico[str(p)] = p.get_code()
with open(self.get_output_dir()/ 'test' /"all_processes.json", "w") as outfile:
json.dump(dico, outfile, indent = 4)
def generate_all_subworkflows(self):
subs = self.get_subworkflows_called()
dico= {}
for s in subs:
dico[str(s)] = s.get_code()
with open(self.get_output_dir()/ 'test' /"all_subworkflows.json", "w") as outfile:
json.dump(dico, outfile, indent = 4)
def generate_all_test_data(self):
self.generate_test_specification_graph()
self.generate_all_executors()
self.generate_all_processes()
self.generate_all_subworkflows()
self.generate_executors_per_subworkflows()
#Returns a dico of number of processes called per each condition
......@@ -293,7 +345,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
#TODO -> update the operations -> also consider the operations in the params of the calls which need to be updated
for o in self.get_workflow_main().root.get_all_executors_from_workflow():
for o in self.get_workflow_main().get_all_executors_in_workflow():
if(o.get_type()=="Operation"):
code = code.replace(o.get_code(get_OG=True), o.convert_to_DSL2())
else:
......@@ -435,6 +487,14 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
if(ele.get_type()=="Subworkflow"):
subs.append(ele)
return subs
def get_processes_called(self):
subs = []
for c in self.get_workflow_main().get_all_calls_in_workflow():
ele = c.get_first_element_called()
if(ele.get_type()=="Process"):
subs.append(ele)
return subs
def rewrite_and_initialise(self, code):
......
{
"Call_124185449263312": "sub2()",
"Call_124185449266912": "sub3()",
"Call_124185450586384": "M1()",
"Call_124185450591088": "M2(M1.out)",
"Call_124185449161792": "M1()",
"Call_124185449333136": "M2(M1.out)",
"Call_124185450583648": "sub1()",
"<src.operation.Operation object at 0x70f22dacb8e0>": "sub1.out.view()",
"Call_124185449045184": "sub1()",
"<src.operation.Operation object at 0x70f22da43040>": "sub1.out.view()"
}
\ No newline at end of file
{
"<src.process.Process object at 0x70f22dac9210>": "process M1 {\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}",
"<src.process.Process object at 0x70f22dacb5b0>": "process M2 {\n input:\n path a\n\n \"\"\"\n SOMETHING\n \"\"\"\n}",
"<src.process.Process object at 0x70f22d925bd0>": "process M1 {\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}",
"<src.process.Process object at 0x70f22d927f10>": "process M2 {\n input:\n path a\n\n \"\"\"\n SOMETHING\n \"\"\"\n}"
}
\ No newline at end of file
{
"<src.subworkflow.Subworkflow object at 0x70f22dab2770>": "workflow sub1 {\n main:\n M1()\n M2(M1.out)\n\n emit:\n M1.out\n}",
"<src.subworkflow.Subworkflow object at 0x70f22d93a5c0>": "workflow sub1 {\n main:\n M1()\n M2(M1.out)\n\n emit:\n M1.out\n}",
"<src.subworkflow.Subworkflow object at 0x70f22d96fca0>": "workflow sub2 {\n main:\n sub1()\n sub1.out.view()\n}",
"<src.subworkflow.Subworkflow object at 0x70f22d93a410>": "workflow sub3 {\n main:\n sub1()\n sub1.out.view()\n}"
}
\ No newline at end of file
{
"<src.subworkflow.Subworkflow object at 0x70f22dab2770>": {
"Call_124185450586384": "M1()",
"Call_124185450591088": "M2(M1.out)"
},
"<src.subworkflow.Subworkflow object at 0x70f22d93a5c0>": {
"Call_124185449161792": "M1()",
"Call_124185449333136": "M2(M1.out)"
},
"<src.subworkflow.Subworkflow object at 0x70f22d96fca0>": {
"Call_124185450583648": "sub1()",
"<src.operation.Operation object at 0x70f22dacb8e0>": "sub1.out.view()",
"Call_124185450586384": "M1()",
"Call_124185450591088": "M2(M1.out)"
},
"<src.subworkflow.Subworkflow object at 0x70f22d93a410>": {
"Call_124185449045184": "sub1()",
"<src.operation.Operation object at 0x70f22da43040>": "sub1.out.view()",
"Call_124185449161792": "M1()",
"Call_124185449333136": "M2(M1.out)"
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
"sub2_0": {
"nodes": [
{
"id": "<src.operation.Operation object at 0x786a10c39fc0>",
"id": "<src.operation.Operation object at 0x70f22dacb8e0>",
"name": "",
"shape": "point",
"xlabel": "sub1.out.view()",
......@@ -14,8 +14,8 @@
],
"edges": [
{
"A": "<src.operation.Operation object at 0x786a10c399f0>",
"B": "<src.operation.Operation object at 0x786a10c39fc0>",
"A": "<src.operation.Operation object at 0x70f289390070>",
"B": "<src.operation.Operation object at 0x70f22dacb8e0>",
"label": "sub1.out"
}
],
......@@ -23,28 +23,28 @@
"sub1_0": {
"nodes": [
{
"id": "<src.process.Process object at 0x786a10c394e0>",
"id": "<src.process.Process object at 0x70f22dac9210>",
"name": "M1",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.process.Process object at 0x786a10c395a0>",
"id": "<src.process.Process object at 0x70f22dacb5b0>",
"name": "M2",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.operation.Operation object at 0x786a10c39420>",
"id": "<src.operation.Operation object at 0x70f22dacbf40>",
"name": "",
"shape": "point",
"xlabel": "M1.out",
"fillcolor": "white"
},
{
"id": "<src.operation.Operation object at 0x786a10c399f0>",
"id": "<src.operation.Operation object at 0x70f289390070>",
"name": "",
"shape": "point",
"xlabel": "emit: M1.out",
......@@ -53,18 +53,18 @@
],
"edges": [
{
"A": "<src.process.Process object at 0x786a10c394e0>",
"B": "<src.operation.Operation object at 0x786a10c39420>",
"A": "<src.process.Process object at 0x70f22dac9210>",
"B": "<src.operation.Operation object at 0x70f22dacbf40>",
"label": "M1.out"
},
{
"A": "<src.operation.Operation object at 0x786a10c39420>",
"B": "<src.process.Process object at 0x786a10c395a0>",
"A": "<src.operation.Operation object at 0x70f22dacbf40>",
"B": "<src.process.Process object at 0x70f22dacb5b0>",
"label": ""
},
{
"A": "<src.process.Process object at 0x786a10c394e0>",
"B": "<src.operation.Operation object at 0x786a10c399f0>",
"A": "<src.process.Process object at 0x70f22dac9210>",
"B": "<src.operation.Operation object at 0x70f289390070>",
"label": "M1.out"
}
],
......@@ -75,7 +75,7 @@
"sub3_0": {
"nodes": [
{
"id": "<src.operation.Operation object at 0x786a10c3a770>",
"id": "<src.operation.Operation object at 0x70f22da43040>",
"name": "",
"shape": "point",
"xlabel": "sub1.out.view()",
......@@ -84,8 +84,8 @@
],
"edges": [
{
"A": "<src.operation.Operation object at 0x786a10c3a560>",
"B": "<src.operation.Operation object at 0x786a10c3a770>",
"A": "<src.operation.Operation object at 0x70f22d9561a0>",
"B": "<src.operation.Operation object at 0x70f22da43040>",
"label": "sub1.out"
}
],
......@@ -93,28 +93,28 @@
"sub1_1": {
"nodes": [
{
"id": "<src.process.Process object at 0x786a10c3a4a0>",
"id": "<src.process.Process object at 0x70f22d925bd0>",
"name": "M1",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.process.Process object at 0x786a10c39f00>",
"id": "<src.process.Process object at 0x70f22d927f10>",
"name": "M2",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.operation.Operation object at 0x786a10c3a500>",
"id": "<src.operation.Operation object at 0x70f22d926c50>",
"name": "",
"shape": "point",
"xlabel": "M1.out",
"fillcolor": "white"
},
{
"id": "<src.operation.Operation object at 0x786a10c3a560>",
"id": "<src.operation.Operation object at 0x70f22d9561a0>",
"name": "",
"shape": "point",
"xlabel": "emit: M1.out",
......@@ -123,18 +123,18 @@
],
"edges": [
{
"A": "<src.process.Process object at 0x786a10c3a4a0>",
"B": "<src.operation.Operation object at 0x786a10c3a500>",
"A": "<src.process.Process object at 0x70f22d925bd0>",
"B": "<src.operation.Operation object at 0x70f22d926c50>",
"label": "M1.out"
},
{
"A": "<src.operation.Operation object at 0x786a10c3a500>",
"B": "<src.process.Process object at 0x786a10c39f00>",
"A": "<src.operation.Operation object at 0x70f22d926c50>",
"B": "<src.process.Process object at 0x70f22d927f10>",
"label": ""
},
{
"A": "<src.process.Process object at 0x786a10c3a4a0>",
"B": "<src.operation.Operation object at 0x786a10c3a560>",
"A": "<src.process.Process object at 0x70f22d925bd0>",
"B": "<src.operation.Operation object at 0x70f22d9561a0>",
"label": "M1.out"
}
],
......
{
"Call_124185448873504": "M2(M1.out)",
"Call_124185450888880": "M1()",
"Call_124185448859584": "M1()"
}
\ No newline at end of file
{
"<src.process.Process object at 0x70f22dafa9e0>": "process M2 {\n input:\n path a\n\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}",
"<src.process.Process object at 0x70f22dafa200>": "process M1 {\n\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}",
"<src.process.Process object at 0x70f22dafbf10>": "process M1 {\n\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}"
}
\ No newline at end of file
{}
\ No newline at end of file
{}
\ No newline at end of file
{
"nodes": [
{
"id": "<src.process.Process object at 0x71ee1a494c70>",
"id": "<src.process.Process object at 0x70f22dafa200>",
"name": "M1",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.process.Process object at 0x71ee1a496ce0>",
"id": "<src.process.Process object at 0x70f22dafbf10>",
"name": "M1",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.process.Process object at 0x71ee1a4950f0>",
"id": "<src.process.Process object at 0x70f22dafa9e0>",
"name": "M2",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.operation.Operation object at 0x71ee1a497700>",
"id": "<src.operation.Operation object at 0x70f22daf9e10>",
"name": "",
"shape": "point",
"xlabel": "M1.out",
......@@ -31,18 +31,18 @@
],
"edges": [
{
"A": "<src.process.Process object at 0x71ee1a494c70>",
"B": "<src.operation.Operation object at 0x71ee1a497700>",
"A": "<src.process.Process object at 0x70f22dafa200>",
"B": "<src.operation.Operation object at 0x70f22daf9e10>",
"label": "M1.out"
},
{
"A": "<src.process.Process object at 0x71ee1a496ce0>",
"B": "<src.operation.Operation object at 0x71ee1a497700>",
"A": "<src.process.Process object at 0x70f22dafbf10>",
"B": "<src.operation.Operation object at 0x70f22daf9e10>",
"label": "M1.out"
},
{
"A": "<src.operation.Operation object at 0x71ee1a497700>",
"B": "<src.process.Process object at 0x71ee1a4950f0>",
"A": "<src.operation.Operation object at 0x70f22daf9e10>",
"B": "<src.process.Process object at 0x70f22dafa9e0>",
"label": ""
}
],
......
{
"<src.operation.Operation object at 0x70f2e278ba60>": "a = M1()",
"<src.operation.Operation object at 0x70f22db13670>": "a = Channel.empty()",
"Call_124185450985744": "M2(a)"
}
\ No newline at end of file
{
"<src.process.Process object at 0x70f22db13280>": "process M1 {\n\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}",
"<src.process.Process object at 0x70f22db13b80>": "process M2 {\n input:\n path a\n\n output:\n path 'chunk_*'\n\n \"\"\"\n SOMETHING\n \"\"\"\n}"
}
\ No newline at end of file
{}
\ No newline at end of file
{}
\ No newline at end of file
{
"nodes": [
{
"id": "<src.operation.Operation object at 0x71ee1a48e440>",
"id": "<src.operation.Operation object at 0x70f2e278ba60>",
"name": "",
"shape": "point",
"xlabel": "a = M1()",
"fillcolor": "white"
},
{
"id": "<src.process.Process object at 0x71ee1a48fb50>",
"id": "<src.process.Process object at 0x70f22db13280>",
"name": "M1",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.operation.Operation object at 0x71ee1a48fac0>",
"id": "<src.operation.Operation object at 0x70f22db13670>",
"name": "",
"shape": "point",
"xlabel": "a = Channel.empty()",
"fillcolor": ""
},
{
"id": "<src.process.Process object at 0x71ee1a48ed40>",
"id": "<src.process.Process object at 0x70f22db13b80>",
"name": "M2",
"shape": "ellipse",
"xlabel": "",
"fillcolor": ""
},
{
"id": "<src.operation.Operation object at 0x71ee1a48fa60>",
"id": "<src.operation.Operation object at 0x70f22db134c0>",
"name": "",
"shape": "point",
"xlabel": "a",
......@@ -38,23 +38,23 @@
],
"edges": [
{
"A": "<src.process.Process object at 0x71ee1a48fb50>",
"B": "<src.operation.Operation object at 0x71ee1a48e440>",
"A": "<src.process.Process object at 0x70f22db13280>",
"B": "<src.operation.Operation object at 0x70f2e278ba60>",
"label": ""
},
{
"A": "<src.operation.Operation object at 0x71ee1a48e440>",
"B": "<src.operation.Operation object at 0x71ee1a48fa60>",
"A": "<src.operation.Operation object at 0x70f2e278ba60>",
"B": "<src.operation.Operation object at 0x70f22db134c0>",
"label": "a"
},
{
"A": "<src.operation.Operation object at 0x71ee1a48fac0>",
"B": "<src.operation.Operation object at 0x71ee1a48fa60>",
"A": "<src.operation.Operation object at 0x70f22db13670>",
"B": "<src.operation.Operation object at 0x70f22db134c0>",
"label": "a"
},
{
"A": "<src.operation.Operation object at 0x71ee1a48fa60>",
"B": "<src.process.Process object at 0x71ee1a48ed40>",
"A": "<src.operation.Operation object at 0x70f22db134c0>",
"B": "<src.process.Process object at 0x70f22db13b80>",
"label": ""
}
],
......
{
"<src.operation.Operation object at 0x70f22da400d0>": "b = sub1.out.a",
"Call_124185451105920": "sub1()",
"Call_124185448857952": "sub2(b)",
"<src.operation.Operation object at 0x70f22d927e20>": "a = M1()",
"Call_124185450917040": "M2(b)"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment