-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
90 lines (76 loc) · 3.16 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# @Author : bajins https://www.bajins.com
# @File : test.py
# @Version: 1.0.0
# @Time : 5050/9/30 13:00
# @Project: scripts_python
# @Package:
# @Software: PyCharm
# 单元测试框架,主要由四部分组成:测试固件、测试用例、测试套件、测试执行器
import os
import random
import time
import unittest
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls): # 启动执行一次
print("execute setUpClass".center(50, "="))
@classmethod
def tearDownClass(cls): # 结束执行一次
print("execute tearDownClass".center(50, "="))
def setUp(self): # 每条用例执行前都要执行
print("execute setUp".center(50, "="))
def tearDown(self): # 每条用例执行后都要执行
print("execute tearDown".center(50, "="))
def test_one(self): # 注意所有测试方法都需要以test开头
print('execute test_one'.center(50, "="))
self.assertTrue('FOO'.isupper())
def testReptileUtil(self):
# download_taobao_chromedriver()
# download_chromedriver()
from utils.reptile_util import SafeDriver
safe_driver = SafeDriver("https://www.bajins.com") # 触发__del__
# 仅仅从功能上来说,instance 变量与safe_driver变量完全一样
# 所不同的是,使用with启用上下文管理器以后,在退出缩进的时候会执行__exit__中的内容。
with SafeDriver("https://www.bajins.com") as instance: # 触发__exit__
pass
with safe_driver.driver as driver:
pass
def testSystemUtil(self):
# print(get_windows_software())
from utils.system_util import restart_process
restart_process(os.path.abspath(__file__))
def testStringUtil(self):
# print(random.randint(1, 10))
# print(random.randint(5000, 5017))
# from utils.StringUtil import is_empty
# is_empty("")
from utils import string_util
print(string_util.hump_case_underline_lower("oneHTTPRequest12AaureBBBXu"))
print(string_util.underline2hump("hello_word"))
print(string_util.hump2underline("URLCamelCaseHello12Word"))
json_str = """{"userName":"hi"}"""
print(string_util.json_hump2underline(json_str))
def testFileUtil(self):
from utils.file_util import count_dir_size
print(count_dir_size("images"))
from utils.file_util import size_unit_format
print(size_unit_format(25635891))
def testMultipartFileUtil(self):
# t = DownloadWorkerThread(r'http://a3.kuaihou.com/ruanjian/ucdnb.zip', 'd:\\ucdnb.zip', header)
# t.start()
url = input(u"The URL Waiting for downloading:")
filename = input(u"The Filepath to save:")
from utils.multipart_file_util import download
t = download(url, filename)
while t.is_alive():
time.sleep(60)
print("bye")
def testDatabaseUtil(self):
from utils.database_util import Sqlite3
s3 = Sqlite3("test")
s3.excel_to_db_com(r"./test.xlsx", "test", password="test")
if __name__ == '__main__':
unittest.main() # 测试所有