Exemplo n.º 1
0
def test_multi_named_output(clear_now_and_after):
    '''Test DAG built from multiple named_output #1166'''
    clear_now_and_after('a.txt', 'b.txt', 'test_named_output.dot')

    execute_workflow('''
        [A]
        output: A='a.txt', B='b.txt'
        _output.touch()

        [default]
        input: named_output('A'), named_output('B')
        ''',
                     options={'output_dag': 'test_named_output.dot'})
    # note that A2 is no longer mentioned
    assertDAG('test_named_output.dot', [
        '''
        strict digraph "" {
        default;
        "A (B)";
        "A (B)" -> default;
        }
        ''', '''
        strict digraph "" {
        default;
        "A (A)";
        "A (A)" -> default;
        }
        '''
    ])
Exemplo n.º 2
0
def testRun():
    '''Test action run'''
    execute_workflow(r'''
        [0]
        run:
        echo 'Echo'
        ''')
Exemplo n.º 3
0
def test_remote_exec_named_path(clear_now_and_after):
    clear_now_and_after("result_named_path.txt")
    root_dir = "/root/build" if "TRAVIS" in os.environ else "/root"

    execute_workflow(
        """
        output: '#home/result_named_path.txt'

        task:
        sh: expand=True
            echo Output: {_output} > {_output}
            echo PWD: `pwd`. >> {_output}
        """,
        options={
            "config_file": "~/docker.yml",
            "default_queue": "docker",
            "sig_mode": "force",
        },
    )
    assert file_target("#home/result_named_path.txt").target_exists()
    with open(file_target("#home/result_named_path.txt")) as res:
        result = res.read()
        print(result)
        assert "Output: /root/result_named_path.txt" in result
        assert f"PWD: {root_dir}/vatlab/sos/test." in result
Exemplo n.º 4
0
def testAcceptableArgs():
    '''test acceptable args of options'''
    with pytest.raises(Exception):
        execute_workflow(r"""
            run: unrecog=1
            echo 'a'
            """)
Exemplo n.º 5
0
def testRunWithShebang():
    execute_workflow(r'''
        [0]
        run:
        #!/usr/bin/env python
        print('Echo')
        ''')
Exemplo n.º 6
0
def test_to_host_option_with_named_path(clear_now_and_after):
    """Test from_remote option"""
    clear_now_and_after(
        os.path.expanduser("~/to_host_named_testfile.txt"),
        "to_host_named_linecount.txt",
    )
    with open(os.path.expanduser("~/to_host_named_testfile.txt"), "w") as tf:
        for i in range(200):
            tf.write(f"line {i+1}\n")
    execute_workflow(
        """
        [10]
        output: 'to_host_named_linecount.txt'
        task: to_host='#home/to_host_named_testfile.txt'
        sh:
            wc -l ~/to_host_named_testfile.txt > to_host_named_linecount.txt
        """,
        options={
            "config_file": "~/docker.yml",
            "default_queue": "docker",
            "sig_mode": "force",
        },
    )
    assert os.path.isfile("to_host_named_linecount.txt")
    with open("to_host_named_linecount.txt") as lc:
        assert lc.read().strip().startswith("200")
Exemplo n.º 7
0
def test_bash_in_docker():
    '''Test action bash in docker environment'''
    execute_workflow(r'''
        [0]
        run:  container='docker://ubuntu'
        echo 'Echo'
        ''')
Exemplo n.º 8
0
def test_python2():
    execute_workflow(r'''
        [0]
        python2: expand='${ }'
        a = {'1', '2'}
        print a
        ''')
Exemplo n.º 9
0
def test_rmarkdown(clear_now_and_after):
    """Test action Rmarkdown"""
    if not R_library('rmarkdown1').target_exists():
        pytest.xfail('rmarkdown is not properly installed.')

    clear_now_and_after("myreport.html")
    execute_workflow(
        r"""
        [10]

        report:
        ## Some random figure

        Generated by matplotlib


        [100]
        # generate report
        output: 'myreport.html'
        Rmarkdown(output=_output[0])
        """,
        options={"report_output": "report.md"},
    )

    assert os.path.isfile("myreport.html")
