import pytest from pathlib import Path from config_loader import ConfigError, load_config VALID_CONTENT = """\ スクリプトフォルダ=スクリプト テンプレートフォルダ=テンプレート スキャンフォルダ=スキャン アウトプットフォルダ=アウトプット 成功フォルダ=成功 失敗フォルダ=失敗 ログフォルダ=ログ margin=0.10 DPI=300 ファイル安定待ち秒=1 ファイル安定待ちリトライ回数=5 """ def test_load_config_missing_file_raises(tmp_path): missing_path = tmp_path / "config.txt" with pytest.raises(ConfigError): load_config(missing_path) def test_load_config_parses_all_keys(tmp_path): config_path = tmp_path / "config.txt" config_path.write_text(VALID_CONTENT, encoding="utf-8") config = load_config(config_path) assert config["スクリプトフォルダ"] == "スクリプト" assert config["テンプレートフォルダ"] == "テンプレート" assert config["margin"] == "0.10" assert config["ファイル安定待ちリトライ回数"] == "5" def test_load_config_missing_required_key_raises(tmp_path): config_path = tmp_path / "config.txt" config_path.write_text("スクリプトフォルダ=スクリプト\n", encoding="utf-8") with pytest.raises(ConfigError): load_config(config_path) def test_load_config_ignores_blank_lines_and_comments(tmp_path): config_path = tmp_path / "config.txt" content = "# comment\n\n" + VALID_CONTENT config_path.write_text(content, encoding="utf-8") config = load_config(config_path) assert config["スクリプトフォルダ"] == "スクリプト"