2014-09-21 07:54:39 +08:00
|
|
|
"""Code generation and assertion tests."""
|
2014-11-10 16:58:46 +08:00
|
|
|
|
2014-09-21 07:54:39 +08:00
|
|
|
import os.path
|
|
|
|
|
|
|
|
import py
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_missing(testdir):
|
2015-04-28 20:57:02 +08:00
|
|
|
dirname = "test_generate_missing"
|
|
|
|
tests = testdir.mkpydir(dirname)
|
2014-11-09 19:56:50 +08:00
|
|
|
with open(os.path.join(os.path.dirname(__file__), "generation.feature")) as fd:
|
2014-09-21 07:54:39 +08:00
|
|
|
tests.join('generation.feature').write(fd.read())
|
|
|
|
|
|
|
|
tests.join("test_foo.py").write(py.code.Source("""
|
|
|
|
import functools
|
|
|
|
|
|
|
|
from pytest_bdd import scenario, given
|
|
|
|
|
2014-11-09 19:56:50 +08:00
|
|
|
scenario = functools.partial(scenario, "generation.feature")
|
2014-09-21 07:54:39 +08:00
|
|
|
|
2014-11-09 19:56:50 +08:00
|
|
|
@given("I have a bar")
|
2014-09-21 07:54:39 +08:00
|
|
|
def i_have_a_bar():
|
2014-11-09 19:56:50 +08:00
|
|
|
return "bar"
|
2014-09-21 07:54:39 +08:00
|
|
|
|
2014-11-09 19:56:50 +08:00
|
|
|
@scenario("Scenario tests which are already bound to the tests stay as is")
|
2014-09-21 07:54:39 +08:00
|
|
|
def test_foo():
|
|
|
|
pass
|
|
|
|
|
2014-11-09 19:56:50 +08:00
|
|
|
@scenario("Code is generated for scenario steps which are not yet defined(implemented)")
|
2014-09-21 07:54:39 +08:00
|
|
|
def test_missing_steps():
|
|
|
|
pass
|
|
|
|
"""))
|
|
|
|
|
2015-04-28 20:57:02 +08:00
|
|
|
result = testdir.runpytest(dirname, "--generate-missing", "--feature", tests.join('generation.feature').strpath)
|
2014-09-21 07:54:39 +08:00
|
|
|
|
|
|
|
result.stdout.fnmatch_lines([
|
2014-11-10 16:58:46 +08:00
|
|
|
'Scenario "Code is generated for scenarios which are not bound to any tests" is not bound to any test *']
|
|
|
|
)
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
2015-06-10 06:53:12 +08:00
|
|
|
'Step Given "I have a custom bar" is not defined in the scenario '
|
2014-11-10 16:58:46 +08:00
|
|
|
'"Code is generated for scenario steps which are not yet defined(implemented)" *',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(
|
2015-06-10 06:53:12 +08:00
|
|
|
['Step Given "I have a foobar" is not defined in the background of the feature "Missing code generation" *']
|
2014-11-10 16:58:46 +08:00
|
|
|
)
|
2014-09-22 14:27:46 +08:00
|
|
|
|
2014-11-09 19:56:50 +08:00
|
|
|
result.stdout.fnmatch_lines(["Please place the code above to the test file(s):"])
|