8000 fix: hide failure and success summary private attributes in closure · proofit404/stories@eae4e95 · GitHub
[go: up one dir, main page]

Skip to content

Commit eae4e95

Browse files
dry-python-botdry-python-bot
dry-python-bot
authored and
dry-python-bot
committed
fix: hide failure and success summary private attributes in closure
1 parent 1fafcc1 commit eae4e95

File tree

6 files changed

+75
-76
lines changed

6 files changed

+75
-76
lines changed

src/_stories/execute/function.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ from _stories.returned import Skip
1919
from _stories.returned import Success
2020
from _stories.run import Call
2121
from _stories.run import Run
22-
from _stories.summary import FailureSummary
23-
from _stories.summary import SuccessSummary
2422
@overload
2523
def execute(
2624
runner: Call,
@@ -54,4 +52,4 @@ def execute(
5452
Union[NullExecProtocol, DisabledNullExecProtocol, NotNullExecProtocol],
5553
],
5654
],
57-
) -> Union[SuccessSummary, FailureSummary]: ...
55+
) -> object: ...

src/_stories/mounted.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ from _stories.failures import NotNullExecProtocol
1414
from _stories.failures import NullExecProtocol
1515
from _stories.marker import BeginningOfStory
1616
from _stories.marker import EndOfStory
17-
from _stories.summary import FailureSummary
18-
from _stories.summary import SuccessSummary
1917

2018
class ClassMountedStory:
2119
def __init__(
@@ -46,7 +44,5 @@ class MountedStory:
4644
failures: Optional[Union[List[str], Type[Enum]]],
4745
) -> None: ...
4846
def __call__(self, **kwargs: Dict[str, Any]) -> Optional[Union[List[str], int]]: ...
49-
def run(
50-
self, **kwargs: Dict[str, Any]
51-
) -> Union[SuccessSummary, FailureSummary]: ...
47+
def run(self, **kwargs: Dict[str, Any]) -> object: ...
5248
def __repr__(self) -> str: ...

src/_stories/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def __init__(self, protocol):
2020
self.protocol = protocol
2121

2222
def got_failure(self, ctx, method_name, reason):
23-
return FailureSummary(self.protocol, ctx, method_name, reason)
23+
return make_failure_summary(self.protocol, ctx, method_name, reason)
2424

2525
def got_result(self, value):
26-
return SuccessSummary(self.protocol, value)
26+
return make_success_summary(self.protocol, value)
2727

2828
def finished(self):
29-
return SuccessSummary(self.protocol, None)
29+
return make_success_summary(self.protocol, None)

src/_stories/run.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ from typing import Union
66

77
from _stories.failures import NotNullRunProtocol
88
from _stories.failures import NullRunProtocol
9-
from _stories.summary import FailureSummary
10-
from _stories.summary import SuccessSummary
119

1210
class Call:
1311
def got_failure(
@@ -22,6 +20,6 @@ class Run:
2220
) -> None: ...
2321
def got_failure(
2422
self, ctx: object, method_name: str, reason: Optional[Union[str, Enum]]
25-
) -> FailureSummary: ...
26-
def got_result(self, value: Union[List[str], int]) -> SuccessSummary: ...
27-
def finished(self) -> SuccessSummary: ...
23+
) -> object: ...
24+
def got_result(self, value: Union[List[str], int]) -> object: ...
25+
def finished(self) -> object: ...

src/_stories/summary.py

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,60 @@
11
# -*- coding: utf-8 -*-
22

33

