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()
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
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
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
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
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