Skip to content

Commit 49dbe35

Browse files
authored
Merge pull request #493 from alexandrehassan/484-test-pick
Add tests for @pick
2 parents e9d7a8b + 303e82a commit 49dbe35

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Verify the pick feature
2+
3+
Scenario: Add a method to the world using pick
4+
Given I don't have a pick decorated method
5+
Then I expect the pick step not to be in the world
6+
Given I have a method decorated with pick
7+
Then I expect the pick step to be in the world
8+
When I call the pick decorated method
9+
Then I expect the pick result to be 42
10+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from radish.stepregistry import given, step, then, when
2+
from radish.terrain import pick, world
3+
4+
5+
@step("I don't have a pick decorated method")
6+
def dont_have_pick_method(step):
7+
if hasattr(world, "pick_decorated"):
8+
delattr(world, "pick_decorated")
9+
10+
11+
@given("I have a method decorated with pick")
12+
def add_pick_step(step):
13+
@pick
14+
def pick_decorated():
15+
return 42
16+
17+
step.context.decorate_method_name = pick_decorated.__name__
18+
19+
20+
@then("I expect the pick step to be in the world")
21+
def expect_pick_step(step):
22+
assert hasattr(world, "pick_decorated"), "World is missing the decorated method pick_decorated"
23+
24+
25+
@then("I expect the pick step not to be in the world")
26+
def expect_pick_step_missing(step):
27+
assert not hasattr(world, "pick_decorated"), "World has the decorated method pick_decorated"
28+
29+
30+
@when("I call the pick decorated method")
31+
def call_pick_decorated_method(step):
32+
step.context.pick_result = world.pick_decorated()
33+
34+
35+
@then("I expect the pick result to be {expected_result:d}")
36+
def expect_pick_result(step, expected_result):
37+
assert step.context.pick_result == expected_result, (
38+
f"Expected pick result to be {expected_result} but was {step.context.pick_result}"
39+
)

tests/unit/test_terrain.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from radish.terrain import pick, world
2+
3+
4+
def test_pick_decorator_adds_function_to_world():
5+
"""Test that the pick decorator adds the function to the world object."""
6+
assert not hasattr(world, "sample_function")
7+
8+
@pick
9+
def sample_function():
10+
return "test"
11+
12+
assert hasattr(world, "sample_function")
13+
assert world.sample_function() == "test"
14+
15+
@pick
16+
def another_function(x, y=0):
17+
return x + y
18+
19+
assert hasattr(world, "another_function")
20+
assert world.another_function(2, y=3) == 5, "Parameters not passed correctly."
21+
22+
def func():
23+
return "overridden"
24+
25+
func.__name__ = "sample_function"
26+
27+
pick(func)
28+
29+
assert world.sample_function() == "overridden", "The function was not overridden correctly."

0 commit comments

Comments
 (0)