import import_module from PYSTUDY.loglib import Logger from PYSTUDY.unittestlib import run_one_test, TestCase from PYSTUDY.oslib import getcwd from PYSTUDY.threadinglib import create_thread, active_count def write_log(logger, msg): for i in range(100000): logger.log(msg) class LoglibTest(TestCase): def test_logfile(self): fileName = getcwd() + '/log_data/' + 'test_logfile.log' log = Logger('test_logfile', fileName) tasks = [] for i in range(100): t = create_thread(True, write_log, log, "mm5201314_%d" % i) t.start() tasks.append(t) for t in tasks: t.join() if __name__ == '__main__': run_one_test(LoglibTest, 'test_logfile')
import import_module from PYSTUDY.processlib import create_process, start_process, get_process_pid from PYSTUDY.unittestlib import TestCase, run_one_test def f(): i = 0 while True: print(i) i += 1 class ProcesslibTest(TestCase): def test_process(self): bp = create_process(True, 'test', f) start_process(bp) if __name__ == '__main__': run_one_test(ProcesslibTest, 'test_process') input()
} sql = 'select * from xx where catId=319 limit 10' mp = get_mysql_pool(**kwargs) datas = mp.execute(sql) print(datas) mp.close() def test_insert_id(self): kwargs = { 'user': '******', 'host': '192.168.80.4', 'password': '******', 'db': 'xx', 'size': 20, 'isSync': False, } sql = ('insert into category(name, url, totalPages, updatedTime, responseTime)' ' values("test", "www.test.com", 1, 0, 0)') mp = get_mysql_pool(**kwargs) insertId = mp.execute(sql) print(insertId) mp.close() if __name__ == '__main__': run_one_test(MySQLLIBTest, 'test_async') # run_one_test(MySQLLIBTest, 'test_async_kwargs') # run_one_test(MySQLLIBTest, 'test_kwargs') # run_one_test(MySQLLIBTest, 'test_factory_method') # run_one_test(MySQLLIBTest, 'test_insert_id')
# host = 'www.whsjyr.net' i = 1 protocol = 'udp' while i < 65536: if active_count() <= 100: # 这里将False改为True,线程都不会运行,不是说不运行,主线程退出,其它线程都死掉了 create_thread(False, conn, protocol, self.host, i).start() i += 1 else: sleep(2) def test_udp(self): conn('udp', self.host, 27019) def test_udp_raw_sock(self): import socket import logging logging.basicConfig(level=logging.DEBUG) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.settimeout(10) s.sendto(b'', ('localhost', 8000)) LOG.log(s.recv(1024)) LOG.log('等待主机返回信息') s.close() if __name__ == '__main__': # run_one_test(ThreadinglibTest, 'test_thread') run_one_test(ThreadinglibTest, 'test_udp_raw_sock')
img = resize(img, 100, 100) # img.show() def test_gps(self): img = open_img("pillib_data/mmexport1507584906988.jpg") print(GPS().get_gps(img)) def test_resize(self): src = "pillib_data/我.jpg" dst = 'pillib_data/缩小的我.jpg' src_size = getsize(src) print('源文件的大小为:', src_size) img = open_img(src) img.show() # img.show() width, height = get_size(img) print(width, height) img = resize(img, width // 2, height // 2) save(dst, img) dimg = open_img(dst) dimg.show() dst_size = getsize(dst) print('目标文件的大小:', dst_size) if __name__ == '__main__': run_one_test(PillibTestCase, 'test_resize')
from PYSTUDY.unittestlib import TestCase, run_one_test import import_module from PYSTUDY.oslib import parent_dir, listdir, getsize class OSlibTestCase(TestCase): def test_parent_dir(self): cwd = __file__ print('cwd:', cwd) print(parent_dir(cwd)) prd = parent_dir("/PYSTUDY/a") print('prd:', prd) def test_listdir(self): print(listdir('.')) def test_getsize(self): cwd = __file__ print(getsize(cwd)) print(1024 * 1024 * 100) if __name__ == '__main__': run_one_test(OSlibTestCase, 'test_getsize')