8000 acpt: add Hyperlink properties scenarios · python-openxml/python-docx@7868f3e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7868f3e

Browse files
committed
acpt: add Hyperlink properties scenarios
1 parent 9dd2851 commit 7868f3e

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

features/hlk-props.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: Access hyperlink properties
< 8000 /td>2+
In order to access the URL and other details for a hyperlink
3+
As a developer using python-docx
4+
I need properties on Hyperlink
5+
6+
7+
@wip
8+
Scenario: Hyperlink.address has the URL of the hyperlink
9+
Given a hyperlink
10+
Then hyperlink.address is the URL of the hyperlink
11+
12+
13+
@wip
14+
Scenario Outline: Hyperlink.contains_page_break reports presence of page-break
15+
Given a hyperlink having <zero-or-more> rendered page breaks
16+
Then hyperlink.contains_page_break is <value>
17+
18+
Examples: Hyperlink.contains_page_break cases
19+
| zero-or-more | value |
20+
| no | False |
21+
| one | True |
22+
23+
24+
@wip
25+
Scenario Outline: Hyperlink.runs contains Run for each run in hyperlink
26+
Given a hyperlink having <zero-or-more> runs
27+
Then hyperlink.runs has length <value>
28+
And hyperlink.runs contains only Run instances
29+
30+
Examples: Hyperlink.runs cases
31+
| zero-or-more | value |
32+
| one | 1 |
33+
| two | 2 |
34+
35+
36+
@wip
37+
Scenario: Hyperlink.text has the visible text of the hyperlink
38+
Given a hyperlink
39+
Then hyperlink.text is the visible text of the hyperlink

features/steps/hyperlink.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""Step implementations for hyperlink-related features."""
2+
3+
from __future__ import annotations
4+
5+
from behave import given, then
6+
from behave.runner import Context
7+
8+
from docx import Document
9+
10+
from helpers import test_docx
11+
12+
# given ===================================================
13+
14+
15+
@given("a hyperlink")
16+
def given_a_hyperlink(context: Context):
17+
document = Document(test_docx("par-hyperlinks"))
18+
context.hyperlink = document.paragraphs[1].hyperlinks[0]
19+
20+
21+
@given("a hyperlink having {zero_or_more} rendered page breaks")
22+
def given_a_hyperlink_having_rendered_page_breaks(context: Context, zero_or_more: str):
23+
paragraph_idx = {
24+
"no": 1,
25+
"one": 2,
26+
}[zero_or_more]
27+
document = Document(test_docx("par-hyperlinks"))
28+
paragraph = document.paragraphs[paragraph_idx]
29+
context.hyperlink = paragraph.hyperlinks[0]
30+
31+
32+
@given("a hyperlink having {one_or_more} runs")
33+
def given_a_hyperlink_having_one_or_more_runs(context: Context, one_or_more: str):
34+
paragraph_idx, hyperlink_idx = {
35+
"one": (1, 0),
36+
"two": (2, 1),
37+
}[one_or_more]
38+
document = Document(test_docx("par-hyperlinks"))
39+
paragraph = document.paragraphs[paragraph_idx]
40+
context.hyperlink = paragraph.hyperlinks[hyperlink_idx]
41+
42+
43+
# then =====================================================
44+
45+
46+
@then("hyperlink.address is the URL of the hyperlink")
47+
def then_hyperlink_address_is_the_URL_of_the_hyperlink(context: Context):
48+
actual_value = context.hyperlink.address
49+
expected_value = "http://yahoo.com/"
50+
assert (
51+
actual_value == expected_value
52+
), f"expected: {expected_value}, got: {actual_value}"
53+
54+
55+
@then("hyperlink.contains_page_break is {value}")
56+
def then_hyperlink_contains_page_break_is_value(context: Context, value: str):
57+
actual_value = context.hyperlink.contains_page_break
58+
expected_value = {"True": True, "False": False}[value]
59+
assert (
60+
actual_value == expected_value
61+
), f"expected: {expected_value}, got: {actual_value}"
62+
63+
64+
@then("hyperlink.runs contains only Run instances")
65+
def then_hyperlink_runs_contains_only_Run_instances(context: Context):
66+
actual_value = [type(item).__name__ for item in context.hyperlink.runs]
67+
expected_value = ["Run" for _ in context.hyperlink.runs]
68+
assert (
69+
actual_value == expected_value
70+
), f"expected: {expected_value}, got: {actual_value}"
71+
72+
73+
@then("hyperlink.runs has length {value}")
74+
def then_hyperlink_runs_has_length(context: Context, value: str):
75+
actual_value = len(context.hyperlink.runs)
76+
expected_value = int(value)
77+
assert (
78+
actual_value == expected_value
79+
), f"expected: {expected_value}, got: {actual_value}"
80+
81+
82+
@then("hyperlink.text is the visible text of the hyperlink")
83+
def then_hyperlink_text_is_the_visible_text_of_the_hyperlink(context: Context):
84+
actual_value = context.hyperlink.text
85+
expected_value = "awesome hyperlink"
86+
assert (
87+
actual_value == expected_value
88+
), f"expected: {expected_value}, got: {actual_value}"

0 commit comments

Comments
 (0)
0