Exemplo n.º 1
0
def test_local_diff_conditional_evaluate_no_checkpoint():
    config = {ID: 'conditional', DIFF: [{ID: 'a', PATH: 'mypath/.*'}]}
    CHECKPOINT = {}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    assert conditional.evaluate() is True
Exemplo n.º 2
0
def test_local_diff_conditional_evaluate_content():
    config = {
        ID: 'conditional',
        DIFF: [{
            ID: 'a',
            PATH: 'mypath/.*',
            CONTENT: 'name:.*'
        }],
        BRANCH: {
            ACTIVE: 'master',
            TARGET: 'testing'
        }
    }
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    conditional.repo, commits, diffs = get_repo_mock()

    result = conditional.evaluate()
    assert result is True
    conditional.repo.git.checkout.assert_called()
    conditional.repo.git.checkout.assert_any_call('testing')
    conditional.repo.git.checkout.assert_any_call('master')
    for commit in commits:
        commit.__str__.assert_called()
    conditional.repo.iter_commits.assert_called_once()
    for diff in diffs:
        diff.a_rawpath.decode.assert_called()
    conditional.repo.head.commit.diff.assert_called()
Exemplo n.º 3
0
def test_local_diff_conditional_evaluate_invalid_diff_path():
    config = {ID: 'conditional', DIFF: [{ID: 'a', 'file': 'mypath/.*'}]}
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    conditional.repo, commits, diffs = get_repo_mock()
    assert conditional.evaluate() is False
Exemplo n.º 4
0
def test_local_diff_conditional_config_no_active_target_branch():
    config = {ID: 'conditional', DIFF: [], BRANCH: {}, EXPRESSION: 'a and b'}
    CHECKPOINT = 'checkpoint'
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    assert conditional.id == config[ID]
    assert conditional.active_branch is None
    assert conditional.target_branch is None
    assert conditional.checkpoint == CHECKPOINT
    assert conditional.expression == config[EXPRESSION]
Exemplo n.º 5
0
def test_local_diff_conditional_evaluate_invalid_diff():
    config = {ID: 'conditional', DIFF: ['mypath/.*']}
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    conditional.repo, commits, diffs = get_repo_mock()

    try:
        _ = conditional.evaluate()
        pytest.fail('Conditional should not evaluate on invalid diff spec')
    except Exception as e:
        assert type(e) is ConfigError
Exemplo n.º 6
0
def test_local_diff_conditional_config_no_id():
    try:
        config = {
            DIFF: [],
            BRANCH: {
                ACTIVE: 'master',
                TARGET: 'master'
            },
            EXPRESSION: 'a and b'
        }
        CHECKPOINT = 'checkpoint'
        from plumber.operators import LocalDiffConditional
        conditional = LocalDiffConditional()
        conditional.configure(config, CHECKPOINT)
    except Exception as e:
        assert type(e) is ConfigError
Exemplo n.º 7
0
def test_local_diff_conditional_evaluate_multiple_with_expression():
    config = {
        ID: 'conditional',
        EXPRESSION: 'a and b',
        DIFF: [{
            ID: 'a',
            PATH: 'mypath/.*'
        }, {
            ID: 'b',
            PATH: 'path1/.*'
        }]
    }
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    conditional.repo, commits, diffs = get_repo_mock()
    assert conditional.evaluate() is True
Exemplo n.º 8
0
def test_local_diff_conditional_config():
    config = {
        ID: 'conditional',
        DIFF: [],
        BRANCH: {
            ACTIVE: 'master',
            TARGET: 'master'
        },
        EXPRESSION: 'a and b'
    }
    CHECKPOINT = 'checkpoint'
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    assert conditional.id == config[ID]
    assert conditional.active_branch == config[BRANCH][ACTIVE]
    assert conditional.target_branch == config[BRANCH][TARGET]
    assert conditional.checkpoint == CHECKPOINT
    assert conditional.expression == config[EXPRESSION]
Exemplo n.º 9
0
def test_local_diff_conditional_create_checkpoint():
    config = {
        ID: 'conditional',
        EXPRESSION: 'a and b',
        DIFF: [{
            ID: 'a',
            PATH: 'mypath/.*'
        }, {
            ID: 'b',
            PATH: 'path1/.*'
        }]
    }
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    from git import Repo
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    new_checkpoint = conditional.create_checkpoint()
    assert COMMIT in new_checkpoint
    assert new_checkpoint[COMMIT] == str(Repo().head.commit)
Exemplo n.º 10
0
def test_local_diff_conditional_evaluate_invalid_diff_expression_id():
    config = {
        ID: 'conditional',
        EXPRESSION: 'a',
        DIFF: [{
            ID: 'b',
            'file': 'mypath/.*'
        }]
    }
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    conditional.repo, commits, diffs = get_repo_mock()

    try:
        _ = conditional.evaluate()
        pytest.fail('Conditional should not evaluate on undefined diff id')
    except Exception as e:
        assert type(e) is NameError
Exemplo n.º 11
0
def test_local_diff_conditional_evaluate_not_active_branch():
    config = {
        ID: 'conditional',
        DIFF: [{
            ID: 'a',
            PATH: 'mypath/.*'
        }],
        BRANCH: {
            ACTIVE: 'testing',
            TARGET: 'testing'
        }
    }
    CHECKPOINT = {COMMIT: 'last-checkpoint'}
    from plumber.operators import LocalDiffConditional
    conditional = LocalDiffConditional()
    conditional.configure(config, CHECKPOINT)
    conditional.repo = MagicMock()
    conditional.repo.active_branch = 'master'

    assert conditional.evaluate() is False