[Test] Add unit coverage for content-based file type detection

已关闭 适合新手
#15 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@srivarshni7 已经在做这个了。

开始于 2026年11月2日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, security
领域
testing

调研方向

从 utilities/file_types.py 中的四个辅助函数开始:sniff_magic、detect_type_key、type_label 和 guess_kind。参考 tests/test_file_type_icons.py 了解现有的测试风格,然后添加一个不依赖 Qt 的新测试模块。完成的标准是:PNG 或 PDF 的魔数字节优先于冲突的扩展名,.tar.gz 能被正确解析,未知二进制文件回退到安全类别,并且测试在没有 QApplication 的情况下通过。

由索引模型根据 Issue 内容生成。

描述

good first issue test

Summary

utilities/file_types.py contains content sniffing and compound-extension handling, but the test suite currently has no focused tests for these helpers. Regressions could affect file labels and preview selection without being detected.

Proposed solution

Add a small, Qt-independent test module covering sniff_magic, detect_type_key, type_label, and guess_kind. Use representative byte samples and filenames to verify magic bytes take precedence over extensions, .tar.gz is handled correctly, text and unknown data are classified safely, and case-insensitive extensions work.

Acceptance criteria

  • Tests cover at least PNG/PDF or another representative magic-byte pair.
  • A content type overrides a conflicting filename extension.
  • Compound extensions such as .tar.gz are covered.
  • Unknown binary data falls back to the expected safe category.
  • Tests run without creating a Qt application.

Security considerations

Tests must use synthetic data only and must not weaken or bypass encryption behavior.

Additional context

Relevant file: utilities/file_types.py; existing UI icon tests are in tests/test_file_type_icons.py.

主要语言
Python
星标
1
派生
5
平均合并
4 小时 22 分钟
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ANCORATE/EncryptHome 的其他 Issue

查看 ANCORATE/EncryptHome 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。