def test_step_matches_invalid_config(given_invalid_config, expected_error_msg): """ Test match config without a sentence and a should_match attribute """ # given & when with pytest.raises(ValueError) as exc: matches.test_step_matches(given_invalid_config, []) # then assert str(exc.value) == expected_error_msg
def test_sentence_argument_errors(capsys): """ Test if sentence arguments do not match """ # given def foo(step, foo, bar): pass steps = {re.compile(r'What (.*?) can (.*)'): foo} config = [{ 'sentence': 'What FOO can BAR', 'should_match': 'foo', 'with_arguments': [{ 'foo': 'foooooooo' }, { 'bar': 'baaaaaaar' }] }] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert 'Expected argument "foo" with value "foooooooo" does not match value "FOO"' in out assert 'Expected argument "bar" with value "baaaaaaar" does not match value "BAR"' in out assert actual_returncode == expected_returncode
def test_sentence_argument_errors(capsys): """ Test if sentence arguments do not match """ # given def foo(step, foo, bar): pass steps = {re.compile(r"What (.*?) can (.*)"): foo} config = [ { "sentence": "What FOO can BAR", "should_match": "foo", "with_arguments": [{"foo": "foooooooo"}, {"bar": "baaaaaaar"}], } ] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert ( 'Expected argument "foo" with value "foooooooo" does not match value "FOO"' in out ) assert ( 'Expected argument "bar" with value "baaaaaaar" does not match value "BAR"' in out ) assert actual_returncode == expected_returncode
def test_sentence_not_match_specific_step(capsys): """ Test if sentence does not match specific step """ # given def foo(step): pass def bar(step): pass steps = { re.compile(r'foo'): foo, re.compile(r'bar'): bar, } config = [{'sentence': 'foo', 'should_not_match': 'bar'}] expected_returncode = (0, 1) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert actual_returncode == expected_returncode
def test_sentence_no_step_match(capsys): """ Test if sentence does not match any Step Pattern """ # given steps = {} config = [{'sentence': 'foo', 'should_match': 'bar'}] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert 'Expected sentence didn\'t match any step implementation' in out assert actual_returncode == expected_returncode
def test_sentence_no_step_match(capsys): """ Test if sentence does not match any Step Pattern """ # given steps = {} config = [{"sentence": "foo", "should_match": "bar"}] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert "Expected sentence didn't match any step implementation" in out assert actual_returncode == expected_returncode
def test_sentence_not_match_anything(capsys): """ Test if sentence does not match any steps """ # given def foo(step, foo, bar): pass steps = {re.compile(r"What (.*?) can (.*)"): foo} config = [{"sentence": "foo", "should_not_match": ""}] expected_returncode = (0, 1) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert actual_returncode == expected_returncode
def test_sentence_not_match_anything(capsys): """ Test if sentence does not match any steps """ # given def foo(step, foo, bar): pass steps = {re.compile(r'What (.*?) can (.*)'): foo} config = [{ 'sentence': 'foo', 'should_not_match': '' }] expected_returncode = (0, 1) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert actual_returncode == expected_returncode
def test_sentence_not_match_but_does(capsys): """ Test if sentence matched step but shouldn't """ # given def foo(): pass steps = {"foo": foo} config = [{"sentence": "foo", "should_not_match": "foo"}] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert "Expected sentence did match foo but it shouldn't" in out assert actual_returncode == expected_returncode
def test_sentence_match_wrong_step(capsys): """ Test if sentence matched wrong step """ # given def foo(): pass steps = {"foo": foo} config = [{"sentence": "foo", "should_match": "bar"}] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert "Expected sentence matched foo instead of bar" in out assert actual_returncode == expected_returncode
def test_sentence_match_wrong_step(capsys): """ Test if sentence matched wrong step """ # given def foo(): pass steps = {'foo': foo} config = [{'sentence': 'foo', 'should_match': 'bar'}] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert 'Expected sentence matched foo instead of bar' in out assert actual_returncode == expected_returncode
def test_sentence_not_match_but_does(capsys): """ Test if sentence matched step but shouldn't """ # given def foo(): pass steps = {'foo': foo} config = [{ 'sentence': 'foo', 'should_not_match': 'foo' }] expected_returncode = (1, 0) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert 'Expected sentence did match foo but it shouldn\'t' in out assert actual_returncode == expected_returncode
def test_sentence_not_match_specific_step(capsys): """ Test if sentence does not match specific step """ # given def foo(step): pass def bar(step): pass steps = {re.compile(r"foo"): foo, re.compile(r"bar"): bar} config = [{"sentence": "foo", "should_not_match": "bar"}] expected_returncode = (0, 1) # when actual_returncode = matches.test_step_matches(config, steps) out, _ = capsys.readouterr() # then assert actual_returncode == expected_returncode