Skip to content

Commit

Permalink
Allow action option "active" to accept True/False conditions #914
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Mar 7, 2018
1 parent 7e4484d commit cd86e00
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 25 deletions.
53 changes: 53 additions & 0 deletions test/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import os
import sys
import glob
import unittest
import shutil

Expand Down Expand Up @@ -601,5 +602,57 @@ def testRegenerateReport(self):
Base_Executor(wf).run()


def testActiveActionOption(self):
'''Test the active option of actions'''
# disallow
self.assertRaises(Exception, SoS_Script, '''
[1]
rep = range(5)
input: for_each = 'rep'
# ff should change and be usable inside run
ff = f"{_rep}.txt"
run: expand=True, active=1,2
echo {ff}
touch temp/{ff}
''')
#
for active, result in [
('0', ['temp/0.txt']),
('-1', ['temp/4.txt']),
('(1,2)', ['temp/1.txt', 'temp/2.txt']),
('[2,3]', ['temp/2.txt', 'temp/3.txt']),
('(0,2,4)', ['temp/0.txt', 'temp/2.txt', 'temp/4.txt']),
('slice(1,None)', ['temp/1.txt', 'temp/2.txt', 'temp/3.txt', 'temp/4.txt']),
('slice(1,-2)', ['temp/1.txt', 'temp/2.txt']),
('slice(None,None,2)', ['temp/0.txt', 'temp/2.txt', 'temp/4.txt']),
('True', ['temp/0.txt', 'temp/1.txt', 'temp/2.txt', 'temp/3.txt', 'temp/4.txt']),
('False', []),
]:
if os.path.isdir('temp'):
shutil.rmtree('temp')
os.mkdir('temp')
# test first iteration
script = SoS_Script(('''
[1]
rep = range(5)
input: for_each = 'rep'
# ff should change and be usable inside run
ff = f"{_rep}.txt"
run: expand=True, active=%s
echo {ff}
touch temp/{ff}
''' % active).replace('/', os.sep))
wf = script.workflow()
env.config['sig_mode'] = 'force'
env.config['wait_for_task'] = True
Base_Executor(wf).run()
files = list(glob.glob(os.path.join('temp', '*.txt')))
self.assertEqual(sorted(files), sorted([x.replace('/', os.sep) for x in result]))
#
# test last iteration
shutil.rmtree('temp')



if __name__ == '__main__':
unittest.main()
26 changes: 1 addition & 25 deletions test/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def testPrependPath(self):
Base_Executor(wf).run()


def testActiveActionOption(self):
def testActiveTaskOption(self):
'''Test the active option of actions'''
# disallow
self.assertRaises(ParsingError, SoS_Script, '''
Expand All @@ -212,30 +212,6 @@ def testActiveActionOption(self):
if os.path.isdir('temp'):
shutil.rmtree('temp')
os.mkdir('temp')
# test first iteration
script = SoS_Script(('''
[1]
rep = range(5)
input: for_each = 'rep'
# ff should change and be usable inside run
ff = f"{_rep}.txt"
run: expand=True, active=%s
echo {ff}
touch temp/{ff}
''' % active).replace('/', os.sep))
wf = script.workflow()
env.config['sig_mode'] = 'force'
env.config['wait_for_task'] = True
Host.reset()
Base_Executor(wf).run()
files = list(glob.glob(os.path.join('temp', '*.txt')))
self.assertEqual(sorted(files), sorted([x.replace('/', os.sep) for x in result]))
#
# test last iteration
shutil.rmtree('temp')
#
# test active option for task
os.mkdir('temp')
script = SoS_Script(('''
[1]
rep = range(5)
Expand Down

0 comments on commit cd86e00

Please sign in to comment.