4-
class FailureSummary(object):
5-
def __init__(self, protocol, ctx, failed_method, reason):
6-
self.__protocol = protocol
7-
self.is_success = False
8-
self.is_failure = True
9-
self.ctx = ctx
10-
self.__failed_method = failed_method
11-
self.__failure_reason = reason
12-
13-
def failed_on(self, method_name):
14-
return method_name == self.__failed_method
15-
16-
def failed_because(self, reason):
17-
self.__protocol.check_failed_because_argument(reason)
18-
return self.__protocol.compare_failed_because_argument(
19-
reason, self.__failure_reason
20-
)
21-
22-
@property
23-
def value(self):
24-
raise AssertionError
25-
26-
def __repr__(self):
27-
return "Failure()"
28-
29-
30-
class SuccessSummary(object):
31-
def __init__(self, protocol, value):
32-
self.__protocol = protocol
33-
self.is_success = True
34-
self.is_failure = False
35-
self.value = value
36-
37-
def failed_on(self, method_name):
38-
return False
4+
def make_failure_summary(protocol, ctx, failed_method, failure_reason):
5+
def failed_on_method(self, method_name):
6+
return method_name == failed_method
7+
8+
def failed_because_method(self, reason):
9+
protocol.check_failed_because_argument(reason)
10+
return protocol.compare_failed_because_argument(reason, failure_reason)
11+
12+
return type(
13+
"FailureSummary",
14+
(object,),
15+
{
16+
"is_success": False,
17+
"is_failure": True,
18+
"ctx": ctx,
19+
"value": failure_value_method,
20+
"failed_on": failed_on_method,
21+
"failed_because": failed_because_method,
22+
"__repr__": failure_repr_method,
23+
},
24+
)()
25+
26+
27+
@property
28+
def failure_value_method(self):
29+
raise AssertionError
30+
3931

40-
def failed_because(self, reason):
41-
self.__protocol.check_failed_because_argument(reason)
32+
def failure_repr_method(self):
33+
return "Failure()"
34+
35+
36+
def make_success_summary(protocol, value):
37+
def success_failed_because_method(self, reason):
38+
protocol.check_failed_because_argument(reason)
4239
return False
4340

44-
def __repr__(self):
45-
return "Success()"
41+
return type(
42+
"SuccessSummary",
43+
(object,),
44+
{
45+
"is_success": True,
46+
"is_failure": False,
47+
"value": value,
48+
"failed_on": success_failed_on_method,
49+
"failed_because": success_failed_because_method,
50+
"__repr__": success_repr_method,
51+
},
52+
)()
53+
54+
55+
def success_failed_on_method(self, method_name):
56+
return False
57+
58+
59+
def success_repr_method(self):
60+
return "Success()"

src/_stories/summary.pyi

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@ from typing import Union
77
from _stories.failures import NotNullRunProtocol
88
from _stories.failures import NullRunProtocol
99

10-
class FailureSummary:
11-
def __init__(
12-
self,
13-
protocol: Union[NullRunProtocol, NotNullRunProtocol],
14-
ctx: object,
15-
failed_method: str,
16-
reason: Optional[Union[str, Enum]],
17-
) -> None: ...
18-
def failed_on(self, method_name: str) -> bool: ...
19-
def failed_because(self, reason: Union[str, Enum]) -> bool: ...
20-
@property
21-
def value(self) -> NoReturn: ...
22-
def __repr__(self) -> str: ...
23-
24-
class SuccessSummary:
25-
def __init__(
26-
self, protocol: Union[NullRunProtocol, NotNullRunProtocol], value: Any
27-
) -> None: ...
28-
def failed_on(self, method_name: str) -> bool: ...
29-
def failed_because(self, reason: str) -> bool: ...
30-
def __repr__(self) -> str: ...
10+
def make_failure_summary(
11+
protocol: Union[NullRunProtocol, NotNullRunProtocol],
12+
ctx: object,
13+
failed_method: str,
14+
reason: Optional[Union[str, Enum]],
15+
) -> object: ...
16+
def failure_value_method(self: object) -> NoReturn: ...
17+
def failure_repr_method(self: object) -> str: ...
18+
def make_success_summary(
19+
protocol: Union[NullRunProtocol, NotNullRunProtocol], value: Any
20+
) -> object: ...
21+
def success_failed_on_method(self: object, method_name: str) -> bool: ...
22+
def success_repr_method(self: object) -> str: ...

0 commit comments

Comments
 (0)
0