# 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 flow_graph_dir(flow_name):
#     """Control which directory to put flow graph in.
# 
#     Put the generated graph in the workspace root if running from Jenkins.
#     If running from commandline put it under config.flow_graph_root_dir/flow_name
# 
#     Return: dir-name
#     """
#     return '.' if os.environ.get('JOB_NAME') else jp(flow_graph_root_dir, flow_name)
# 
# Path: test/json_test.py
# def _assert_json(got_json, expected_json, api_type):
#     got_json = utils.replace_host_port(api_type, got_json)
#     got_json = _timestamp_re.sub(r't": 12345.123', got_json)
# 
#     if api_type == ApiType.SCRIPT:
#         expected_json = utils.replace_host_port(api_type, expected_json)
# 
#     if got_json.strip() != expected_json:
#         if not os.environ.get('JOB_NAME'):
#             print("--- expected json ---")
#             print(expected_json)
#             print("--- got json ---")
#             print(got_json)
#         assert got_json.strip() == expected_json


import os
from os.path import join as jp
from jenkinsflow.flow import serial
from .framework import api_select
from .framework.utils import flow_graph_dir
from .json_test import _assert_json

    with serial(api, timeout=1, job_name_prefix=api.job_name_prefix, json_dir=json_dir, json_strip_top_level_prefix=True, just_dump=True) as ctrl1:
        ctrl1.invoke('j1')

        with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2:
            with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a:
                ctrl3a.invoke('j2')
                ctrl3a.invoke_unchecked('j3_unchecked')

            with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b:
                ctrl3b.invoke('j4')

        ctrl1.invoke('j5')

    return ctrl1


def test_just_dump_no_json(api_type):
    with api_select.api(__file__, api_type, login=True) as api:
        api.flow_job()
        api.job('j1', max_fails=0, expect_invocations=0, expect_order=None)
        api.job('j2', max_fails=0, expect_invocations=0, expect_order=None)
        api.job('j3_unchecked', max_fails=0, expect_invocations=0, expect_order=None, exec_time=40)
        api.job('j4', max_fails=0, expect_invocations=0, expect_order=None, exec_time=5)
        api.job('j5', max_fails=0, expect_invocations=0, expect_order=None, exec_time=5)

        _flow(api, None)


def test_just_dump_with_json(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 flow_graph_dir(flow_name):
#     """Control which directory to put flow graph in.
# 
#     Put the generated graph in the workspace root if running from Jenkins.
#     If running from commandline put it under config.flow_graph_root_dir/flow_name
# 
#     Return: dir-name
#     """
#     return '.' if os.environ.get('JOB_NAME') else jp(flow_graph_root_dir, flow_name)
# 
# Path: test/json_test.py
# def _assert_json(got_json, expected_json, api_type):
#     got_json = utils.replace_host_port(api_type, got_json)
#     got_json = _timestamp_re.sub(r't": 12345.123', got_json)
# 
#     if api_type == ApiType.SCRIPT:
#         expected_json = utils.replace_host_port(api_type, expected_json)
# 
#     if got_json.strip() != expected_json:
#         if not os.environ.get('JOB_NAME'):
#             print("--- expected json ---")
#             print(expected_json)
#             print("--- got json ---")
#             print(got_json)
#         assert got_json.strip() == expected_json


# Path: test/just_dump_test.py
import os
from os.path import join as jp
from jenkinsflow.flow import serial
from .framework import api_select
from .framework.utils import flow_graph_dir
from .json_test import _assert_json


    with serial(api, timeout=1, job_name_prefix=api.job_name_prefix, json_dir=json_dir, json_strip_top_level_prefix=True, just_dump=True) as ctrl1:
        ctrl1.invoke('j1')

        with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2:
            with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a:
                ctrl3a.invoke('j2')
                ctrl3a.invoke_unchecked('j3_unchecked')

            with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b:
                ctrl3b.invoke('j4')

        ctrl1.invoke('j5')

    return ctrl1


def test_just_dump_no_json(api_type):
    with api_select.api(__file__, api_type, login=True) as api:
        api.flow_job()
        api.job('j1', max_fails=0, expect_invocations=0, expect_order=None)
        api.job('j2', max_fails=0, expect_invocations=0, expect_order=None)
        api.job('j3_unchecked', max_fails=0, expect_invocations=0, expect_order=None, exec_time=40)
        api.job('j4', max_fails=0, expect_invocations=0, expect_order=None, exec_time=5)
        api.job('j5', max_fails=0, expect_invocations=0, expect_order=None, exec_time=5)

        _flow(api, None)


def test_just_dump_with_json(api_type):

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