• 111 Lucky


    1.

    from openpyxl import load_workbook
    
    
    class DoExcel:
        def __init__(self, file_name, sheet_name):
            self.file_name = file_name
            self.sheet_name = sheet_name
            self.sheet_obj = load_workbook(self.file_name)[self.sheet_name]
            self.max_row = self.sheet_obj.max_row
            self.max_column = self.sheet_obj.max_column
    
        def get_data(self, i, j):
            return self.sheet_obj.cell(i, j).value
    
    if __name__ == '__main__':
        value = DoExcel('test.xlsx', 'test').get_data(2, 1)
        print(value)

    2.

    import unittest
    from xxx.xxx.xxx import HttpRequest
    from xxx.xxx.xxx import DoExcel
    
    
    class TestHttp(unittest.TestCase):
        def setUp(self):
            pass
    
        def __init__(self, methodName, url, data, method, expected):
            super(TestHttp, self).__init__(methodName)
            self.url = url
            self.data = data
            self.method = method
            self.expected = expected
    
        def test_api(self):
            res = HttpRequest().http_request(self.url, self.data, self.method)
    
            try:
                self.assertEqual(self.expected, res.json()['code'])  
            except AssertionError as e:
                print("'test_api's error is{}".format(e))
                raise e
    
        def tearDown(self):
            pass
    
    
    if __name__ == '__main__':
    
        suite = unittest.TestSuite()
        t = DoExcel('test.xlsx', 'test')
        for i in range(2, t.max_row + 1):
            suite.addTest(TestHttp('test_api', t.get_data(i, 1), t.get_data(i, 2), t.get_data(i, 3), t.get_data(i, 4)))
        runner = unittest.TextTestRunner()
        runner.run(suite)
  • 相关阅读:
    Python易忽略要点记录二
    Python使用的几个小技巧
    MySQL内容整理二
    C++面向对象知识总结
    AssemblyInfo 的作用
    中国新年第一篇
    function函数的运用
    C语言1博客作业03
    C语言1博客作业02
    .C# 拷贝一个图片到指定文件夹下(IO文件操作实例)
  • 原文地址:https://www.cnblogs.com/continuous-luck/p/16482357.html
Copyright © 2020-2023  润新知