several updates to functionality

This commit is contained in:
2026-02-02 13:16:18 +01:00
parent 1f3ba037d6
commit 3ac987ac34
19 changed files with 1808 additions and 135 deletions

126
tests/test_cli_options.py Normal file
View File

@@ -0,0 +1,126 @@
import json
import os
import tempfile
import unittest
import generator
class CliOptionsTest(unittest.TestCase):
def test_output_dir_and_duration_minutes(self) -> None:
config_date = "2026-02-06"
config_time = "15:00"
story_data = {
"meta": {"name": "CLI Options Story", "log_prefix": "LOG"},
"events": [
{"id": "log_01", "title": "Kickoff", "story": "Hello"},
],
}
with tempfile.TemporaryDirectory() as tmpdir:
previous_cwd = os.getcwd()
os.chdir(tmpdir)
try:
with open("config.toml", "w", encoding="utf-8") as f:
f.write(
"\n".join(
[
f'start_date = "{config_date}"',
f'start_time = "{config_time}"',
"blocked_weeks = []",
"blocked_dates = []",
"skip_day_after_ascension = false",
]
)
+ "\n"
)
story_path = os.path.join(tmpdir, "story.json")
with open(story_path, "w", encoding="utf-8") as f:
json.dump(story_data, f, ensure_ascii=False, indent=2)
output_dir = "custom_output"
generator.generate_single_file(
story_path,
preview_html=True,
output_dir=output_dir,
duration_minutes=90,
)
slug = generator.sanitize_filename(story_data["meta"]["name"])
preview_path = os.path.join(output_dir, f"PREVIEW_{slug}.html")
ics_path = os.path.join(output_dir, f"FULL_SERIES_{slug}.ics")
self.assertTrue(os.path.exists(preview_path))
self.assertTrue(os.path.exists(ics_path))
with open(preview_path, "r", encoding="utf-8") as f:
preview_html = f.read()
self.assertIn("15:00-16:30", preview_html)
finally:
os.chdir(previous_cwd)
def test_config_path_override_and_timezone(self) -> None:
story_data = {
"meta": {"name": "CLI Config Story", "log_prefix": "LOG"},
"events": [
{"id": "log_01", "title": "Kickoff", "story": "Hello"},
],
}
with tempfile.TemporaryDirectory() as tmpdir:
previous_cwd = os.getcwd()
os.chdir(tmpdir)
try:
with open("config.toml", "w", encoding="utf-8") as f:
f.write(
"\n".join(
[
'start_date = "2026-02-06"',
'start_time = "15:00"',
"blocked_weeks = []",
"blocked_dates = []",
"skip_day_after_ascension = false",
]
)
+ "\n"
)
override_path = os.path.join(tmpdir, "override.toml")
with open(override_path, "w", encoding="utf-8") as f:
f.write(
"\n".join(
[
'start_date = "2026-02-06"',
'start_time = "14:00"',
"blocked_weeks = []",
"blocked_dates = []",
"skip_day_after_ascension = false",
]
)
+ "\n"
)
story_path = os.path.join(tmpdir, "story.json")
with open(story_path, "w", encoding="utf-8") as f:
json.dump(story_data, f, ensure_ascii=False, indent=2)
output_dir = "custom_output"
generator.generate_single_file(
story_path,
preview_html=True,
output_dir=output_dir,
config_path=override_path,
timezone_name="UTC",
)
slug = generator.sanitize_filename(story_data["meta"]["name"])
preview_path = os.path.join(output_dir, f"PREVIEW_{slug}.html")
self.assertTrue(os.path.exists(preview_path))
with open(preview_path, "r", encoding="utf-8") as f:
preview_html = f.read()
self.assertIn("14:00-15:00", preview_html)
self.assertIn("(UTC)", preview_html)
finally:
os.chdir(previous_cwd)