Skip to content

Commit 06edbaa

Browse files
Remove pluggable-libs submodule and cleanup (#433)
1 parent 3c0725a commit 06edbaa

File tree

8 files changed

+60
-31
lines changed

8 files changed

+60
-31
lines changed

patterns/behavioral/memento.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ def Transactional(method):
4747
4848
:param method: The function to be decorated.
4949
"""
50+
5051
def transaction(obj, *args, **kwargs):
5152
state = memento(obj)
5253
try:
5354
return method(obj, *args, **kwargs)
5455
except Exception as e:
5556
state()
5657
raise e
58+
5759
return transaction
5860

61+
5962
class NumObj:
6063
def __init__(self, value):
6164
self.value = value

patterns/behavioral/servant.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,26 @@
1919
References:
2020
- https://en.wikipedia.org/wiki/Servant_(design_pattern)
2121
"""
22+
2223
import math
2324

25+
2426
class Position:
2527
"""Representation of a 2D position with x and y coordinates."""
2628

2729
def __init__(self, x, y):
2830
self.x = x
2931
self.y = y
3032

33+
3134
class Circle:
3235
"""Representation of a circle defined by a radius and a position."""
3336

3437
def __init__(self, radius, position: Position):
3538
self.radius = radius
3639
self.position = position
3740

41+
3842
class Rectangle:
3943
"""Representation of a rectangle defined by width, height, and a position."""
4044

@@ -65,7 +69,7 @@ def calculate_area(shape):
6569
ValueError: If the shape type is unsupported.
6670
"""
6771
if isinstance(shape, Circle):
68-
return math.pi * shape.radius ** 2
72+
return math.pi * shape.radius**2
6973
elif isinstance(shape, Rectangle):
7074
return shape.width * shape.height
7175
else:

patterns/other/blackboard.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
class AbstractExpert(ABC):
1717
"""Abstract class for experts in the blackboard system."""
18+
1819
@abstractmethod
1920
def __init__(self, blackboard) -> None:
2021
self.blackboard = blackboard
@@ -31,6 +32,7 @@ def contribute(self) -> None:
3132

3233
class Blackboard:
3334
"""The blackboard system that holds the common state."""
35+
3436
def __init__(self) -> None:
3537
self.experts: list = []
3638
self.common_state = {
@@ -46,6 +48,7 @@ def add_expert(self, expert: AbstractExpert) -> None:
4648

4749
class Controller:
4850
"""The controller that manages the blackboard system."""
51+
4952
def __init__(self, blackboard: Blackboard) -> None:
5053
self.blackboard = blackboard
5154

@@ -63,6 +66,7 @@ def run_loop(self):
6366

6467
class Student(AbstractExpert):
6568
"""Concrete class for a student expert."""
69+
6670
def __init__(self, blackboard) -> None:
6771
super().__init__(blackboard)
6872

@@ -79,6 +83,7 @@ def contribute(self) -> None:
7983

8084
class Scientist(AbstractExpert):
8185
"""Concrete class for a scientist expert."""
86+
8287
def __init__(self, blackboard) -> None:
8388
super().__init__(blackboard)
8489

patterns/structural/mvc.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class Model(ABC):
1313
"""The Model is the data layer of the application."""
14+
1415
@abstractmethod
1516
def __iter__(self) -> Any:
1617
pass
@@ -29,6 +30,7 @@ def item_type(self) -> str:
2930

3031
class ProductModel(Model):
3132
"""The Model is the data layer of the application."""
33+
3234
class Price(float):
3335
"""A polymorphic way to pass a float with a particular
3436
__str__ functionality."""
@@ -56,12 +58,15 @@ def get(self, product: str) -> dict:
5658

5759
class View(ABC):
5860
"""The View is the presentation layer of the application."""
61+
5962
@abstractmethod
6063
def show_item_list(self, item_type: str, item_list: list) -> None:
6164
pass
6265

6366
@abstractmethod
64-
def show_item_information(self, item_type: str, item_name: str, item_info: dict) -> None:
67+
def show_item_information(
68+
self, item_type: str, item_name: str, item_info: dict
69+
) -> None:
6570
"""Will look for item information by iterating over key,value pairs
6671
yielded by item_info.items()"""
6772
pass
@@ -73,6 +78,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
7378

7479
class ConsoleView(View):
7580
"""The View is the presentation layer of the application."""
81+
7682
def show_item_list(self, item_type: str, item_list: list) -> None:
7783
print(item_type.upper() + " LIST:")
7884
for item in item_list:
@@ -84,7 +90,9 @@ def capitalizer(string: str) -> str:
8490
"""Capitalizes the first letter of a string and lowercases the rest."""
8591
return string[0].upper() + string[1:].lower()
8692

87-
def show_item_information(self, item_type: str, item_name: str, item_info: dict) -> None:
93+
def show_item_information(
94+
self, item_type: str, item_name: str, item_info: dict
95+
) -> None:
8896
"""Will look for item information by iterating over key,value pairs"""
8997
print(item_type.upper() + " INFORMATION:")
9098
printout = "Name: %s" % item_name
@@ -99,6 +107,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
99107

100108
class Controller:
101109
"""The Controller is the intermediary between the Model and the View."""
110+
102111
def __init__(self, model_class: Model, view_class: View) -> None:
103112
self.model: Model = model_class
104113
self.view: View = view_class
@@ -124,15 +133,17 @@ def show_item_information(self, item_name: str) -> None:
124133

125134
class Router:
126135
"""The Router is the entry point of the application."""
136+
127137
def __init__(self):
128138
self.routes = {}
129139

130140
def register(
131-
self,
132-
path: str,
133-
controller_class: type[Controller],
134-
model_class: type[Model],
135-
view_class: type[View]) -> None:
141+
self,
142+
path: str,
143+
controller_class: type[Controller],
144+
model_class: type[Model],
145+
view_class: type[View],
146+
) -> None:
136147
model_instance: Model = model_class()
137148
view_instance: View = view_class()
138149
self.routes[path] = controller_class(model_instance, view_instance)
@@ -184,7 +195,7 @@ def main():
184195
controller: Controller = router.resolve(argv[1])
185196

186197
action: str = str(argv[2]) if len(argv) > 2 else ""
187-
args: str = ' '.join(map(str, argv[3:])) if len(argv) > 3 else ""
198+
args: str = " ".join(map(str, argv[3:])) if len(argv) > 3 else ""
188199

189200
if hasattr(controller, action):
190201
command = getattr(controller, action)
@@ -201,4 +212,5 @@ def main():
201212
print(f"Command {action} not found in the controller.")
202213

203214
import doctest
215+
204216
doctest.testmod()

tests/behavioral/test_publish_subscribe.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,21 @@ def test_provider_shall_update_affected_subscribers_with_published_subscription(
4848
sub2 = Subscriber("sub 2 name", pro)
4949
sub2.subscribe("sub 2 msg 1")
5050
sub2.subscribe("sub 2 msg 2")
51-
with patch.object(sub1, "run") as mock_subscriber1_run, patch.object(
52-
sub2, "run"
53-
) as mock_subscriber2_run:
51+
with (
52+
patch.object(sub1, "run") as mock_subscriber1_run,
53+
patch.object(sub2, "run") as mock_subscriber2_run,
54+
):
5455
pro.update()
5556
cls.assertEqual(mock_subscriber1_run.call_count, 0)
5657
cls.assertEqual(mock_subscriber2_run.call_count, 0)
5758
pub.publish("sub 1 msg 1")
5859
pub.publish("sub 1 msg 2")
5960
pub.publish("sub 2 msg 1")
6061
pub.publish("sub 2 msg 2")
61-
with patch.object(sub1, "run") as mock_subscriber1_run, patch.object(
62-
sub2, "run"
63-
) as mock_subscriber2_run:
62+
with (
63+
patch.object(sub1, "run") as mock_subscriber1_run,
64+
patch.object(sub2, "run") as mock_subscriber2_run,
65+
):
6466
pro.update()
6567
expected_sub1_calls = [call("sub 1 msg 1"), call("sub 1 msg 2")]
6668
mock_subscriber1_run.assert_has_calls(expected_sub1_calls)

tests/behavioral/test_servant.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
def circle():
88
return Circle(3, Position(0, 0))
99

10+
1011
@pytest.fixture
1112
def rectangle():
1213
return Rectangle(4, 5, Position(0, 0))
1314

1415

1516
def test_calculate_area(circle, rectangle):
16-
assert GeometryTools.calculate_area(circle) == math.pi * 3 ** 2
17+
assert GeometryTools.calculate_area(circle) == math.pi * 3**2
1718
assert GeometryTools.calculate_area(rectangle) == 4 * 5
1819

1920
with pytest.raises(ValueError):
2021
GeometryTools.calculate_area("invalid shape")
2122

23+
2224
def test_calculate_perimeter(circle, rectangle):
2325
assert GeometryTools.calculate_perimeter(circle) == 2 * math.pi * 3
2426
assert GeometryTools.calculate_perimeter(rectangle) == 2 * (4 + 5)

tests/structural/test_bridge.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ class BridgeTest(unittest.TestCase):
88
def test_bridge_shall_draw_with_concrete_api_implementation(cls):
99
ci1 = DrawingAPI1()
1010
ci2 = DrawingAPI2()
11-
with patch.object(ci1, "draw_circle") as mock_ci1_draw_circle, patch.object(
12-
ci2, "draw_circle"
13-
) as mock_ci2_draw_circle:
11+
with (
12+
patch.object(ci1, "draw_circle") as mock_ci1_draw_circle,
13+
patch.object(ci2, "draw_circle") as mock_ci2_draw_circle,
14+
):
1415
sh1 = CircleShape(1, 2, 3, ci1)
1516
sh1.draw()
1617
cls.assertEqual(mock_ci1_draw_circle.call_count, 1)
@@ -33,9 +34,10 @@ def test_bridge_shall_scale_both_api_circles_with_own_implementation(cls):
3334
sh2.scale(SCALE_FACTOR)
3435
cls.assertEqual(sh1._radius, EXPECTED_CIRCLE1_RADIUS)
3536
cls.assertEqual(sh2._radius, EXPECTED_CIRCLE2_RADIUS)
36-
with patch.object(sh1, "scale") as mock_sh1_scale_circle, patch.object(
37-
sh2, "scale"
38-
) as mock_sh2_scale_circle:
37+
with (
38+
patch.object(sh1, "scale") as mock_sh1_scale_circle,
39+
patch.object(sh2, "scale") as mock_sh2_scale_circle,
40+
):
3941
sh1.scale(2)
4042
sh2.scale(2)
4143
cls.assertEqual(mock_sh1_scale_circle.call_count, 1)

tests/test_hsm.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ def test_given_standby_on_message_switchover_shall_set_active(cls):
5858
cls.assertEqual(isinstance(cls.hsm._current_state, Active), True)
5959

6060
def test_given_standby_on_message_switchover_shall_call_hsm_methods(cls):
61-
with patch.object(
62-
cls.hsm, "_perform_switchover"
63-
) as mock_perform_switchover, patch.object(
64-
cls.hsm, "_check_mate_status"
65-
) as mock_check_mate_status, patch.object(
66-
cls.hsm, "_send_switchover_response"
67-
) as mock_send_switchover_response, patch.object(
68-
cls.hsm, "_next_state"
69-
) as mock_next_state:
61+
with (
62+
patch.object(cls.hsm, "_perform_switchover") as mock_perform_switchover,
63+
patch.object(cls.hsm, "_check_mate_status") as mock_check_mate_status,
64+
patch.object(
65+
cls.hsm, "_send_switchover_response"
66+
) as mock_send_switchover_response,
67+
patch.object(cls.hsm, "_next_state") as mock_next_state,
68+
):
7069
cls.hsm.on_message("switchover")
7170
cls.assertEqual(mock_perform_switchover.call_count, 1)
7271
cls.assertEqual(mock_check_mate_status.call_count, 1)

0 commit comments

Comments
 (0)