Skip to content

辅助函数测试 tests/utils/test_helpers.py ​

验证 objection.utils.helpers 的字符串处理工具:pretty_concat 截断、sizeof_fmt 字节格式化、get_tokens 引号感知分词、clean_argument_flags 去标志、print_frida_connection_help 连接帮助输出。

📋 模块概览 ​

项目值
文件路径tests/utils/test_helpers.py
被测对象objection.utils.helpers(pretty_concat/sizeof_fmt/get_tokens/clean_argument_flags/print_frida_connection_help)
用例数8
框架pytest + unittest

🎯 测试意图 ​

  • 确认 pretty_concat 短字符串原样返回,超长时右侧截断加 ...,left=True 时左侧加 ...。
  • 确认 sizeof_fmt(3000) 输出 2.9 KiB。
  • 确认 get_tokens 对无引号字符串按空白分词,对带引号字符串合并引号内内容,对未闭合引号返回占位列表。
  • 确认 clean_argument_flags 移除 -- 开头的标志。
  • 确认 print_frida_connection_help 输出含 rooted/patched/serial/wiki 提示。

🧪 用例清单 ​

用例行号验证点
test_pretty_concat_with_less_than_seventy_five_chars14短字符串原样
test_pretty_concat_with_more_than_max_chars19右侧截断加 ...
test_pretty_concat_with_more_than_max_chars_to_the_left24左侧加 ...
test_sizeof_formats_values293000 → 2.9 KiB
test_gets_tokens_without_quotes34按空白分词
test_gets_tokens_with_quotes39合并引号内容
test_gets_tokens_and_handles_missing_quotes44未闭合引号返回占位
test_cleans_argument_lists_with_flags49移除 -- 标志
test_prints_frida_connection_help53输出连接帮助文本

⚙️ 测试手法 ​

纯函数测试,直接调用断言返回值。print_frida_connection_help 用 capture 捕获 stdout 做精确字符串相等。无 mock。

关键代码 tests/utils/test_helpers.py:39:

python
def test_gets_tokens_with_quotes(self):
    result = get_tokens('this is "a test"')
    self.assertEqual(result, ['this', 'is', 'a test'])

🔍 源码索引 ​

用例位置
test_pretty_concat_with_less_than_seventy_five_charstests/utils/test_helpers.py:14
test_pretty_concat_with_more_than_max_charstests/utils/test_helpers.py:19
test_pretty_concat_with_more_than_max_chars_to_the_lefttests/utils/test_helpers.py:24
test_sizeof_formats_valuestests/utils/test_helpers.py:29
test_gets_tokens_without_quotestests/utils/test_helpers.py:34
test_gets_tokens_with_quotestests/utils/test_helpers.py:39
test_gets_tokens_and_handles_missing_quotestests/utils/test_helpers.py:44
test_cleans_argument_lists_with_flagstests/utils/test_helpers.py:49
test_prints_frida_connection_helptests/utils/test_helpers.py:53

🔗 相关文档 ​

基于 GPL-3.0-or-later 许可发布