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

Merge branch 'fail-ci-on-test-failure' into 'main'

Return non zero code on failure

See merge request !7
parents 24982603 42df9460
No related branches found
No related tags found
1 merge request!7Return non zero code on failure
Pipeline #13263 passed with stage
in 42 seconds
...@@ -5,4 +5,5 @@ __pycache__ ...@@ -5,4 +5,5 @@ __pycache__
.venv .venv
.idea .idea
dist/ dist/
results*/ results*/
\ No newline at end of file *.candidate.nf
\ No newline at end of file
#!/usr/bin/env python #!/usr/bin/env python
import sys
import unittest import unittest
#Run all tests
if __name__ == '__main__': # Run all tests
def main(pattern='test_*.py', *args):
test_loader = unittest.TestLoader() test_loader = unittest.TestLoader()
test_suite = test_loader.discover('tests', pattern='test_*.py') test_suite = test_loader.discover('tests', pattern=pattern)
runner = unittest.TextTestRunner() runner = unittest.TextTestRunner()
runner.run(test_suite) results = runner.run(test_suite)
return results.wasSuccessful()
if __name__ == '__main__':
sys.exit(0 if main(*sys.argv[1:]) else 1)
...@@ -43,6 +43,8 @@ class BioFlowInsightError(Exception): ...@@ -43,6 +43,8 @@ class BioFlowInsightError(Exception):
#* [5] -> A ternary conditional operator was used with an tuple #* [5] -> A ternary conditional operator was used with an tuple
#* [7] -> Tuple with emit (ch1, ch2) = emit.out #* [7] -> Tuple with emit (ch1, ch2) = emit.out
#* [9] -> Tuple with call (ch1, ch2) = wf() #* [9] -> Tuple with call (ch1, ch2) = wf()
#* [11] -> Failed to extract the operation or call at the line x. Try rewriting it in a simplified version.
......
...@@ -318,16 +318,24 @@ class Nextflow_Building_Blocks: ...@@ -318,16 +318,24 @@ class Nextflow_Building_Blocks:
if(match.group(1) in constant.LIST_OPERATORS): if(match.group(1) in constant.LIST_OPERATORS):
#TODO -> the function below might not work perfectly but i don't have any other ideas #TODO -> the function below might not work perfectly but i don't have any other ideas
#TODO -> IMPORTANT find another way of doing this -> for example if there isn't the same number of curlies/parentheses
#Use if there is an operator called right before opening the curlies/parenthse #Use if there is an operator called right before opening the curlies/parenthse
curly_left, curly_right = get_curly_count(text[:start]), get_curly_count(text[end:]) #curly_left, curly_right = get_curly_count(text[:start]), get_curly_count(text[end:])
parenthese_left, parenthese_right = get_parenthese_count(text[:start]), get_parenthese_count(text[end:]) parenthese_left, parenthese_right = get_parenthese_count(text[:start]), get_parenthese_count(text[end:])
#if(curly_left==0 and curly_right==0 and parenthese_left==0 and parenthese_right==0 and (start, end) not in searched): #if(curly_left==0 and curly_right==0 and parenthese_left==0 and parenthese_right==0 and (start, end) not in searched):
if(parenthese_left==0 and parenthese_right==0 and (start, end) not in searched): if(parenthese_left==0 and parenthese_right==0 and (start, end) not in searched):
searched.append((start, end)) searched.append((start, end))
pot = extract_executor_from_middle(text, start, end) try:
pot = extract_executor_from_middle(text, start, end)
except:
try:
temp = text[start-10:end+10]
except:
temp = text[start:end]
raise BioFlowInsightError(f"Failed to extract the operation or call{self.get_string_line(temp)}. Try rewriting it in a simplified version.", num = 11, origin=self)
pot = expand_to_pipe_operators(text, pot) pot = expand_to_pipe_operators(text, pot)
#If the thing which is extracted is not in the conditon of an if #If the thing which is extracted is not in the conditon of an if
...@@ -360,6 +368,7 @@ class Nextflow_Building_Blocks: ...@@ -360,6 +368,7 @@ class Nextflow_Building_Blocks:
self.executors.append(ope) self.executors.append(ope)
searching = True searching = True
break break
#--------------------------------------------------------------- #---------------------------------------------------------------
#STEP4 - Extract the Executors which only use the pipe operators (which start with a channel) #STEP4 - Extract the Executors which only use the pipe operators (which start with a channel)
......
...@@ -91,13 +91,20 @@ class Nextflow_File(Nextflow_Building_Blocks): ...@@ -91,13 +91,20 @@ class Nextflow_File(Nextflow_Building_Blocks):
if(self.first_file): if(self.first_file):
return self.output_dir return self.output_dir
else: else:
return self.origin.get_output_dir() if(self.origin==None):
return self.output_dir
else:
return self.origin.get_output_dir()
def get_display_info(self): def get_display_info(self):
if (self.first_file): if (self.first_file):
return self.display_info return self.display_info
else: else:
return self.origin.get_display_info() if(self.origin==None):
return self.display_info
else:
return self.origin.get_display_info()
def set_name(self): def set_name(self):
......
...@@ -80,7 +80,7 @@ class RO_Crate: ...@@ -80,7 +80,7 @@ class RO_Crate:
current_directory = os.getcwd() current_directory = os.getcwd()
os.chdir("/".join(self.workflow.nextflow_file.get_file_address().split("/")[:-1])) os.chdir("/".join(self.workflow.nextflow_file.get_file_address().split("/")[:-1]))
try: try:
os.system(f"git log {'--reverse'*reverse} {file} > temp_{id(self)}.txt") os.system(f"git log {'--reverse'*reverse} \"{file}\" > temp_{id(self)}.txt")
with open(f'temp_{id(self)}.txt') as f: with open(f'temp_{id(self)}.txt') as f:
info = f.read() info = f.read()
os.system(f"rm temp_{id(self)}.txt") os.system(f"rm temp_{id(self)}.txt")
......
...@@ -3,26 +3,34 @@ from src.channel import * ...@@ -3,26 +3,34 @@ from src.channel import *
from src.nextflow_file import Nextflow_File from src.nextflow_file import Nextflow_File
class EmptyNextflowFile(Nextflow_File):
def __init__(self, address="tests/ressources/channel/empty_wf.nf", display_info=False, *args, **kwargs):
super().__init__(address=address, display_info=display_info, *args, **kwargs)
def check_file_correctness_after_DSL(self):
return
class TestChannel(unittest.TestCase): class TestChannel(unittest.TestCase):
def test_get_code(self): def test_get_code(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
self.assertIsInstance(ch1, Channel) self.assertIsInstance(ch1, Channel)
self.assertEqual(ch1.get_code(), "ch1") self.assertEqual(ch1.get_code(), "ch1")
def test_get_name(self): def test_get_name(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
self.assertEqual(ch1.get_name(), "ch1") self.assertEqual(ch1.get_name(), "ch1")
def test_get_type(self): def test_get_type(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
self.assertEqual(ch1.get_type(), "Channel") self.assertEqual(ch1.get_type(), "Channel")
def test_add_source(self): def test_add_source(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
self.assertEqual(ch1.get_source(), []) self.assertEqual(ch1.get_source(), [])
ele = "This is a test" ele = "This is a test"
...@@ -30,7 +38,7 @@ class TestChannel(unittest.TestCase): ...@@ -30,7 +38,7 @@ class TestChannel(unittest.TestCase):
self.assertEqual(ch1.get_source(), [ele]) self.assertEqual(ch1.get_source(), [ele])
def test_add_sink(self): def test_add_sink(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
self.assertEqual(ch1.get_sink(), []) self.assertEqual(ch1.get_sink(), [])
ele = "This is a test" ele = "This is a test"
...@@ -38,7 +46,7 @@ class TestChannel(unittest.TestCase): ...@@ -38,7 +46,7 @@ class TestChannel(unittest.TestCase):
self.assertEqual(ch1.get_sink(), [ele]) self.assertEqual(ch1.get_sink(), [ele])
def test_set_sink_null(self): def test_set_sink_null(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
ele = "This is a test" ele = "This is a test"
ch1.add_sink(ele) ch1.add_sink(ele)
...@@ -47,7 +55,7 @@ class TestChannel(unittest.TestCase): ...@@ -47,7 +55,7 @@ class TestChannel(unittest.TestCase):
self.assertEqual(ch1.get_sink(), []) self.assertEqual(ch1.get_sink(), [])
def test_remove_element_from_sink(self): def test_remove_element_from_sink(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
ele = "This is a test" ele = "This is a test"
ch1.add_sink(ele) ch1.add_sink(ele)
...@@ -56,7 +64,7 @@ class TestChannel(unittest.TestCase): ...@@ -56,7 +64,7 @@ class TestChannel(unittest.TestCase):
self.assertEqual(ch1.get_sink(), []) self.assertEqual(ch1.get_sink(), [])
def test_equal(self): def test_equal(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
ch1_1 = Channel(name = "ch1", origin = wf1) ch1_1 = Channel(name = "ch1", origin = wf1)
ch2 = Channel(name = "ch2", origin = wf1) ch2 = Channel(name = "ch2", origin = wf1)
...@@ -64,7 +72,7 @@ class TestChannel(unittest.TestCase): ...@@ -64,7 +72,7 @@ class TestChannel(unittest.TestCase):
self.assertFalse(ch1.equal(channel=ch2)) self.assertFalse(ch1.equal(channel=ch2))
def test_get_structure(self): def test_get_structure(self):
wf1 = Nextflow_File("tests/ressources/channel/empty_wf.nf", display_info=False) wf1 = EmptyNextflowFile()
ch1 = Channel(name = "ch1", origin = wf1) ch1 = Channel(name = "ch1", origin = wf1)
dico = {} dico = {}
dico['nodes'] = [] dico['nodes'] = []
......
...@@ -7,7 +7,7 @@ from bioflow_insight_cli.main import cli ...@@ -7,7 +7,7 @@ from bioflow_insight_cli.main import cli
class TestCall(unittest.TestCase): class TestCall(unittest.TestCase):
def test_cli_works(self): def test_cli_works(self):
cli("./wf_test/main.nf", render_graphs=True) #cli("./wf_test/main.nf", render_graphs=False)
cli("./wf_test/main.nf", render_graphs=False) cli("./wf_test/main.nf", render_graphs=False)
def test_cli_output_considered(self): def test_cli_output_considered(self):
......
...@@ -3,25 +3,14 @@ from src.code_ import * ...@@ -3,25 +3,14 @@ from src.code_ import *
class TestCode(unittest.TestCase): class TestCode(unittest.TestCase):
def test_initialise(self):
with open("tests/ressources/outils/remove_comments_with.nf", 'r') as f:
code_with_comments = f.read()
with open("tests/ressources/outils/remove_comments_wo.nf", 'r') as f:
code_wo_comments = f.read()
code = Code(code_with_comments, origin=None)
self.assertIsInstance(code, Code)
self.assertEqual(code.code, '\n'+code_with_comments+'\n')
self.assertEqual(code.code_wo_comments, '\n'+code_wo_comments+'\n')
def test_get_code(self): def test_get_code(self):
with open("tests/ressources/outils/remove_comments_with.nf", 'r') as f: with open("tests/ressources/outils/remove_comments_with.nf", 'r') as f:
code_with_comments = f.read() code_with_comments = f.read()
with open("tests/ressources/outils/remove_comments_wo.nf", 'r') as f: with open("tests/ressources/outils/remove_comments_wo.nf", 'r') as f:
code_wo_comments = f.read() code_wo_comments = f.read()
code = Code(code_with_comments, origin=None) code = Code(code_with_comments, origin=None)
self.assertEqual(code.code, '\n'+code_with_comments+'\n')
self.assertEqual(code.code_wo_comments.strip(), code_wo_comments.strip())
self.assertEqual(code.get_code(), code_wo_comments.strip()) self.assertEqual(code.get_code(), code_wo_comments.strip())
import os
import unittest import unittest
from src.outils import * from src.outils import *
...@@ -36,6 +37,10 @@ class TestOutils(unittest.TestCase): ...@@ -36,6 +37,10 @@ class TestOutils(unittest.TestCase):
with open("tests/ressources/outils/remove_comments_wo.nf", 'r') as f: with open("tests/ressources/outils/remove_comments_wo.nf", 'r') as f:
code_wo_comments = f.read() code_wo_comments = f.read()
self.assertEqual(remove_comments(code_with_comments), code_wo_comments)
produced = remove_comments(code_with_comments)
with open(candidate := "tests/ressources/outils/remove_comments_wo.candidate.nf", 'w') as f:
f.write(produced)
self.assertEqual(produced.strip(), code_wo_comments.strip())
os.unlink(candidate)
...@@ -10,20 +10,20 @@ class TestProcess(unittest.TestCase): ...@@ -10,20 +10,20 @@ class TestProcess(unittest.TestCase):
def test_initialise_name(self): def test_initialise_name(self):
#DSL1 #DSL1
file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL1 = file.processes[0] process_DSL1 = file.processes[0]
self.assertEqual(process_DSL1.get_name(), "cleanSpeciesTree") self.assertEqual(process_DSL1.get_name(), "cleanSpeciesTree")
self.assertEqual(process_DSL1.get_alias(), "cleanSpeciesTree") self.assertEqual(process_DSL1.get_alias(), "cleanSpeciesTree")
#DSL2 #DSL2
file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False, DSL = "DSL2")
file.initialise() file.initialise()
process_DSL2 = file.processes[0] process_DSL2 = file.processes[0]
self.assertEqual(process_DSL2.get_name(), "OPENMS_FALSEDISCOVERYRATE") self.assertEqual(process_DSL2.get_name(), "OPENMS_FALSEDISCOVERYRATE")
self.assertEqual(process_DSL2.get_alias(), "OPENMS_FALSEDISCOVERYRATE") self.assertEqual(process_DSL2.get_alias(), "OPENMS_FALSEDISCOVERYRATE")
def test_set_alias(self): def test_set_alias(self):
file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False, DSL = "DSL2")
file.initialise() file.initialise()
process_DSL2 = file.processes[0] process_DSL2 = file.processes[0]
self.assertEqual(process_DSL2.get_alias(), "OPENMS_FALSEDISCOVERYRATE") self.assertEqual(process_DSL2.get_alias(), "OPENMS_FALSEDISCOVERYRATE")
...@@ -35,24 +35,24 @@ class TestProcess(unittest.TestCase): ...@@ -35,24 +35,24 @@ class TestProcess(unittest.TestCase):
def test_which_DSL(self): def test_which_DSL(self):
#DSL1 #DSL1
file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL1 = file.processes[0] process_DSL1 = file.processes[0]
self.assertEqual(process_DSL1.which_DSL(), "DSL1") self.assertEqual(process_DSL1.which_DSL(), "DSL1")
#DSL2 #DSL2
file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL2 = file.processes[0] process_DSL2 = file.processes[0]
self.assertEqual(process_DSL2.which_DSL(), "DSL2") self.assertEqual(process_DSL2.which_DSL(), "DSL2")
def test_is_initialised(self): def test_is_initialised(self):
#DSL1 #DSL1
file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL1 = file.processes[0] process_DSL1 = file.processes[0]
self.assertTrue(process_DSL1.is_initialised()) self.assertTrue(process_DSL1.is_initialised())
#DSL2 #DSL2
file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False, DSL = "DSL2")
file.initialise() file.initialise()
process_DSL2 = file.processes[0] process_DSL2 = file.processes[0]
self.assertTrue(process_DSL2.is_initialised()) self.assertTrue(process_DSL2.is_initialised())
...@@ -60,12 +60,12 @@ class TestProcess(unittest.TestCase): ...@@ -60,12 +60,12 @@ class TestProcess(unittest.TestCase):
def test_get_type(self): def test_get_type(self):
#DSL1 #DSL1
file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL1 = file.processes[0] process_DSL1 = file.processes[0]
self.assertEqual(process_DSL1.get_type(), "Process") self.assertEqual(process_DSL1.get_type(), "Process")
#DSL2 #DSL2
file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False, DSL = "DSL2")
file.initialise() file.initialise()
process_DSL2 = file.processes[0] process_DSL2 = file.processes[0]
self.assertEqual(process_DSL2.get_type(), "Process") self.assertEqual(process_DSL2.get_type(), "Process")
...@@ -74,7 +74,7 @@ class TestProcess(unittest.TestCase): ...@@ -74,7 +74,7 @@ class TestProcess(unittest.TestCase):
def test_get_structure(self): def test_get_structure(self):
#DSL1 #DSL1
file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL1 = file.processes[0] process_DSL1 = file.processes[0]
dico = {} dico = {}
...@@ -82,10 +82,11 @@ class TestProcess(unittest.TestCase): ...@@ -82,10 +82,11 @@ class TestProcess(unittest.TestCase):
dico['edges'] = [] dico['edges'] = []
dico['subworkflows'] = {} dico['subworkflows'] = {}
process_DSL1.get_structure(dico) process_DSL1.get_structure(dico)
dico_true = {'nodes': [{'id': str(process_DSL1), 'name': 'cleanSpeciesTree', 'shape': 'ellipse', 'xlabel': ''}], 'edges': [], 'subworkflows': {}} dico_true = {'nodes': [{'id': str(process_DSL1), 'name': 'cleanSpeciesTree', 'shape': 'ellipse', 'xlabel': '', 'fillcolor': ''}], 'edges': [], 'subworkflows': {}}
self.assertEqual(dico, dico_true) self.assertEqual(dico, dico_true)
#DSL2 #DSL2
file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL2.nf", display_info=False, DSL = "DSL2")
file.initialise() file.initialise()
process_DSL2 = file.processes[0] process_DSL2 = file.processes[0]
dico = {} dico = {}
...@@ -93,11 +94,11 @@ class TestProcess(unittest.TestCase): ...@@ -93,11 +94,11 @@ class TestProcess(unittest.TestCase):
dico['edges'] = [] dico['edges'] = []
dico['subworkflows'] = {} dico['subworkflows'] = {}
process_DSL2.get_structure(dico) process_DSL2.get_structure(dico)
dico_true = {'nodes': [{'id': str(process_DSL2), 'name': 'OPENMS_FALSEDISCOVERYRATE', 'shape': 'ellipse', 'xlabel': ''}], 'edges': [], 'subworkflows': {}} dico_true = {'nodes': [{'id': str(process_DSL2), 'name': 'OPENMS_FALSEDISCOVERYRATE', 'shape': 'ellipse', 'xlabel': '', 'fillcolor': ''}], 'edges': [], 'subworkflows': {}}
self.assertEqual(dico, dico_true) self.assertEqual(dico, dico_true)
def test_(self): def test_(self):
file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False) file = Nextflow_File("tests/ressources/process/process_DSL1.nf", display_info=False, DSL = "DSL1")
file.initialise() file.initialise()
process_DSL1 = file.processes[0] process_DSL1 = file.processes[0]
......
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