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