Exemplo n.º 10
0
def test_delayed_interpolation(clear_now_and_after):
    """Test delayed interpolation with expression involving remote objects"""
    # purge all previous tasks
    clear_now_and_after('test.py', 'test.py.bak')
    execute_workflow(
        """
        [10]
        output: remote('test.py')
        task:
        run:
            touch test.py

        [20]
        output: remote(f"{_input:R}.bak")
        task:
        run: expand=True
            cp {_input} {_output}
        """, options={
            "config_file": "~/docker.yml",
            # do not wait for jobs
            "wait_for_task": True,
            "default_queue": "docker",
            "sig_mode": "force",
        },
    )
    # this file is remote only
    assert not os.path.isfile("test.py")
    assert not os.path.isfile("test.py.bak")
Exemplo n.º 11
0
def testRegenerateReport(clear_now_and_after):
    '''Testing the regeneration of report once is needed. The problem
    here is the 'input' parameter of report.'''
    clear_now_and_after('a1.md', 'a2.md', 'out.md')
    script = r'''
        [A_1]
        output: 'a1.txt', 'a1.md'
        run:
        echo 'a1' >> a1.txt

        report: output='a1.md'
        a1

        [A_2]
        output: 'a2.txt', 'a2.md'
        run:
        echo 'a2' >> a2.txt
        report: output='a2.md'
        a2

        [A_3]
        input: 'a1.md', 'a2.md'
        output: 'out.md'
        report:     input=['a1.md', 'a2.md'], output='out.md'
        '''
    execute_workflow(script)
    with open('a1.md') as a:
        assert a.read() == 'a1\n\n'
    with open('a2.md') as a:
        assert a.read() == 'a2\n\n'
    with open('out.md') as a:
        assert a.read() == 'a1\n\na2\n\n'

    clear_now_and_after('a1.md', 'a2.md', 'out.md')
    execute_workflow(script)
Exemplo n.º 12
0
def testGetOutput():
    '''Test utility function get_output'''
    execute_workflow(r"""
        [0: shared='ret']
        ret = get_output('echo blah')
        """)
    # use strip because there would be \r\n under windows
    assert env.sos_dict['ret'].strip() == 'blah'

    execute_workflow(r"""
        [0: shared='ret']
        ret = get_output('echo blah', show_command=True)
        """)
    assert [x.strip() for x in env.sos_dict['ret'].splitlines()
            ] == ['$ echo blah', 'blah']

    execute_workflow(r"""
        [0: shared='ret']
        ret = get_output('echo blah', show_command=True, prompt='% ')
        """)
    assert [x.strip() for x in env.sos_dict['ret'].splitlines()
            ] == ['% echo blah', 'blah']

    with pytest.raises(Exception):
        execute_workflow(r"""
            [0]
            get_output('catmouse')
        """)

    with pytest.raises(Exception):
        execute_workflow(r"""
            [0]
            ret = get_output('cat -h')
            """)
Exemplo n.º 13
0
def test_r_library():
    """Test target R_Library"""
    execute_workflow("""
        [default]
        depends: R_library("dplyr", autoinstall=True)
        R:
            library('dplyr')
        """)
Exemplo n.º 14
0
def test_action_option_template():
    if os.path.isfile('template_output.txt'):
        os.remove('template_output.txt')
    execute_workflow('''
run:  template='cat {filename}'
    echo 'whatever' > template_output.txt
''')
    assert not os.path.isfile('template_output.txt')
Exemplo n.º 15
0
def test_docker_script_action():
    '''Test action sh in docker environment'''
    # test docker
    execute_workflow(r'''
        [0]
        script: container='docker://ubuntu', args='{script}'
        echo 'Echo'
        ''')
Exemplo n.º 16
0
def test_node():
    '''Test action node'''
    execute_workflow(r'''
        [0]
        node:
        var args = process.argv.slice(2);
        console.log('Hello ' + args.join(' ') + '!');
        ''')
Exemplo n.º 17
0
def test_run_1():

    with pytest.raises(Exception):
        execute_workflow(r'''
            [0]
            run:
            echo 'Echo
            ''')
