Skip to content

Commit cad799c

Browse files
committed
test: Add additional test cases and refactor
1 parent 418797c commit cad799c

9 files changed

+87
-37
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ The formatter follows a list of pre-defined rules outlined below.
2828
* Tables/step text: Six spaces
2929

3030
## Installation
31-
To install the latest feefifofum version from the main branch, run the following command:
31+
Install the feefifofum directly from GitHub by running the following command:
3232
```shell
33-
pip install git+https://github.com/rushwerks/feefifofum.git@v0.1.0
34-
33+
pip install git+https://github.com/rushwerks/feefifofum.git@v0.1.1
3534
```
3635

3736
## Usage
@@ -47,7 +46,7 @@ feefifofum <directory1> <directory2>
4746
`feefifofum` is also available as a pre-commit hook. It can be configured as follows:
4847
```yaml
4948
- repo: https://github.com/rushwerks/feefifofum/
50-
rev: v0.1.0
49+
rev: v0.1.1
5150
hooks:
5251
- id: feefifofum
5352
```

feefifofum/helpers/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
TABLE_LEFT_EDGE = '| '
99
TABLE_RIGHT_EDGE = ' |\n'
1010

11+
1112
# Whitespace
1213
class Whitespace(NamedTuple):
1314
newline: int
1415
indent: int
1516

17+
1618
WHITESPACE_CONFIG: dict[str, Whitespace] = {
1719
'Feature': Whitespace(0, 0),
1820
'Scenario': Whitespace(2, 1),

feefifofum/helpers/whitespace.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ def format_whitespace(file_lines: list[str]) -> list[str]:
2626
for line in file_lines:
2727
leading_word = line.split(maxsplit=1)[0].rstrip(':')
2828

29-
if leading_word in WHITESPACE_CONFIG or line.startswith(TABLE_SEPARATOR): # TODO: Test
30-
newline, indent = WHITESPACE_CONFIG[leading_word]
31-
previous_leading_word_match = leading_word
29+
if leading_word in WHITESPACE_CONFIG or line.startswith(TABLE_SEPARATOR):
30+
whitespace_key = leading_word if leading_word in WHITESPACE_CONFIG else TABLE_SEPARATOR
31+
newline, indent = WHITESPACE_CONFIG[whitespace_key]
32+
previous_leading_word_match = whitespace_key
3233
else:
3334
newline, indent = WHITESPACE_CONFIG.get(previous_leading_word_match, (0, 0))
3435
newline = 0 # Keep in same feature file block

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "feefifofum"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
description = "Feature file formatter"
99
readme = "README.md"
1010
requires-python = ">=3.7"

tests/data/example_expected.feature tests/data/full_file_expected.feature

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ Feature: Example test file for formatter
44

55
Scenario: Test scenario for formatting
66

7-
Given some contract and business partner data exists in system A
8-
| contract_id | bp_id |
9-
| contract_1 | 1 |
10-
| contract_2 | 2 |
11-
12-
And some contracts data exists in system B
13-
# Some random comment
7+
Given contracts exist in system A
148
| contract_id |
159
| contract_1 |
16-
| contract_3 |
10+
| contract_2 |
11+
12+
And corresponding customers exists in system B
13+
# Comment 1
14+
# Comment 2
15+
| contract_id | customer_id |
16+
| contract_1 | customer_1 |
17+
| contract_3 | customer_2 |
1718

1819
Then the output table should show missing contract data and the error type
1920
"""
20-
Some other random comment
21+
Multi-line
22+
comment
2123
"""
2224
| contract_id | error_type | missing_in |
2325
| contract_2 | missing contract | B |

tests/data/example_input.feature tests/data/full_file_input.feature

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11

22
Feature: Example test file for formatter
33
This is an example feature file with poor formatting
4+
Scenario: Test scenario for formatting
45

6+
Given contracts exist in system A
7+
|contract_id |
8+
|contract_1 |
9+
| contract_2 |
510

6-
Scenario: Test scenario for formatting
711

8-
Given some contract and business partner data exists in system A
9-
|contract_id | bp_id |
10-
|contract_1 | 1 |
11-
| contract_2 | 2 |
12-
And some contracts data exists in system B
13-
# Some random comment
14-
| contract_id |
15-
| contract_1 |
16-
| contract_3 |
12+
And corresponding customers exists in system B
13+
# Comment 1
14+
# Comment 2
15+
| contract_id | customer_id |
16+
| contract_1 |customer_1 |
17+
| contract_3 | customer_2 |
1718

1819
Then the output table should show missing contract data and the error type
1920
"""
20-
Some other random comment
21+
Multi-line
22+
comment
2123
"""
2224
| contract_id | error_type | missing_in |
2325
| contract_2 | missing contract |B |

tests/data/text_only_expected.feature

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Example test file for formatter
2+
This is an example feature file with poor formatting
3+
4+
5+
Scenario: Test scenario for formatting
6+
7+
Given contracts exist in system A
8+
9+
And corresponding customers exists in system B
10+
# Comment 1
11+
# Comment 2
12+
13+
Then the output table should show missing contract data and the error type
14+
"""
15+
Multi-line
16+
comment
17+
"""

tests/data/text_only_input.feature

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Feature: Example test file for formatter
3+
This is an example feature file with poor formatting
4+
Scenario: Test scenario for formatting
5+
6+
Given contracts exist in system A
7+
8+
9+
And corresponding customers exists in system B
10+
# Comment 1
11+
# Comment 2
12+
13+
Then the output table should show missing contract data and the error type
14+
"""
15+
Multi-line
16+
comment
17+
"""

tests/test_main.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
from pathlib import Path
22

3+
import pytest
4+
35
from feefifofum.main import format_feature_file
46
from feefifofum.utils.file_utils import read_file_lines
57

6-
78
ROOT_DIR = Path(__file__).resolve().parent
89

910

10-
def test_format_feature_file() -> None:
11-
"""Tests format_feature_file by running all transformations."""
12-
file_path_input = ROOT_DIR / 'data' / 'example_input.feature'
13-
file_path_expected = ROOT_DIR / 'data' / 'example_expected.feature'
11+
class TestFormatFeatureFile:
12+
"""Tests for format_feature_file()."""
13+
14+
test_data = [
15+
('full_file_input.feature', 'full_file_expected.feature'),
16+
('text_only_input.feature', 'text_only_expected.feature'),
17+
]
18+
19+
@pytest.mark.parametrize('input_file, expected_file', test_data)
20+
def test_format_feature_file(self, input_file: str, expected_file: str) -> None:
21+
"""Tests format_feature_file by running all transformations."""
22+
file_path_input = ROOT_DIR / 'data' / input_file
23+
file_path_expected = ROOT_DIR / 'data' / expected_file
1424

15-
file_lines_input = read_file_lines(file_path_input)
16-
formatted_output = format_feature_file(file_lines_input)
25+
file_lines_input = read_file_lines(file_path_input)
26+
formatted_output = format_feature_file(file_lines_input)
1727

18-
formatted_expected = read_file_lines(file_path_expected)
28+
formatted_expected = read_file_lines(file_path_expected)
1929

20-
assert formatted_output == formatted_expected
30+
assert formatted_output == formatted_expected

0 commit comments

Comments
 (0)