Skip to content

Commit 46abbb9

Browse files
committed
Fix syntax errors
1 parent dc2aa11 commit 46abbb9

2 files changed

Lines changed: 68 additions & 64 deletions

File tree

test/test_base.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from typing import Optional
2+
from chaski.node import ChaskiNode
3+
4+
5+
class TestBase:
6+
7+
async def asyncTearDown(self):
8+
for node in self.nodes:
9+
print(f"Closing node {node.port}")
10+
await node.stop()
11+
12+
def assertConnection(
13+
self, node1: ChaskiNode, node2: ChaskiNode, msg: Optional[str] = None
14+
):
15+
"""
16+
Assert that two ChaskiNodes are connected to each other.
17+
18+
This method checks if `node1` is connected to `node2` and vice versa.
19+
It raises an assertion error if the connection is not established in
20+
both directions.
21+
22+
Parameters
23+
----------
24+
node1 : ChaskiNode
25+
The first ChaskiNode to check connection from.
26+
node2 : ChaskiNode
27+
The second ChaskiNode to check connection to.
28+
msg : str, optional
29+
An optional message to include in the assertion error if the
30+
nodes are not connected.
31+
32+
Raises
33+
------
34+
AssertionError
35+
If `node1` is not connected to `node2` or `node2` is not connected to `node1`.
36+
"""
37+
conn = node1.is_connected_to(node2) and node2.is_connected_to(node1)
38+
return self.assertTrue(conn, msg)
39+
40+
def assertNoConnection(
41+
self, node1: ChaskiNode, node2: ChaskiNode, msg: Optional[str] = None
42+
):
43+
"""
44+
Assert that two ChaskiNodes are not connected to each other.
45+
46+
This method checks if `node1` is connected to `node2` and vice versa.
47+
It raises an assertion error if the connection is established in
48+
either direction.
49+
50+
Parameters
51+
----------
52+
node1 : ChaskiNode
53+
The first ChaskiNode to check connection from.
54+
node2 : ChaskiNode
55+
The second ChaskiNode to check connection to.
56+
msg : str, optional
57+
An optional message to include in the assertion error if the
58+
nodes are connected.
59+
60+
Raises
61+
------
62+
AssertionError
63+
If `node1` is connected to `node2` or `node2` is connected to `node1`.
64+
"""
65+
conn = node1.is_connected_to(node2) and node2.is_connected_to(node1)
66+
return self.assertFalse(conn, msg)

test/test_subscription.py

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
import pytest
2121
import unittest
2222
import asyncio
23-
from typing import Optional
2423
from chaski.utils.auto import create_nodes
25-
from chaski.node import ChaskiNode
24+
from .test_base import TestBase
2625

2726

28-
class TestSubscriptions(unittest.IsolatedAsyncioTestCase):
27+
class TestSubscriptions(unittest.IsolatedAsyncioTestCase, TestBase):
2928
"""
3029
Test case for testing a single subscription scenario in ChaskiNodes.
3130
@@ -36,67 +35,6 @@ class TestSubscriptions(unittest.IsolatedAsyncioTestCase):
3635
nodes = []
3736
host = "127.0.0.1"
3837

39-
async def asyncTearDown(self):
40-
for node in self.nodes:
41-
print(f"Closing node {node.port}")
42-
await node.stop()
43-
44-
def assertConnection(
45-
self, node1: ChaskiNode, node2: ChaskiNode, msg: Optional[str] = None
46-
):
47-
"""
48-
Assert that two ChaskiNodes are connected to each other.
49-
50-
This method checks if `node1` is connected to `node2` and vice versa.
51-
It raises an assertion error if the connection is not established in
52-
both directions.
53-
54-
Parameters
55-
----------
56-
node1 : ChaskiNode
57-
The first ChaskiNode to check connection from.
58-
node2 : ChaskiNode
59-
The second ChaskiNode to check connection to.
60-
msg : str, optional
61-
An optional message to include in the assertion error if the
62-
nodes are not connected.
63-
64-
Raises
65-
------
66-
AssertionError
67-
If `node1` is not connected to `node2` or `node2` is not connected to `node1`.
68-
"""
69-
conn = node1.is_connected_to(node2) and node2.is_connected_to(node1)
70-
return self.assertTrue(conn, msg)
71-
72-
def assertNoConnection(
73-
self, node1: ChaskiNode, node2: ChaskiNode, msg: Optional[str] = None
74-
):
75-
"""
76-
Assert that two ChaskiNodes are not connected to each other.
77-
78-
This method checks if `node1` is connected to `node2` and vice versa.
79-
It raises an assertion error if the connection is established in
80-
either direction.
81-
82-
Parameters
83-
----------
84-
node1 : ChaskiNode
85-
The first ChaskiNode to check connection from.
86-
node2 : ChaskiNode
87-
The second ChaskiNode to check connection to.
88-
msg : str, optional
89-
An optional message to include in the assertion error if the
90-
nodes are connected.
91-
92-
Raises
93-
------
94-
AssertionError
95-
If `node1` is connected to `node2` or `node2` is connected to `node1`.
96-
"""
97-
conn = node1.is_connected_to(node2) and node2.is_connected_to(node1)
98-
return self.assertFalse(conn, msg)
99-
10038
@pytest.mark.asyncio
10139
async def test_single_subscription_no_disconnect(self):
10240
"""

0 commit comments

Comments
 (0)