# 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/framework/utils.py
# def _script_api_log_file(job_name):
# def console_url(api, job_name, num):
# def result_msg(api, job_name, num=None):
# def build_started_msg(api, job_name, num, invocation_number=0):
# def kill_current_msg(api, job_name, num):
# def build_queued_msg(api, job_name, num):
# def replace_host_port(api_type, contains_url):
# def lines_in(api_type, text, *expected_lines):
# def flow_graph_dir(flow_name):


from pytest import raises
from jenkinsflow.flow import parallel, serial, FailedChildJobException, FailedChildJobsException
from .framework import api_select, utils
def test_retry_serial_through_parent_serial_level_fail(api_type):
    with api_select.api(__file__, api_type) as api:
        api.flow_job()
        api.job('j31_fail', max_fails=4, expect_invocations=4, expect_order=1)
        api.job('j32', max_fails=0, expect_invocations=0, expect_order=None)

        with raises(FailedChildJobException):
            with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1:
                with ctrl1.serial(timeout=70, max_tries=2) as ctrl2:
                    with ctrl2.serial(timeout=70, max_tries=2) as ctrl3:
                        ctrl3.invoke('j31_fail')
                        ctrl3.invoke('j32')


def test_retry_serial_through_parent_parallel_level(api_type):
    with api_select.api(__file__, api_type) as api:
        api.flow_job()
        api.job('j11', max_fails=0, expect_invocations=1, expect_order=1)
        api.job('j21', max_fails=0, expect_invocations=1, expect_order=2, serial=True)
        api.job('j31_fail', max_fails=2, expect_invocations=3, expect_order=2)

        with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1:
            ctrl1.invoke('j11')
            with ctrl1.parallel(timeout=70, max_tries=2) as ctrl2:
                ctrl2.invoke('j21')
                with ctrl2.serial(timeout=70, max_tries=2) as ctrl3:
                    ctrl3.invoke('j31_fail')


def test_retry_serial_through_parent_parallel_level_fail(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/framework/utils.py
# def _script_api_log_file(job_name):
# def console_url(api, job_name, num):
# def result_msg(api, job_name, num=None):
# def build_started_msg(api, job_name, num, invocation_number=0):
# def kill_current_msg(api, job_name, num):
# def build_queued_msg(api, job_name, num):
# def replace_host_port(api_type, contains_url):
# def lines_in(api_type, text, *expected_lines):
# def flow_graph_dir(flow_name):


# Path: test/retry_test.py
from pytest import raises
from jenkinsflow.flow import parallel, serial, FailedChildJobException, FailedChildJobsException
from .framework import api_select, utils

def test_retry_serial_through_parent_serial_level_fail(api_type):
    with api_select.api(__file__, api_type) as api:
        api.flow_job()
        api.job('j31_fail', max_fails=4, expect_invocations=4, expect_order=1)
        api.job('j32', max_fails=0, expect_invocations=0, expect_order=None)

        with raises(FailedChildJobException):
            with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1:
                with ctrl1.serial(timeout=70, max_tries=2) as ctrl2:
                    with ctrl2.serial(timeout=70, max_tries=2) as ctrl3:
                        ctrl3.invoke('j31_fail')
                        ctrl3.invoke('j32')


def test_retry_serial_through_parent_parallel_level(api_type):
    with api_select.api(__file__, api_type) as api:
        api.flow_job()
        api.job('j11', max_fails=0, expect_invocations=1, expect_order=1)
        api.job('j21', max_fails=0, expect_invocations=1, expect_order=2, serial=True)
        api.job('j31_fail', max_fails=2, expect_invocations=3, expect_order=2)

        with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1:
            ctrl1.invoke('j11')
            with ctrl1.parallel(timeout=70, max_tries=2) as ctrl2:
                ctrl2.invoke('j21')
                with ctrl2.serial(timeout=70, max_tries=2) as ctrl3:
                    ctrl3.invoke('j31_fail')


def test_retry_serial_through_parent_parallel_level_fail(api_type):

    with api_select.api(__file__, api_type) as api: