Skip to content

Commit 78d5430

Browse files
Copilotlaeubi
andcommitted
Create io.cucumber.eclipse.python bundle
Add inital implementation and example for supporting behave tests using python. Co-authored-by: laeubi <[email protected]>
1 parent 30481e7 commit 78d5430

36 files changed

+2669
-0
lines changed

.github/copilot-instructions.md

Lines changed: 662 additions & 0 deletions
Large diffs are not rendered by default.

examples/.project

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>cucumber-eclipse-examples</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
9+
</buildSpec>
10+
<natures>
11+
</natures>
12+
</projectDescription>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__/
2+
*.pyc
3+
*.pyo
4+
.pytest_cache/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>python-caclulator</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
9+
</buildSpec>
10+
<natures>
11+
</natures>
12+
</projectDescription>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Python Calculator Example
2+
3+
This is a simple example demonstrating how to use the Cucumber-Behave launcher with Eclipse.
4+
5+
## Prerequisites
6+
7+
1. Python 3.x installed
8+
2. Behave package installed:
9+
```bash
10+
pip install behave
11+
```
12+
13+
## Running the Example
14+
15+
### From Command Line
16+
17+
```bash
18+
cd examples/python-calculator
19+
behave
20+
```
21+
22+
### From Eclipse
23+
24+
1. Open Eclipse with Cucumber Eclipse plugin installed
25+
2. Import this project into Eclipse
26+
3. Right-click on `features/calculator.feature`
27+
4. Select "Run As" > "Cucumber-Behave"
28+
5. In the launch configuration dialog:
29+
- **Feature Path**: Select the `calculator.feature` file
30+
- **Working Directory**: Set to the `examples/python-calculator` directory
31+
- **Python Interpreter**: Use `python` or `python3` depending on your system
32+
- Click "Run"
33+
34+
## Project Structure
35+
36+
```
37+
python-calculator/
38+
├── features/
39+
│ ├── calculator.feature # Feature file with scenarios
40+
│ └── steps/
41+
│ └── calculator_steps.py # Step definitions
42+
└── README.md
43+
```
44+
45+
## Expected Output
46+
47+
When you run the tests, you should see output indicating that all three scenarios pass:
48+
49+
```
50+
Feature: Calculator # features/calculator.feature:1
51+
52+
Scenario: Add two numbers # features/calculator.feature:6
53+
Given I have a calculator # features/steps/calculator_steps.py:19
54+
When I add 2 and 3 # features/steps/calculator_steps.py:23
55+
Then the result should be 5 # features/steps/calculator_steps.py:35
56+
57+
Scenario: Subtract two numbers # features/calculator.feature:11
58+
Given I have a calculator # features/steps/calculator_steps.py:19
59+
When I subtract 3 from 5 # features/steps/calculator_steps.py:27
60+
Then the result should be 2 # features/steps/calculator_steps.py:35
61+
62+
Scenario: Multiply two numbers # features/calculator.feature:16
63+
Given I have a calculator # features/steps/calculator_steps.py:19
64+
When I multiply 2 by 3 # features/steps/calculator_steps.py:31
65+
Then the result should be 6 # features/steps/calculator_steps.py:35
66+
67+
3 scenarios (3 passed)
68+
9 steps (9 passed)
69+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Calculator
2+
As a user
3+
I want to use a calculator
4+
So that I can perform basic arithmetic operations
5+
6+
Scenario: Add two numbers
7+
Given I have a calculator
8+
When I add 2 and 3
9+
Then the result should be 5
10+
11+
Scenario: Subtract two numbers
12+
Given I have a calculator
13+
When I subtract 3 from 5
14+
Then the result should be 2
15+
16+
Scenario: Multiply two numbers
17+
Given I have a calculator
18+
When I multiply 2 by 3
19+
Then the result should be 6
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from behave import given, when, then
2+
3+
class Calculator:
4+
def __init__(self):
5+
self.result = 0
6+
7+
def add(self, a, b):
8+
self.result = a + b
9+
return self.result
10+
11+
def subtract(self, a, b):
12+
self.result = a - b
13+
return self.result
14+
15+
def multiply(self, a, b):
16+
self.result = a * b
17+
return self.result
18+
19+
@given('I have a calculator')
20+
def step_impl(context):
21+
context.calculator = Calculator()
22+
23+
@when('I add {a:d} and {b:d}')
24+
def step_impl(context, a, b):
25+
context.calculator.add(a, b)
26+
27+
@when('I subtract {a:d} from {b:d}')
28+
def step_impl(context, a, b):
29+
context.calculator.subtract(b, a)
30+
31+
@when('I multiply {a:d} by {b:d}')
32+
def step_impl(context, a, b):
33+
context.calculator.multiply(a, b)
34+
35+
@then('the result should be {expected:d}')
36+
def step_impl(context, expected):
37+
assert context.calculator.result == expected, \
38+
f"Expected {expected}, but got {context.calculator.result}"

io.cucumber.eclipse.feature/feature.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5151
id="io.cucumber.eclipse.java.plugins"
5252
version="0.0.0"/>
5353

54+
<plugin
55+
id="io.cucumber.eclipse.python"
56+
version="0.0.0"/>
57+
5458
</feature>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

0 commit comments

Comments
 (0)