from pathlib import Path from extract_and_rename import ( check_dependencies, check_external_tools, select_template_file, ) def test_select_template_file_picks_first_by_name(tmp_path): (tmp_path / "b_template.png").write_bytes(b"x") (tmp_path / "a_template.png").write_bytes(b"x") (tmp_path / "note.txt").write_bytes(b"x") # 対象外拡張子 result = select_template_file(tmp_path) assert result == tmp_path / "a_template.png" def test_select_template_file_no_candidates_raises(tmp_path): (tmp_path / "note.txt").write_bytes(b"x") try: select_template_file(tmp_path) assert False, "FileNotFoundErrorが送出されるべき" except FileNotFoundError: pass def test_check_dependencies_detects_missing_module(): result = check_dependencies(("this_module_does_not_exist_xyz",)) assert result == ["this_module_does_not_exist_xyz"] def test_check_dependencies_detects_installed_module(): result = check_dependencies(("os",)) assert result == [] def test_check_external_tools_detects_missing(tmp_path): tesseract = tmp_path / "tools" / "tesseract" / "tesseract.exe" poppler = tmp_path / "tools" / "poppler" / "pdftoppm.exe" result = check_external_tools(tesseract, poppler) assert str(tesseract) in result assert str(poppler) in result def test_check_external_tools_all_present(tmp_path): tesseract = tmp_path / "tesseract.exe" poppler = tmp_path / "pdftoppm.exe" tesseract.write_bytes(b"x") poppler.write_bytes(b"x") result = check_external_tools(tesseract, poppler) assert result == []