def test_platform_specific_graph(mocker, testing_conda_resolve):
    """the recipes herein have selectors on dependencies.  We're making sure they work correctly.

    build:
      b -> a
      c -> b
      d -> c
      e -> d

    run:
      c -> a  # win
      e -> b  # win64
    """

    # the 32-bit here the platform doesn't actually determine the output target_platform.
    worker = {'platform': 'win', 'arch': '32', 'label': 'worker'}
    mocker.patch.object(compute_build_graph, '_installable')
    mocker.patch.object(
        compute_build_graph, '_buildable',
        lambda name, version, recipes_dir, worker, config: os.path.join(
            recipes_dir, name))
    compute_build_graph._installable.return_value = False
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        worker,
        folders=('a', 'b', 'c', 'd', 'e'),
        run='build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)
    # left depends on right
    deps = {
        ('b-1.0-on-worker', 'a-1.0-on-worker'),
        ('c-1.0-on-worker', 'b-1.0-on-worker'),
        ('d-1.0-on-worker', 'c-1.0-on-worker'),
        ('e-1.0-on-worker', 'd-1.0-on-worker'),
        ('c-1.0-on-worker', 'a-1.0-on-worker'),
    }
    assert set(g.edges()) == deps
    worker['arch'] = '64'
    # this dependency is only present with a selector on win-64
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        worker,
        folders=('a', 'b', 'c', 'd', 'e'),
        run='build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)
    # left depends on right
    deps = {
        ('b-1.0-on-worker', 'a-1.0-on-worker'),
        ('c-1.0-on-worker', 'b-1.0-on-worker'),
        ('d-1.0-on-worker', 'c-1.0-on-worker'),
        ('e-1.0-on-worker', 'd-1.0-on-worker'),
        ('c-1.0-on-worker', 'a-1.0-on-worker'),
        ('e-1.0-on-worker', 'b-1.0-on-worker'),
    }
    assert set(g.edges()) == deps
def test_expand_run_build_non_installable_prereq(mocker,
                                                 testing_conda_resolve):
    mocker.patch.object(compute_build_graph, '_installable')
    compute_build_graph._installable.return_value = False
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        dummy_worker,
        folders=('b', ),
        run='build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)

    compute_build_graph.expand_run(g,
                                   Config(),
                                   testing_conda_resolve,
                                   run='build',
                                   worker=dummy_worker,
                                   recipes_dir=graph_data_dir)
    assert set(g.nodes()) == {'a-1.0-on-linux', 'b-1.0-on-linux'}

    compute_build_graph.expand_run(g,
                                   Config(),
                                   testing_conda_resolve,
                                   run='build',
                                   worker=dummy_worker,
                                   recipes_dir=graph_data_dir,
                                   matrix_base_dir=test_config_dir,
                                   steps=1)
    assert set(
        g.nodes()) == {'a-1.0-on-linux', 'b-1.0-on-linux', 'c-1.0-on-linux'}
def test_expand_run_all_steps_down(mocker, testing_graph,
                                   testing_conda_resolve):
    """
    Should build/test/upload all of the recipes.
    Start with B
    B depends on A, so build A
    Step down the tree from B to C
    Step down the tree from C to D
    Step down the tree from D to E
    """
    mocker.patch.object(compute_build_graph, '_installable')
    compute_build_graph._installable.return_value = False
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        dummy_worker,
        folders=('b', ),
        run='build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)

    compute_build_graph.expand_run(g,
                                   Config(),
                                   testing_conda_resolve,
                                   run='build',
                                   worker=dummy_worker,
                                   recipes_dir=graph_data_dir,
                                   matrix_base_dir=test_config_dir,
                                   max_downstream=-1,
                                   steps=-1)
    assert set(g.nodes()) == {
        'a-1.0-on-linux', 'b-1.0-on-linux', 'c-1.0-on-linux', 'd-1.0-on-linux',
        'e-1.0-on-linux'
    }
def test_construct_graph(mocker, testing_conda_resolve):
    mocker.patch.object(compute_build_graph, '_installable')
    compute_build_graph._installable.return_value = True
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        worker=dummy_worker,
        run='build',
        folders=('b'),
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)
    assert set(g.nodes()) == set(['b-1.0-on-linux'])
def test_run_test_graph(testing_conda_resolve):
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        dummy_worker,
        folders=('a', 'b', 'c'),
        run='test',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)
    assert set(g.nodes()) == set([
        'c3itest-a-1.0-on-linux', 'c3itest-b-1.0-on-linux',
        'c3itest-c-1.0-on-linux'
    ])
def test_version_matching(testing_conda_resolve):
    g = compute_build_graph.construct_graph(
        os.path.join(test_data_dir, 'version_resolution'),
        dummy_worker,
        folders=('upstream-1.0', 'upstream-2.0', 'downstream'),
        run='build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)
    assert len(g.nodes()) == 4
    assert ('downstream-1.0-upstream_1.0-on-linux',
            'upstream-1.0.1-on-linux') in g.edges()
    assert ('downstream-1.0-upstream_2.0-on-linux',
            'upstream-2.0.2-on-linux') in g.edges()
def test_construct_graph_relative_path(testing_git_repo,
                                       testing_conda_resolve):
    g = compute_build_graph.construct_graph(
        '.',
        dummy_worker,
        'build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)
    assert set(g.nodes()) == {
        'test_dir_3-1.0-on-linux', 'test_dir_2-1.0-on-linux',
        'test_dir_1-1.0-on-linux'
    }
    assert set(g.edges()) == {
        ('test_dir_2-1.0-on-linux', 'test_dir_1-1.0-on-linux'),
        ('test_dir_3-1.0-on-linux', 'test_dir_2-1.0-on-linux')
    }
def test_expand_run_two_steps_down(mocker, testing_graph,
                                   testing_conda_resolve):
    mocker.patch.object(compute_build_graph, '_installable')
    compute_build_graph._installable.return_value = False
    # second expansion - one more layer out
    g = compute_build_graph.construct_graph(
        graph_data_dir,
        dummy_worker,
        folders=('a', ),
        run='build',
        matrix_base_dir=test_config_dir,
        conda_resolve=testing_conda_resolve)

    compute_build_graph.expand_run(g,
                                   testing_conda_resolve,
                                   run='build',
                                   worker=dummy_worker,
                                   recipes_dir=graph_data_dir,
                                   matrix_base_dir=test_config_dir,
                                   steps=2)
    assert set(
        g.nodes()) == {'a-1.0-on-linux', 'b-1.0-on-linux', 'c-1.0-on-linux'}