diff --git a/fishbase/fish_common.py b/fishbase/fish_common.py index 7b52aba..8807fa5 100644 --- a/fishbase/fish_common.py +++ b/fishbase/fish_common.py @@ -107,12 +107,6 @@ def get_uuid(kind): get_time_uuid = functools.partial(get_uuid, udTime) -# 2019.01.05 v1.1.6 edit by Hu Jun, #152 -def if_any_elements_is_space(dic): - show_deprecation_warn('if_any_elements_is_space', 'has_space_element') - return has_space_element(dic) - - # 2017.2.22 edit by David.Yi, #19007 # 2018.6.29 v1.0.14 edit by Hu Jun,#62 # 2019.1.5 v1.1.6 edit by Hu Jun, #152 @@ -187,17 +181,12 @@ def if_any_elements_is_number(source): return True -# 2019.01.05 v1.1.6 edit by Hu Jun, #152 -def if_any_elements_is_letter(source): - show_deprecation_warn('if_any_elements_is_letter', 'fish_isalpha') - return fish_isalpha(source) - - -# 2017.3.30 create by Leo #11004 -# 功能:监测list或者元素是否只包含英文 +# 功能:检查 list 或者元素是否只包含英文 # 输入:source 是参数列表或元组 # 输出:True:只包含英文;False:不只包含英文 -def fish_isalpha(source): +# 2017.3.30 create by Leo #11004 +# 2020.3.28 edit by David Yi, #263 +def is_alpha(source): for i in source: if not i.isalpha(): @@ -206,34 +195,6 @@ def fish_isalpha(source): return True -# 2019.01.06 edit by Hu Jun, #152 -# 2019.01.21 edit by Hu Jun, #200 -class GetMD5(object): - @staticmethod - def string(s, salt=None): - from fishbase.fish_crypt import FishMD5 - show_deprecation_warn('GetMD5.sting', 'fish_crypt.FishMD5.string') - return FishMD5.string(s, salt=salt) - - @staticmethod - def file(filename): - from fishbase.fish_crypt import FishMD5 - show_deprecation_warn('GetMD5.file', 'fish_crypt.FishMD5.file') - return FishMD5.file(filename) - - @staticmethod - def big_file(filename): - from fishbase.fish_crypt import FishMD5 - show_deprecation_warn('GetMD5.big_file', 'fish_crypt.FishMD5.big_file') - return FishMD5.big_file(filename) - - @staticmethod - def hmac_md5(s, salt): - from fishbase.fish_crypt import FishMD5 - show_deprecation_warn('GetMD5.hmac_md5', 'fish_crypt.FishMD5.hmac_md5') - return FishMD5.hmac_md5(s, salt) - - # 2018.5.15 v1.0.11 original by Lu Jie, edit by David Yi, #19029 def if_json_contain(left_json, right_json, op='strict'): """ @@ -271,12 +232,6 @@ def if_json_contain(left_json, right_json, op='strict'): return True -# 2019.01.05 v1.1.6 edit by Hu Jun, #152 -def splice_url_params(dic): - show_deprecation_warn('splice_url_params', 'join_url_params') - return join_url_params(dic) - - # 2018.3.8 edit by Xiang qinqin # 2018.5.15 edit by David Yi, #19030 # v1.0.15 edit by Hu Jun, #67 @@ -357,12 +312,6 @@ def sorted_list_from_dict(p_dict, order=odASC): return o_list[::-1] -# 2019.01.05 v1.1.6 edit by Hu Jun, #152 -def is_contain_special_char(p_str, check_style=charChinese): - show_deprecation_warn('is_contain_special_char', 'has_special_char') - return has_special_char(p_str, check_style=check_style) - - # v1.0.13 edit by David Yi, edit by Hu Jun,#36 # v1.0.14 edit by Hu Jun #38 # 2019.01.05 v1.1.6 edit by Hu Jun, #152 @@ -466,55 +415,6 @@ def find_files(path, exts=None): return files_list -# v1.1.6 edit by Hu Jun, #200 -# v1.1.1 edit by Hu Jun, #115 -# v1.0.14 edit by Hu Jun, #51 -def get_random_str(length, letters=True, digits=False, punctuation=False): - """ - 获得指定长度,不同规则的随机字符串,可以包含数字,字母和标点符号 - - :param: - * length: (int) 随机字符串的长度 - * letters: (bool) 随机字符串是否包含字母,默认包含 - * digits: (bool) 随机字符串是否包含数字,默认不包含 - * punctuation: (bool) 随机字符串是否包含特殊标点符号,默认不包含 - - :return: - * random_str: (string) 指定规则的随机字符串 - - 举例如下:: - - print('--- get_random_str demo---') - print(get_random_str(6)) - print(get_random_str(6, digits=True)) - print(get_random_str(12, punctuation=True)) - print(get_random_str(6, letters=False, digits=True)) - print(get_random_str(12, letters=False, digits=True, punctuation=True)) - print('---') - - 执行结果:: - - --- get_random_str demo--- - nRBDHf - jXG5wR - )I;rz{ob&Clg - 427681 - *"4$0^`2}%9{ - --- - - """ - show_deprecation_warn('get_random_str', 'fish_random.gen_random_str') - from fishbase.fish_random import gen_random_str - return gen_random_str(length, length, has_letter=letters, has_digit=digits, - has_punctuation=punctuation) - - -# 2019.01.05 v1.1.6 edit by Hu Jun, #152 -def remove_duplicate_elements(items, key=None): - show_deprecation_warn('remove_duplicate_elements', 'get_distinct_elements') - return get_distinct_elements(items, key=key) - - # v1.0.15 edit by Hu Jun, #77 #63 def get_distinct_elements(items, key=None): """ @@ -683,12 +583,6 @@ def get_sub_dict(data_dict, key_list, default_value='default_value'): return sub_dict -# 2019.01.05 v1.1.6 edit by Hu Jun, #152 -def transform_hump_to_underline(param_dict): - show_deprecation_warn('transform_hump_to_underline', 'camelcase_to_underline') - return camelcase_to_underline(param_dict) - - # v1.1.1 edit by Hu Jun, #114 def camelcase_to_underline(param_dict): """ @@ -821,26 +715,6 @@ def yaml_conf_as_dict(file_path, encoding=None): return False, {}, 'Unknown error' -# 2019.01.06 edit by Hu Jun, #152 -class GetSha256(object): - @staticmethod - def hmac_sha256(secret, message): - from fishbase.fish_crypt import FishSha256 - show_deprecation_warn('GetSha256.hmac_sha256', 'FishSha256.hmac_sha256') - return FishSha256.hmac_sha256(secret, message) - - @staticmethod - def hashlib_sha256(message): - from fishbase.fish_crypt import FishSha256 - show_deprecation_warn('GetSha256.hashlib_sha256', 'FishSha256.hashlib_sha256') - return FishSha256.hashlib_sha256(message) - - -# v1.0.14 original by Jia Chunying, edit by Hu Jun, #27 -# v1.1.3 edit by Hu Jun, #100 move hmac_sha256 to GetSha256 -hmac_sha256 = GetSha256.hmac_sha256 - - # 2019.06.11 edit by Hu Jun, #235 # 2019.06.15 edit by Hu Jun, #238 class RMBConversion(object): diff --git a/test/test_common.py b/test/test_common.py index 909454a..378e9bd 100644 --- a/test/test_common.py +++ b/test/test_common.py @@ -22,19 +22,6 @@ # 2018.5.26 v1.0.13 #19038 edit, 增加 get_uuid() 的 ut class TestFishCommon(object): - # 测试 FishMD5() tc - def test_md5_01(self): - assert GetMD5.string('hello world!') == 'fc3ff98e8c6a0d3087d515c0473f8677' - # different line separator will get different md5 value - assert GetMD5.file(conf_filename) in ['79e1a2614f1afc8297856b7ffdaf4c47', - 'a0a36ccf1bce193658559e092ac43b6d'] - assert GetMD5.big_file(conf_filename) in ['79e1a2614f1afc8297856b7ffdaf4c47', - 'a0a36ccf1bce193658559e092ac43b6d'] - salt_0 = 'salt' - assert GetMD5.hmac_md5('hello world!', salt_0) == '191f82804523bfdafe0188bbbddd6587' - salt_1 = 'm4xV2yGFSn' - assert GetMD5.string('hello world!', salt_1) == '984d47991401fad7d920a30f715cfd22' - # 测试 if_json_contain() tc def test_json_contain_01(self): @@ -56,7 +43,6 @@ def test_join_url_params_01(self): dic02 = {'key1': '1111', 'key2': 'value2'} assert join_url_params(dic01) == '?key1=value1&key2=value2' - assert splice_url_params(dic02) != '?key1=value1&key2=value2' # test get_uuid() tc def test_get_uuid_01(self): @@ -117,8 +103,6 @@ def test_has_special_char_01(self): assert has_special_char(num_str, check_style=charNum) is True assert has_special_char(non_num_str, check_style=10020) is False - assert is_contain_special_char(non_num_str, check_style=10020) is False - if sys.version > '3': chinese_str1 = u'有zhongwen'.encode('gbk') with pytest.raises(TypeError): @@ -131,56 +115,9 @@ def test_find_files_01(self): assert len(find_files(path)) >= len(find_files(path, exts=exts_list)) - # test hmac_sha256() tc - def test_hmac_sha256_01(self): - message = 'Hello HMAC' - secret = '12345678' - assert (hmac_sha256(secret, message) == - '5eb8bdabdaa43f61fb220473028e49d40728444b4322f3093decd9a356afd18f') - - # test FishSha256.hmac_sha256() tc - def test_hmac_sha256_02(self): - message = 'Hello HMAC' - secret = '12345678' - assert (GetSha256.hmac_sha256(secret, message) == - '5eb8bdabdaa43f61fb220473028e49d40728444b4322f3093decd9a356afd18f') - - # test FishSha256.hashlib_sha256() tc - def test_hashlib_sha256_01(self): - message = 'Hello HMAC' - assert (GetSha256.hashlib_sha256(message) == - '4a1601381dfb85d6e713853a414f6b43daa76a82956911108512202f5a1c0ce4') - - # test get_random_str() tc - def test_get_random_str_01(self): - assert len(get_random_str(6)) == 6 - - import re - - digits_pattern = re.compile('[0-9]+') - letters_pattern = re.compile('[a-zA-Z]+') - letters_digits_pattern = re.compile('[0-9a-zA-Z]+') - punctuation_ord_list = [ord(item) for item in string.punctuation] - - letter_str = get_random_str(6) - assert letters_pattern.match(letter_str) - - letter_digits_str = get_random_str(80, digits=True) - assert letters_digits_pattern.match(letter_digits_str) - - digits_str = get_random_str(6, letters=False, digits=True) - assert digits_pattern.match(digits_str) - - punctuation_str = get_random_str(6, letters=False, punctuation=True) - for item in punctuation_str: - assert ord(item) in punctuation_ord_list - - assert len(get_random_str(12, letters=False, digits=True, punctuation=True)) == 12 - # test has_space_element() tc def test_has_space_element_01(self): - assert if_any_elements_is_space([1, 2, 'test_str']) is False - + assert has_space_element([1, 2, 'test_str']) is False assert has_space_element([0, 2]) is False @@ -200,8 +137,7 @@ def test_has_space_element_01(self): def test_get_distinct_elements_01(self): list1 = [1, 5, 2, 1, 9, 1, 5, 10] assert list(get_distinct_elements(list1)) == [1, 5, 2, 9, 10] - assert list(remove_duplicate_elements(list1)) == [1, 5, 2, 9, 10] - + list2 = [{'x': 1, 'y': 2}, {'x': 1, 'y': 3}, {'x': 1, 'y': 2}, {'x': 2, 'y': 4}] dict_demo1 = get_distinct_elements(list2, key=lambda d: (d['x'], d['y'])) @@ -266,11 +202,9 @@ def test_get_sub_dict_02(self): def test_camelcase_to_underline(self): hump_param_dict = {'firstName': 'Python', 'Second_Name': 'zhangshan', 'right_name': 'name'} result_0 = camelcase_to_underline(hump_param_dict) - result_1 = transform_hump_to_underline(hump_param_dict) - + assert 'firstName' not in result_0 assert 'first_name' in result_0 - assert 'first_name' in result_1 # test find_same_between_dicts() tc def test_find_same_between_dicts_01(self): @@ -308,14 +242,12 @@ def test_yaml_conf_as_dict_02(self): assert ds[-1] == 'File not exist' # 测试 fish_isalpha() tc - def test_fish_isalpha(self): + def test_is_alpha(self): letter_str = 'test' mix_str = 'mix123' - assert fish_isalpha(letter_str) - assert not fish_isalpha(mix_str) - assert not if_any_elements_is_letter(mix_str) - + assert is_alpha(letter_str) + assert not is_alpha(mix_str) # 测试 an2cn() tc def test_an2cn_01(self):