def _test_re_match_a_word(): match_str = "class" content_str = "classtest this is " ret = pyre.re_match_a_word(match_str, content_str) real_value = ret.group() expect_value = "class" pylog.test_compare_value(real_value, expect_value)
def _test_re_search_re_str(): match_str = r"b(ab)*" content_str = "ababababa" ret = pyre.re_search(match_str, content_str) real_value = ret.group() expect_value = "bababab" pylog.test_compare_value(real_value, expect_value)
def _test_re_search_a_word_tail(): match_str = "class" content_str = "my tailclass atest" ret = pyre.re_search_a_word_tail(match_str, content_str) real_value = ret.group() expect_value = "class" pylog.test_compare_value(real_value, expect_value)
def _test_check_module(): module_name = "pylog" is_install = pymodule.check_is_install_module(module_name) pylog.test_compare_value(is_install, True) module_name = "pytest" is_install = pymodule.check_is_install_module(module_name) pylog.test_compare_value(is_install, True)
def _test_write_read_file(): write_con = "ok this is my test\n" file_object = pyfile.open_file('./test_pyfile/', 'testfile') file_object.write(write_con) file_object.close() file_object = pyfile.open_file('./test_pyfile/', 'testfile', open_type='r') con = file_object.read() pylog.test_compare_value(con, write_con)
def _test_get_center_content(): match_str = ".*?" front_str = "aaaa" behind_str = "ccc" content_str = "aaaat1tccc aaaat2tcccxaaaat3tccclll" ret = pyre.get_center_content(front_str, behind_str, content_str, match_str) real_value = ret expect_value = "t1t" pylog.test_compare_value(real_value, expect_value)
def _test_re_find_all_center_content2(): match_str = ".*" front_str = "aaaa" behind_str = "ccc" content_str = "aaaat1tccc aaaat2tcccxaaaat3tccclll" ret = pyre.re_find_all_center_content(front_str, behind_str, content_str, match_str) real_value = ret expect_value = ['t1tccc aaaat2tcccxaaaat3t'] pylog.test_compare_value(real_value, expect_value)
def _test_default(): content = b"hello world" encodeStr = pydec_encry.EncryCode(content) real_value = encodeStr expect_value = b"QTPkQEyif8xPzalChdHqSQ==" pylog.test_compare_value(real_value, expect_value) decodeStr = pydec_encry.DecryCode(encodeStr) real_value = decodeStr expect_value = content pylog.test_compare_value(real_value, expect_value)
def test(): obj = Animal() pylog.test_compare_value("Animal move style is Animal move",obj.move()) obj = Plant() pylog.test_compare_value("Plant move style is Plant just stay",obj.move()) obj = Cat() pylog.test_compare_value("Cat move style is Cat walk",obj.move()) obj = Dog() pylog.test_compare_value("Dog move style is Dog run",obj.move()) obj = Fish() pylog.test_compare_value("Fish move style is Fish swim",obj.move())
def _test_self_key(): content = b"hello world" pydec_encry.ENCRY_KEY = "12345678" #need 8 bytes encodeStr = pydec_encry.EncryCode(content) real_value = encodeStr expect_value = b"27Vzf1M8YVkoKD5gjV3wcQ==" pylog.test_compare_value(real_value, expect_value) decodeStr = pydec_encry.DecryCode(encodeStr) real_value = decodeStr expect_value = content pylog.test_compare_value(real_value, expect_value)
def _test_sucess(): url = "http://imgsrc.baidu.com/forum/w%3D580%3B/sign=7dfd5b126a09c93d07f20effaf06f9dc/34fae6cd7b899e51bb592b084fa7d933c9950dd2.jpg" (web_status, img_type, img_weight, img_height) = pyimg.get_img_info(url) pylog.test_compare_value(web_status, True) pylog.test_compare_value(img_type, 'JPEG') pylog.test_compare_value(img_weight, 580) pylog.test_compare_value(img_height, 580)
def pickle_test(): dic = { "key": "111", "id": 222, "value": 333, "name": "nihao", "age": 18, } file_name = 'hello' ret = pypickle.save(dic, file_name) pylog.test_compare_value(True, ret) if ret == True: dic = pypickle.read(file_name) pylog.test_compare_value(18, dic["age"])
def _test_fail(): url = "http://mhimg1.mnsfz.com/pic/meihuo/2015-2-20/1/13547560956462979517680.jpg" (web_status, img_type, img_weight, img_height) = pyimg.get_img_info(url) pylog.test_compare_value(web_status, False) pylog.test_compare_value(img_type, 0) pylog.test_compare_value(img_weight, 0) pylog.test_compare_value(img_height, 0)
def _json_fail_test(): test_str = "json fail" json_con = pyjson.json_fail(test_str) json_dic = pyjson.json_to_dict(json_con) pylog.test_compare_value(json_dic["request_method"],"GET") pylog.test_compare_value(json_dic["data"],test_str) pylog.test_compare_value(json_dic["result"],"fail")
def _json_method_not_support_test(): test_str = "method not support" json_con = pyjson.json_method_not_support(test_str) json_dic = pyjson.json_to_dict(json_con) pylog.test_compare_value(json_dic["request_method"],"GET") pylog.test_compare_value(json_dic["data"],test_str) pylog.test_compare_value(json_dic["result"],"fail")
def _test_sqlite_table(): tb_obj = pysqlite.SQLiteTable() dic = {'key': 9, 'content': 'test'} tb_obj.insert_item_with_dic(dic) tb_obj.insert_item(col_names=['key', 'content'], data_value=[10, 'test']) tb_obj.insert_item(col_names=['key', 'content'], data_value=[11, 'test']) tb_obj.insert_item(col_names=['key', 'content'], data_value=[12, 'test']) tb_obj.insert_item(col_names=['key', 'content'], data_value=[13, 'test']) tb_obj.insert_item(col_names=['key', 'content'], data_value=[14, 'test']) tb_obj.insert_item(col_names=['key', 'content'], data_value=[15, 'test']) ret = tb_obj.query_item() real_value = len(ret) expect_value = 7 pylog.test_compare_value(real_value, expect_value) ret = tb_obj.delete_item("tb_id=4") real_value = ret expect_value = True pylog.test_compare_value(real_value, expect_value) ret = tb_obj.query_item() real_value = len(ret) expect_value = 6 pylog.test_compare_value(real_value, expect_value) ret = tb_obj.update_item(update_str='content="updatewa"', key_str='tb_id=2') real_value = ret expect_value = True pylog.test_compare_value(real_value, expect_value) ret = tb_obj._drop_table() real_value = ret expect_value = True pylog.test_compare_value(real_value, expect_value) ret = tb_obj.database_name os.popen("rm %s.db" % ret)
def sqlObjectTest(): tb_obj = pymysqldb.SQLTable() dic = {} dic['pid'] = 5 dic['name'] = 'test' ret = tb_obj.insert_item_with_dic(dic) pylog.test_compare_value(True, ret) tb_obj.insert_item(col_names=['pid', 'name'], data_value=[4, 'test']) pylog.test_compare_value(True, ret) tb_obj.insert_item(col_names=['pid', 'name'], data_value=[3, 'test']) pylog.test_compare_value(True, ret) tb_obj.insert_item(col_names=['pid', 'name'], data_value=[6, 'test']) pylog.test_compare_value(True, ret) ret = tb_obj.delete_item("pid=4") pylog.test_compare_value(True, ret) ret = tb_obj.update_item(update_str='name="update_name"', key_str='pid=3') pylog.test_compare_value(True, ret) ret = tb_obj.update_item() pylog.test_compare_value(False, ret) query_content = tb_obj.query_item() ret = len(query_content) pylog.test_compare_value(3, ret) # if query_content: # for row in query_content: # print(row) ret = tb_obj._drop_table() pylog.test_compare_value(True, ret) ret = tb_obj._drop_database() pylog.test_compare_value(True, ret)
def test(): pylog.test_compare_value(pyjson_data.JSON_TYPE_OK, "ok") pylog.test_compare_value(pyjson_data.JSON_TYPE_FAIL, "fail") pylog.test_compare_value(pyjson_data.JSON_KEY_RESULT, "result") pylog.test_compare_value(pyjson_data.JSON_KEY_DATA, "data") pylog.test_compare_value(pyjson_data.JSON_KEY_STATE, "state") pylog.test_compare_value(pyjson_data.REQUEST_METHOD, "request_method") pylog.test_compare_value(pyjson_data.REQUEST_METHOD_NOT_SUPPORT, "http method not support") pylog.test_compare_value(pyjson_data.REQUEST_GET, "GET") pylog.test_compare_value(pyjson_data.REQUEST_POST, "POST") pylog.test_compare_value(pyjson_data.NO_DESCRIPTION, "no description")
def _test_get_file_full_name(): test_file_path = "./test_pyfile/test" test_file_name = "test.py" file_name = pyfile.get_file_full_name(test_file_path, test_file_name) pylog.test_compare_value(file_name, "./test_pyfile/test/test.py") file_object = pyfile.open_file(test_file_path, test_file_name)
def _test_http_get(): url = "http://www.baidu.com" is_sucess, ret = pyhttp.http_get(url) pylog.test_compare_value(is_sucess, True)
def _test_nohup_start_python_progress(): progress_name = "yourname" ret = pyprocess.nohup_start_python_progress(progress_name) pylog.test_compare_value(ret, True)
def _test_re_match_first_one_word(): content_str = "string goes here" ret = pyre.re_match_first_one_word(content_str) real_value = ret.group() expect_value = "string" pylog.test_compare_value(real_value, expect_value)
def _test_re_match_first_one_word2(): content_str = "23 45 414 45 " ret = pyre.re_match_first_one_word(content_str) real_value = ret expect_value = None pylog.test_compare_value(real_value, expect_value)
def _get_inner_ip_test(): info = pylinux.get_inner_ip() pylog.test_compare_value(info, "127.0.1.1") _show_test("内网ip", info)