# Path: test/framework/api_select.py
# def api(file_name, api_type, login=None, fixed_prefix=None, url_or_dir=None, fake_public_uri=None, invocation_class=None,
#         username=None, password=None):


from pytest import raises
from jenkinsflow.flow import parallel, serial, FlowTimeoutException
from .framework import api_select
# Copyright (c) 2012 - 2015 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.




def test_timeout_top_level_serial(api_type):
    with api_select.api(__file__, api_type, login=True) as api:
        api.job('quick', max_fails=0, expect_invocations=1, expect_order=None, params=(('s1', '', 'desc'), ('c1', 'false', 'desc')))
        api.job('wait20', max_fails=0, expect_invocations=1, expect_order=None, exec_time=20, unknown_result=True, serial=True)

        with raises(FlowTimeoutException):
            with serial(api, timeout=8, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl:
                ctrl.invoke('quick', s1='', c1=False)
                ctrl.invoke('wait20')


def test_timeout_top_level_parallel(api_type):
    with api_select.api(__file__, api_type, login=True) as api:
        api.job('quick', max_fails=0, expect_invocations=1, expect_order=None, params=(('s1', '', 'desc'), ('c1', 'false', 'desc')))
        api.job('wait20', max_fails=0, expect_invocations=1, expect_order=None, exec_time=20, unknown_result=True)

        with raises(FlowTimeoutException):
            with parallel(api, timeout=8, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl:
                ctrl.invoke('quick', s1='', c1=False)
                ctrl.invoke('wait20')


def test_timeout_inner_level_serial(api_type):

# Path: test/framework/api_select.py
# def api(file_name, api_type, login=None, fixed_prefix=None, url_or_dir=None, fake_public_uri=None, invocation_class=None,
#         username=None, password=None):


# Path: test/timeout_test.py
from pytest import raises
from jenkinsflow.flow import parallel, serial, FlowTimeoutException
from .framework import api_select

# Copyright (c) 2012 - 2015 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.




def test_timeout_top_level_serial(api_type):
    with api_select.api(__file__, api_type, login=True) as api:
        api.job('quick', max_fails=0, expect_invocations=1, expect_order=None, params=(('s1', '', 'desc'), ('c1', 'false', 'desc')))
        api.job('wait20', max_fails=0, expect_invocations=1, expect_order=None, exec_time=20, unknown_result=True, serial=True)

        with raises(FlowTimeoutException):
            with serial(api, timeout=8, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl:
                ctrl.invoke('quick', s1='', c1=False)
                ctrl.invoke('wait20')


def test_timeout_top_level_parallel(api_type):
    with api_select.api(__file__, api_type, login=True) as api:
        api.job('quick', max_fails=0, expect_invocations=1, expect_order=None, params=(('s1', '', 'desc'), ('c1', 'false', 'desc')))
        api.job('wait20', max_fails=0, expect_invocations=1, expect_order=None, exec_time=20, unknown_result=True)

        with raises(FlowTimeoutException):
            with parallel(api, timeout=8, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl:
                ctrl.invoke('quick', s1='', c1=False)
                ctrl.invoke('wait20')


def test_timeout_inner_level_serial(api_type):

    with api_select.api(__file__, api_type, login=True) as api: