From 2d5967e6ff4b2f1609b43d56a3fe3e6e0f3fd0b4 Mon Sep 17 00:00:00 2001 From: hsc Date: Thu, 14 May 2026 09:43:36 +0800 Subject: [PATCH 1/5] update code flake8 error --- qns/entity/cchannel/cchannel_ex.py | 6 ++++-- qns/simulator/stablepool.py | 2 +- test/entity/test_cchannelex.py | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/qns/entity/cchannel/cchannel_ex.py b/qns/entity/cchannel/cchannel_ex.py index b1c5e01..23ea16f 100644 --- a/qns/entity/cchannel/cchannel_ex.py +++ b/qns/entity/cchannel/cchannel_ex.py @@ -15,13 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from typing import Any, List +from typing import List from qns.simulator.ts import Time from qns.entity.node.node import QNode from qns.models.delay.delay import DelayModel from qns.simulator.simulator import Simulator -from qns.entity.cchannel.cchannel import * +from qns.utils.rnd import get_rand +import qns.utils.log as log +from qns.entity.cchannel.cchannel import ClassicPacket, ClassicChannel, RecvClassicPacket, NextHopNotConnectionException class ClassicChannelEx(ClassicChannel): diff --git a/qns/simulator/stablepool.py b/qns/simulator/stablepool.py index 9f0e586..0e845fb 100644 --- a/qns/simulator/stablepool.py +++ b/qns/simulator/stablepool.py @@ -30,7 +30,7 @@ def __eq__(self, other) -> bool: return self.event == other.event and self.seq == other.seq def __lt__(self, other) -> bool: - return self.event < other.event or (@ + return self.event < other.event or ( self.event == other.event and self.seq < other.seq ) diff --git a/test/entity/test_cchannelex.py b/test/entity/test_cchannelex.py index f2ad33d..969c0ac 100644 --- a/test/entity/test_cchannelex.py +++ b/test/entity/test_cchannelex.py @@ -1,8 +1,10 @@ from qns.simulator.event import Event from qns.simulator import Simulator, func_to_event -from qns.utils.log import * from qns.simulator.stablepool import StableEventPool -from qns.entity import * +from qns.entity.node.node import QNode +from qns.entity.node.app import Application +from qns.utils.log import install +from qns.entity.cchannel.cchannel import ClassicChannel, ClassicPacket from qns.entity.cchannel.cchannel_ex import ClassicChannelEx From f0f3c74325c221385f703a274091988947f969dc Mon Sep 17 00:00:00 2001 From: hsc Date: Thu, 14 May 2026 10:14:37 +0800 Subject: [PATCH 2/5] Update pytest error --- qns/entity/cchannel/cchannel_ex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qns/entity/cchannel/cchannel_ex.py b/qns/entity/cchannel/cchannel_ex.py index 23ea16f..663b90c 100644 --- a/qns/entity/cchannel/cchannel_ex.py +++ b/qns/entity/cchannel/cchannel_ex.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from typing import List +from typing import List, Union from qns.simulator.ts import Time from qns.entity.node.node import QNode @@ -37,7 +37,7 @@ def __init__( name: str = None, node_list: List[QNode] = [], bandwidth: int = 0, - delay: float | DelayModel = 0, + delay: Union[float, DelayModel] = 0, length: float | None = 0, drop_rate: float = 0, max_buffer_size: int = 0, From 0efcc3ce737fdb08b0d9474b2db38dca3f48413a Mon Sep 17 00:00:00 2001 From: hsc Date: Thu, 14 May 2026 10:20:29 +0800 Subject: [PATCH 3/5] update error --- qns/entity/cchannel/cchannel_ex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qns/entity/cchannel/cchannel_ex.py b/qns/entity/cchannel/cchannel_ex.py index 663b90c..cc4bd9c 100644 --- a/qns/entity/cchannel/cchannel_ex.py +++ b/qns/entity/cchannel/cchannel_ex.py @@ -38,7 +38,7 @@ def __init__( node_list: List[QNode] = [], bandwidth: int = 0, delay: Union[float, DelayModel] = 0, - length: float | None = 0, + length: Union[float, None] = 0, drop_rate: float = 0, max_buffer_size: int = 0, ): From 0235ae259abf1291059d13f10d9d44a0313834c0 Mon Sep 17 00:00:00 2001 From: hsc Date: Thu, 14 May 2026 10:31:11 +0800 Subject: [PATCH 4/5] update code flake8 and pytest error of ccex and stablepool --- test/entity/test_cchannelex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/entity/test_cchannelex.py b/test/entity/test_cchannelex.py index 969c0ac..728f69f 100644 --- a/test/entity/test_cchannelex.py +++ b/test/entity/test_cchannelex.py @@ -50,7 +50,7 @@ def recv(self, node, event: Event): self.recved_time.append(self._simulator.tc) -def test(ex, tparam): +def test(is_used, tparam): sim = Simulator(0, 10, pool_cls=StableEventPool) install(sim) @@ -59,7 +59,7 @@ def test(ex, tparam): n2 = QNode("n2") global c12 - if not ex: + if not is_used: c12 = ClassicChannel( bandwidth=tparam[0], drop_rate=tparam[1], From dd07d186a38b8de94c3fe58d4a65ee9c4d9f0f0c Mon Sep 17 00:00:00 2001 From: HSC Date: Thu, 14 May 2026 10:51:17 +0800 Subject: [PATCH 5/5] update code flake8 and pytest error of ccex and stablepool --- test/entity/test_cchannelex.py | 51 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/test/entity/test_cchannelex.py b/test/entity/test_cchannelex.py index 728f69f..a8a1154 100644 --- a/test/entity/test_cchannelex.py +++ b/test/entity/test_cchannelex.py @@ -50,15 +50,13 @@ def recv(self, node, event: Event): self.recved_time.append(self._simulator.tc) -def test(is_used, tparam): +def _run_sim(is_used, tparam): sim = Simulator(0, 10, pool_cls=StableEventPool) - install(sim) n1 = QNode("n1") n2 = QNode("n2") - global c12 if not is_used: c12 = ClassicChannel( bandwidth=tparam[0], @@ -96,27 +94,30 @@ def test(is_used, tparam): s1.start() s2.start() - sim.run() - print(f"n1->n2: {r1.recved}") - print(f"time:{r1.recved_time}") - print(f"\nn2->n1: {r2.recved}") - print(f"time:{r2.recved_time}") - - -bidir = (2, 0, 0, 1) -print("============================") -print("bidir w/o Ex:") -test(False, bidir) -print("---------------") -print("bidir w/ Ex:") -test(True, bidir) - -reliable = (0, 0.5, 1, 0) -print("============================") -print("reliable w/o Ex:") -test(False, reliable) -print("---------------") -print("reliable w/ Ex:") -test(True, reliable) + print(f"\nn1->n2: {r1.recved}, time: {r1.recved_time}") + print(f"n2->n1: {r2.recved}, time: {r2.recved_time}") + + +def test_bidir_without_ex(): + print("\n--- bidir w/o Ex ---") + _run_sim(False, (2, 0, 0, 1)) + +def test_bidir_with_ex(): + print("\n--- bidir w/ Ex ---") + _run_sim(True, (2, 0, 0, 1)) + +def test_reliable_without_ex(): + print("\n--- reliable w/o Ex ---") + _run_sim(False, (0, 0.5, 1, 0)) + +def test_reliable_with_ex(): + print("\n--- reliable w/ Ex ---") + _run_sim(True, (0, 0.5, 1, 0)) + + +test_bidir_without_ex() +test_bidir_with_ex() +test_reliable_without_ex() +test_reliable_with_ex() \ No newline at end of file