mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
update unittest
This commit is contained in:
parent
e1fb488b29
commit
6eb79f9b81
37
examples/unittest/test3.py
Normal file
37
examples/unittest/test3.py
Normal file
@ -0,0 +1,37 @@
|
||||
import socket
|
||||
import random
|
||||
import unittest
|
||||
|
||||
|
||||
class TestUnittestAssertions(unittest.TestCase):
|
||||
def testSocket(self):
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
host = "127.0.0.1"
|
||||
port = 9999 + random.randint(0, 1000) + 1
|
||||
print("port:", port)
|
||||
server.bind((host, port))
|
||||
server.listen(5)
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect((host, port))
|
||||
|
||||
accept, addr = server.accept()
|
||||
self.assertEqual(addr, "127.0.0.1")
|
||||
|
||||
print("recv from client: %s" % str(addr))
|
||||
|
||||
client.send("send test from client".encode())
|
||||
print("server recv:", accept.recv(1024).decode())
|
||||
|
||||
accept.send("send test from server".encode())
|
||||
print("client recv:", client.recv(1024).decode())
|
||||
|
||||
accept.close()
|
||||
client.close()
|
||||
server.close()
|
||||
|
||||
|
||||
suit = unittest.TestSuite("test1")
|
||||
suit.addTest(TestUnittestAssertions())
|
||||
runner = unittest.TextTestRunner()
|
||||
res = runner.run(suit)
|
@ -1,3 +1,6 @@
|
||||
import PikaStdLib
|
||||
mem = PikaStdLib.MemChecker()
|
||||
|
||||
class TestResult:
|
||||
def __init__(self):
|
||||
self.errorsNum = 0
|
||||
@ -70,8 +73,14 @@ class TestCase:
|
||||
self.test_fn = getattr(self, name)
|
||||
print("[ RUN ] %s.%s" % (suite_name, name))
|
||||
try:
|
||||
mem_before = 0.0
|
||||
mem_after = 0.0
|
||||
mem_before = mem.getNow()
|
||||
self.test_fn()
|
||||
mem_after = mem.getNow()
|
||||
print("[ OK ] %s.%s" % (suite_name, name))
|
||||
if mem_after != mem_before:
|
||||
print("[ MEM LACK ]", mem_after - mem_before)
|
||||
except:
|
||||
print("[ FAILED ] %s.%s" % (suite_name, name))
|
||||
result.errorsNum += 1
|
||||
|
@ -1,3 +1,6 @@
|
||||
import PikaStdLib
|
||||
mem = PikaStdLib.MemChecker()
|
||||
|
||||
class TestResult:
|
||||
def __init__(self):
|
||||
self.errorsNum = 0
|
||||
@ -70,8 +73,14 @@ class TestCase:
|
||||
self.test_fn = getattr(self, name)
|
||||
print("[ RUN ] %s.%s" % (suite_name, name))
|
||||
try:
|
||||
mem_before = 0.0
|
||||
mem_after = 0.0
|
||||
mem_before = mem.getNow()
|
||||
self.test_fn()
|
||||
mem_after = mem.getNow()
|
||||
print("[ OK ] %s.%s" % (suite_name, name))
|
||||
if mem_after != mem_before:
|
||||
print("[ MEM LACK ]", mem_after - mem_before)
|
||||
except:
|
||||
print("[ FAILED ] %s.%s" % (suite_name, name))
|
||||
result.errorsNum += 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user