From bbab0010e6c6315c5d6af6bf9e7e938b884636c2 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 10 Jul 2019 13:23:10 +0300 Subject: [PATCH] Moved a test script from network.tcp to tests.core --- src/network/tcp.py | 11 ----------- src/tests/core.py | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/network/tcp.py b/src/network/tcp.py index e06cf89f..5ebd6a21 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -381,14 +381,3 @@ class TCPServer(AdvancedDispatcher): TCPConnection(sock=sock)) except socket.error: pass - - -if __name__ == "__main__": - # initial fill - - for host in (("127.0.0.1", 8448),): - direct = TCPConnection(host) - while asyncore.socket_map: - print "loop, state = %s" % (direct.state) - asyncore.loop(timeout=10, count=1) - continue diff --git a/src/tests/core.py b/src/tests/core.py index ce8e7877..a323be83 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -14,6 +14,8 @@ import unittest import knownnodes import state from helper_msgcoding import MsgEncode, MsgDecode +from network import asyncore_pollchoose as asyncore +from network.tcp import TCPConnection from queues import excQueue knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat') @@ -74,10 +76,21 @@ class TestCore(unittest.TestCase): MsgEncode({'body': 'A msg with no subject'}, 3) except Exception as e: self.fail( - 'Exception %s whyle trying to encode message' + 'Exception %s while trying to encode message' ' with no subject!' % e ) + def test_tcpconnection(self): + """initial fill script from network.tcp""" + try: + for peer in (state.Peer("127.0.0.1", 8448),): + direct = TCPConnection(peer) + while asyncore.socket_map: + print("loop, state = %s" % direct.state) + asyncore.loop(timeout=10, count=1) + except: + self.fail('Exception in test loop') + def _wipe_knownnodes(self): with knownnodes.knownNodesLock: knownnodes.knownNodes = {stream: {} for stream in range(1, 4)}