test_init_project_pruning.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import pytest
  4. def test_init_skips_dead_templates_and_empty_libraries_for_single_protagonist(tmp_path, monkeypatch):
  5. import init_project as init_project_module
  6. monkeypatch.setattr(init_project_module, "is_git_available", lambda: False)
  7. project_root = tmp_path / "book"
  8. init_project_module.init_project(
  9. str(project_root),
  10. title="测试书",
  11. genre="仙侠",
  12. protagonist_name="陆鸣",
  13. protagonist_structure="单主角+辅助视角",
  14. heroine_config="无女主",
  15. target_chapters=50,
  16. )
  17. assert (project_root / "设定集" / "主角卡.md").is_file()
  18. assert not (project_root / "设定集" / "主角组.md").exists()
  19. assert not (project_root / "设定集" / "女主卡.md").exists()
  20. assert not (project_root / "设定集" / "金手指设计.md").exists()
  21. assert not (project_root / "设定集" / "复合题材-融合逻辑.md").exists()
  22. assert not (project_root / "大纲" / "爽点规划.md").exists()
  23. assert not (project_root / "设定集" / "角色库").exists()
  24. assert not (project_root / "设定集" / "物品库").exists()
  25. assert not (project_root / "设定集" / "其他设定").exists()
  26. def test_init_master_outline_does_not_prefill_future_volume_rows(tmp_path, monkeypatch):
  27. import init_project as init_project_module
  28. monkeypatch.setattr(init_project_module, "is_git_available", lambda: False)
  29. project_root = tmp_path / "book"
  30. init_project_module.init_project(
  31. str(project_root),
  32. title="测试书",
  33. genre="仙侠",
  34. protagonist_name="陆鸣",
  35. target_chapters=600,
  36. )
  37. summary = (project_root / "大纲" / "总纲.md").read_text(encoding="utf-8")
  38. assert "| 1 |" in summary
  39. assert "| 2 |" not in summary
  40. assert "| 20 |" not in summary
  41. def test_init_generates_conditional_protagonist_group_and_heroine(tmp_path, monkeypatch):
  42. import init_project as init_project_module
  43. monkeypatch.setattr(init_project_module, "is_git_available", lambda: False)
  44. project_root = tmp_path / "book"
  45. init_project_module.init_project(
  46. str(project_root),
  47. title="测试书",
  48. genre="仙侠",
  49. protagonist_name="陆鸣",
  50. protagonist_structure="双主角",
  51. heroine_config="单女主",
  52. heroine_names="苏云",
  53. target_chapters=50,
  54. )
  55. assert (project_root / "设定集" / "主角组.md").is_file()
  56. assert (project_root / "设定集" / "女主卡.md").is_file()
  57. def test_init_rejects_english_profile_key_before_writing_state(tmp_path, monkeypatch):
  58. import init_project as init_project_module
  59. monkeypatch.setattr(init_project_module, "is_git_available", lambda: False)
  60. project_root = tmp_path / "book"
  61. with pytest.raises(SystemExit) as exc:
  62. init_project_module.init_project(
  63. str(project_root),
  64. title="测试书",
  65. genre="rules-mystery",
  66. protagonist_name="陆鸣",
  67. target_chapters=50,
  68. )
  69. message = str(exc.value)
  70. assert "rules-mystery" in message
  71. assert "规则怪谈" in message
  72. assert not (project_root / ".webnovel" / "state.json").exists()