python高级脚本
自动化测试脚本
import unittest
class TestCalculator(unittest.TestCase):
def test_addition(self):
self.assertEqual(2 + 2, 4)
def test_subtraction(self):
self.assertEqual(5 - 3, 1)
if __name__ == "__main__":
unittest.main()
结果:
Ran 2 tests in 0.019s
FAILED (failures=1)
1 != 2
Expected :2
Actual :1
<Click to see difference>
Traceback (most recent call last):
File "D:\example_test\test_auto.py", line 9, in test_subtraction
self.assertEqual(5 - 3, 1)
AssertionError: 2 != 1
数据加密和解密工具--url编码
from urllib.parse import quote, unquote
name = "王大锤"
# 编码
utf8_name = quote(name) # utf-8
print(utf8_name)
# %E7%8E%8B%E5%A4%A7%E9%94%A4 长度是 9
gbk_name = quote(name, encoding="gbk")
print(gbk_name)
# %CD%F5%B4%F3%B4%B8 长度是 6
# 解码
print(unquote(utf8_name))
print(unquote(gbk_name, encoding="gbk"))
# 王大锤
结果:
%E7%8E%8B%E5%A4%A7%E9%94%A4
%CD%F5%B4%F3%B4%B8
王大锤
王大锤
数据加密和解密工具--base64编码
import base64
name = "王大锤"
# 编码: 字符串 -> 二进制 -> base64编码
b64_name = base64.b64encode(name.encode())
print(b64_name)
# b'546L5aSn6ZSk'
# 解码:base64编码 -> 二进制 -> 字符串
print(base64.b64decode(b64_name).decode())
# 王大锤
结果:
b'546L5aSn6ZSk'
王大锤
标签:脚本,name,python,self,base64,高级,test,大锤,print
From: https://www.cnblogs.com/bonne-chance/p/18122350