1. pandas read_json
# 使用单元测试框架(Unittest)来写
import unittest
import pandas as pd
# 定义一个测试类:也就是一个testCase,并继承unittest.TestCase
# 该代码单元的测试方法都写在这个testCase测试类中
class TestCase(unittest.TestCase):
# 定义测试方法1:必须以test开头
def test_demo(self):
pass
def test_read_json(self):
json_df = pd.read_json("./20220531_json_test.json", lines=True, encoding='utf-8')
# print(type(json_df))
# print(json_df)
# test_df1 = json_df[["col1", "col2"]]
# print(test_df1)
test_df2 = json_df[["id", "use_id", "col1", "cil2"]]
print(test_df2)
def test_read_json_time(self):
json_df1 = pd.read_json("./20220531_json_test_1.json", lines=True, encoding='utf-8')[[["id", "use_id", "col1", "cil2"]]
json_df2 = pd.read_json("./20220531_json_test_2.json", lines=True, encoding='utf-8')[["id", "use_id", "col1", "cil2"]]
print(json_df1)
print(json_df2)
if __name__ == "__main__":
# 执行该测试类
# unittest.main()方法会搜索该模块下所有以test开头的测试用例方法,并自动执行
unittest.main()
持续更新......