Exemplo n.º 18
0
def test_action_option_template(clear_now_and_after):
    clear_now_and_after('template_output.txt')

    execute_workflow('''
        run:  template='cat {filename}'
            echo 'whatever' > template_output.txt
        ''')
    assert not os.path.isfile('template_output.txt')
Exemplo n.º 19
0
def test_auto_output_mount():
    '''Test use of option port in action'''
    execute_workflow(r'''
        output: '../data/1.txt'
        run: container='ubuntu'
        sh: expand=True
            touch {_output}
        ''')
    assert os.path.isfile('../data/1.txt')
Exemplo n.º 20
0
def test_to_named_path_path():
    execute_workflow("""
        [10: shared="a"]
        a = path('/root/xxx/whatever').to_named_path(host='docker')
        """,
                     options={
                         "config_file":
                         os.path.join(os.path.expanduser("~"), "docker.yml"),
                     })
    assert env.sos_dict['a'] == '#home/xxx/whatever'
Exemplo n.º 21
0
    def testProvidesSoSVariable(self):
        '''Test provides non-filename targets #1341'''
        execute_workflow('''
[count: provides=sos_variable('numNotebooks')]
numNotebooks = 1

[default]
depends: sos_variable('numNotebooks')
print(f"There are {numNotebooks} notebooks in this directory")
        ''')
Exemplo n.º 22
0
 def pull_images(self, containers):
     for container, engine in containers:
         script = f'[container]\nrun: stderr=False, stdout=False, container={repr(container)}'
         if not engine is None:
             script += f', engine={repr(engine)}'
         script += '\n  dsc -h'
         try:
             execute_workflow(script, workflow='container', options=dict(verbosity=1))
         except Exception as e:
             raise  ModuleNotFoundError(f'Please make sure ``{container}`` is available (locally or online) and has DSC software (including R package dscrutils) installed for use in DSC environment.')
Exemplo n.º 23
0
def test_report_5(clear_now_and_after):
    '''Test action report'''
    clear_now_and_after('a.txt')

    execute_workflow(r'''
        [A_1]
        output: 'a.txt'
        report: output=_output[0]
        something
        ''')
Exemplo n.º 24
0
def test_report_4(clear_now_and_after):
    '''Test action report'''
    clear_now_and_after('a.txt')

    # test report to other types of output: path
    execute_workflow(r'''
        [A_1]
        report: output=path('a.txt')
        something
        ''')
Exemplo n.º 25
0
    def test_group_with_with_no_output(self):
        execute_workflow(r'''
[10]
input: for_each=dict(i=range(3))
output: group_with=dict(var=['A', 'B', 'C'][_index])
print(i)

[20]
print(f'Input is {_input} {var}')
''')
Exemplo n.º 26
0
def testPerl():
    '''Test action perl'''
    execute_workflow(r'''
        [0]
        perl:
        use strict;
        use warnings;

        print "hi NAME\n";
        ''')
Exemplo n.º 27
0
def test_rmarkdown_to_stdout():
    if not R_library('rmarkdown1').target_exists():
        pytest.xfail('rmarkdown is not properly installed.')
    execute_workflow(
        r"""
        # generate report
        Rmarkdown:
            # this is title
        """
    )
Exemplo n.º 28
0
def test_report_6(clear_now_and_after):
    '''Test action report'''
    clear_now_and_after('a.txt')

    # test report to other types of output: sos_targets
    execute_workflow(r'''
        [A_1]
        output: 'a.txt'
        report: output=_output
        something
        ''')
Exemplo n.º 29
0
def test_report_7(clear_now_and_after):
    '''Test action report'''
    clear_now_and_after('a.txt')

    with pytest.raises(Exception):
        execute_workflow(r'''
            [A_1]
            output: 'a.txt', 'b.txt'
            report: output=_output
            something
            ''')
Exemplo n.º 30
0
def test_global_vars(config_factory):
    '''Test SoS defined variables'''
    execute_workflow("[0]", options={'mode': 'dryrun'})

    assert env.sos_dict['SOS_VERSION'] == __version__
    assert isinstance(env.sos_dict['CONFIG'], dict)

    cfg = config_factory({'my_config': 5})

    execute_workflow("[0]", options={'config_file': cfg})
    assert env.sos_dict['CONFIG']['my_config'] == 5