gerodp/hermes-productivity-skills / travel/trip-planner
trip-planner
VerifiedPlan a trip step by step: an itinerary plus a running budget that converts every currency into your preferred one, printed as two tables after each change — and a final summary with the budget broken down by category, the average spend per day, and checks for accommodation gaps and missing daily food/misc estimates.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 18.0 KB |
| scripts/render_trip.py | script | 18.0 KB |
| scripts/test_render_trip.py | script | 8.6 KB |
| scripts/test_trip_planner.py | script | 31.4 KB |
| scripts/trip_planner.py | script | 81.9 KB |
scripts/test_trip_planner.py
View on GitHub#!/usr/bin/env python3
"""Offline unit tests for trip_planner.
No network (every rate fetch is stubbed), no shared state (each test gets its
own temp trips folder). All fixtures are invented — "Ciudad Norte", "Hotel
Acme", "Alex" — never real destinations, hotels or amounts.
Run: python3 test_trip_planner.py
"""
import io
import json
import os
import sys
import tempfile
import unittest
from contextlib import redirect_stdout, redirect_stderr
from datetime import date
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import trip_planner as tp # noqa: E402
# --- stub rate payloads (shapes copied from the real APIs, values invented) ---
ECB_XML = """<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01"
xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<Cube><Cube time="2026-08-01">
<Cube currency="USD" rate="1.1000"/>
<Cube currency="GBP" rate="0.8500"/>
<Cube currency="MXN" rate="20.0000"/>
<Cube currency="CHF" rate="0.9500"/>
<Cube currency="SEK" rate="11.0000"/>
</Cube></Cube>
</gesmes:Envelope>"""
ERAPI_JSON = json.dumps({
"result": "success", "base_code": "EUR",
"time_last_update_utc": "Sat, 01 Aug 2026 00:02:31 +0000",
"rates": {"EUR": 1, "USD": 1.1, "COP": 4000.0, "GBP": 0.85},
})
FLOAT_JSON = json.dumps({
"cop": {"code": "COP", "rate": 3900.0},
"usd": {"code": "USD", "rate": 1.12},
"gbp": {"code": "GBP", "rate": 0.86},
"mxn": {"code": "MXN", "rate": 20.5},
"chf": {"code": "CHF", "rate": 0.94},
})
def fake_getter(calls=None, fail=()):
def get(url, timeout=tp.HTTP_TIMEOUT):
if calls is not None:
calls.append(url)
for marker in fail:
if marker in url:
raise tp.TripError(f"stubbed failure for {marker}")
if "ecb.europa.eu" in url:
return ECB_XML
if "er-api" in url:
return ERAPI_JSON
if "floatrates" in url:
return FLOAT_JSON
raise AssertionError(f"unexpected URL in a test: {url}")
return get
def run(argv, getter=None):
"""Run the CLI with the network stubbed; return (rc, stdout, stderr)."""
original = tp.http_get
tp.http_get = getter or fake_getter()
out, err = io.StringIO(), io.StringIO()
try:
with redirect_stdout(out), redirect_stderr(err):
rc = tp.main(argv)
finally:
tp.http_get = original
return rc, out.getvalue(), err.getvalue()
class TempTrips(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.dir = self.tmp.name
self.addCleanup(self.tmp.cleanup)
def cli(self, *argv, getter=None):
rc, out, err = run(["--dir", self.dir, *argv], getter=getter)
return rc, out, err
def ok(self, *argv, getter=None):
rc, out, err = self.cli(*argv, getter=getter)
self.assertEqual(rc, 0, f"command failed: {argv}\n{err}")
return out
def new_trip(self, **kw):
args = ["new", "--name", kw.get("name", "Demo"),
"--destination", kw.get("destination", "Ciudad Norte"),
"--start", kw.get("start", "2026-09-01"),
"--end", kw.get("end", "2026-09-10"),
"--travelers", str(kw.get("travelers", 2)), "--quiet"]
if kw.get("budget"):
args += ["--budget", str(kw["budget"])]
if kw.get("currency"):
args += ["--currency", kw["currency"]]
if kw.get("lang"):
args += ["--lang", kw["lang"]]
return self.ok(*args)
def bundle(self):
return json.loads(self.ok("show", "--json"))
# --------------------------------------------------------------------------- #
class TestDates(unittest.TestCase):
ref = date(2026, 8, 13)
def test_parses_every_supported_shape(self):
cases = [
("2026-08-13", date(2026, 8, 13)),
("13/08", date(2026, 8, 13)),
("13/08/2026", date(2026, 8, 13)),
("13/8/26", date(2026, 8, 13)),
("13 ago", date(2026, 8, 13)),
("13 AGO", date(2026, 8, 13)),
("13 de agosto", date(2026, 8, 13)),
("13 aug", date(2026, 8, 13)),
("aug 13", date(2026, 8, 13)),
("sep 1", date(2026, 9, 1)),
("1 sept 2026", date(2026, 9, 1)),
("13 dic", date(2026, 12, 13)),
]
for text, expected in cases:
with self.subTest(text=text):
self.assertEqual(tp.parse_date(text, self.ref), expected)
def test_year_rolls_forward_for_a_date_long_past_the_reference(self):
# Planning in December for a January trip → next year, not last year.
self.assertEqual(tp.parse_date("5 ene", date(2026, 12, 20)), date(2027, 1, 5))
# …but a date just behind the reference stays in the same year.
self.assertEqual(tp.parse_date("1 ago", self.ref), date(2026, 8, 1))
def test_ranges(self):
cases = [
("13-16 ago", (date(2026, 8, 13), date(2026, 8, 16))),
("13 - 16 ago", (date(2026, 8, 13), date(2026, 8, 16))),
("13–31 ago", (date(2026, 8, 13), date(2026, 8, 31))),
("21-27 ago 2026", (date(2026, 8, 21), date(2026, 8, 27))),
("2026-08-13..2026-08-16", (date(2026, 8, 13), date(2026, 8, 16))),
("31 ago - 2 sep", (date(2026, 8, 31), date(2026, 9, 2))),
("13 ago", (date(2026, 8, 13), date(2026, 8, 13))),
]
for text, expected in cases:
with self.subTest(text=text):
self.assertEqual(tp.parse_date_range(text, self.ref), expected)
def test_rejects_nonsense(self):
for bad in ("", "yesterday-ish", "32 ago", "13 foo"):
with self.subTest(bad=bad), self.assertRaises(tp.TripError):
tp.parse_date(bad, self.ref)
def test_formatting(self):
d1, d2 = date(2026, 8, 13), date(2026, 8, 31)
self.assertEqual(tp.fmt_span(d1, d1, "es"), "13 ago")
self.assertEqual(tp.fmt_span(d1, d2, "es"), "13-31 ago")
self.assertEqual(tp.fmt_span(d1, date(2026, 9, 2), "es"), "13 ago - 2 sep")
self.assertEqual(tp.fmt_span(d1, d2, "en"), "13–31 Aug")
class TestMoney(unittest.TestCase):
def test_parse_amount(self):
cases = [
("630", None, 630, None),
("630 USD", None, 630, "USD"),
("$630", None, 630, "USD"),
("2.480,00 €", None, 2480.00, "EUR"),
("2.450.000 COP", None, 2450000, "COP"),
("9.480.320,50 COP", None, 9480320.50, "COP"),
("1,500", None, 1500, None),
("630.50", None, 630.50, None),
("431,25", None, 431.25, None),
("1.5", None, 1.5, None),
("100", "EUR", 100, "EUR"),
]
for text, default, value, currency in cases:
with self.subTest(text=text):
v, c = tp.parse_amount(text, default)
self.assertAlmostEqual(float(v), value, places=2)
self.assertEqual(c, currency)
def test_rejects_garbage(self):
for bad in ("", "many euros", "12,,34x"):
with self.subTest(bad=bad), self.assertRaises(tp.TripError):
tp.parse_amount(bad)
def test_formatting_follows_language(self):
self.assertEqual(tp.fmt_money(2480, "EUR", "es"), "2.480,00 €")
self.assertEqual(tp.fmt_money(2480, "EUR", "en"), "2,480.00 €")
self.assertEqual(tp.fmt_money(2450000, "COP", "es"), "2.450.000,00 COP")
self.assertEqual(tp.fmt_rate(0.87, "USD", "EUR", "es"), "1 USD = 0,87 EUR")
def test_tiny_rates_are_stated_the_readable_way_round(self):
# 1 COP = 0,0003 EUR tells the reader nothing; invert it instead.
self.assertEqual(tp.fmt_rate(0.00025, "COP", "EUR", "es"),
"1 EUR = 4.000 COP")
class TestRates(TempTrips):
def test_ecb_is_enough_for_usd_and_is_cached(self):
calls = []
ctx = tp.load_rates(self.dir, need="USD", getter=fake_getter(calls))
self.assertEqual(ctx["sources"], ["ecb"])
self.assertEqual(len(calls), 1)
self.assertTrue(os.path.exists(os.path.join(self.dir, tp.RATES_FILE)))
again = tp.load_rates(self.dir, need="USD", getter=fake_getter(calls))
self.assertEqual(len(calls), 1, "the cache must avoid a second fetch")
self.assertFalse(again["stale"])
def test_falls_through_to_er_api_for_a_currency_ecb_lacks(self):
calls = []
ctx = tp.load_rates(self.dir, need="COP", getter=fake_getter(calls))
self.assertEqual(ctx["sources"], ["ecb", "er-api"])
self.assertEqual(ctx["rates"]["COP"], 4000.0)
self.assertEqual(ctx["rates"]["USD"], 1.1, "ECB wins on overlap")
def test_falls_through_to_floatrates_when_er_api_is_down(self):
ctx = tp.load_rates(self.dir, need="COP",
getter=fake_getter(fail=("er-api",)))
self.assertEqual(ctx["sources"], ["ecb", "floatrates"])
self.assertEqual(ctx["rates"]["COP"], 3900.0)
def test_stale_cache_is_served_when_every_source_is_down(self):
tp.load_rates(self.dir, need="COP", getter=fake_getter())
ctx = tp.load_rates(self.dir, need="COP", refresh=True,
getter=fake_getter(fail=("ecb", "er-api", "floatrates")))
self.assertTrue(ctx["stale"])
self.assertEqual(ctx["rates"]["COP"], 4000.0)
def test_offline_with_no_cache_explains_how_to_proceed(self):
with self.assertRaises(tp.TripError) as cm:
tp.load_rates(self.dir, need="COP",
getter=fake_getter(fail=("ecb", "er-api", "floatrates")))
msg = str(cm.exception)
self.assertIn("--rate", msg)
self.assertIn("google.com/search", msg)
def test_the_cache_records_which_transport_fetched_it(self):
# `check`/`rates` must be able to say whether urllib or the curl
# fallback did the fetch — that is the only way to know if the
# broken-ssl workaround is actually in play on a given machine.
tp.LAST_TRANSPORT = "urllib"
ctx = tp.load_rates(self.dir, need="USD", getter=fake_getter())
self.assertEqual(ctx["transport"], "urllib")
def test_both_sides_of_the_pair_are_guaranteed(self):
# A trip based in an exotic currency paying a USD invoice: USD alone is
# in ECB, but COP is not — the table must still carry both.
ctx = tp.load_rates(self.dir, need=["USD", "COP"], getter=fake_getter())
self.assertIn("COP", ctx["rates"])
self.assertIn("USD", ctx["rates"])
def test_cross_rate(self):
rates = {"EUR": 1.0, "USD": 1.1, "COP": 4000.0}
self.assertAlmostEqual(tp.cross_rate(rates, "USD", "EUR"), 1 / 1.1)
self.assertAlmostEqual(tp.cross_rate(rates, "EUR", "COP"), 4000.0)
with self.assertRaises(tp.TripError):
tp.cross_rate(rates, "JPY", "EUR")
class TestTripLifecycle(TempTrips):
def test_new_requires_the_frame_and_says_exactly_what_is_missing(self):
rc, out, err = self.cli("new", "--name", "Demo")
self.assertEqual(rc, 1)
for flag in ("--destination", "--start", "--end", "--travelers"):
self.assertIn(flag, err)
def test_new_then_add_prints_both_tables(self):
self.new_trip(budget=3000)
out = self.ok("add", "--type", "flight", "--title", "Vuelo ida",
"--place", "Madrid → Ciudad Norte", "--one-way",
"--date", "1 sep", "--amount", "630 USD", "--qty", "2",
"--link", "https://example.com/booking")
self.assertIn("ITINERARIO", out)
self.assertIn("PRESUPUESTO", out)
self.assertIn("Vuelo ida", out)
self.assertIn("1 sep", out)
self.assertIn("https://example.com/booking", out)
b = self.bundle()
item = b["items"][0]
self.assertEqual(item["total"], 1260.0) # 630 × 2
self.assertAlmostEqual(item["rate"], 1 / 1.1, places=6)
self.assertAlmostEqual(item["converted"], 1145.45, places=2)
self.assertEqual(item["rate_source"], "ecb")
self.assertEqual(b["totals"]["spent"], 1145.45)
self.assertEqual(b["totals"]["remaining"], 3000 - 1145.45)
def test_a_trip_based_in_an_exotic_currency_converts_both_ways(self):
self.new_trip(currency="COP", budget=8000000)
self.ok("add", "--type", "flight", "--title", "Vuelo", "--date", "2 sep",
"--from", "Madrid", "--to", "Ciudad Norte", "--one-way",
"--amount", "110 USD")
item = self.bundle()["items"][0]
self.assertEqual(item["currency"], "USD")
# 110 USD → EUR (÷1.1) → COP (×4000)
self.assertAlmostEqual(item["converted"], 400000.0, places=2)
def test_per_person_multiplies_by_travelers(self):
self.new_trip(travelers=3)
self.ok("add", "--type", "activity", "--title", "Excursión",
"--date", "2 sep", "--amount", "50", "--per-person")
self.assertEqual(self.bundle()["items"][0]["converted"], 150.0)
def test_manual_rate_wins_and_needs_no_network(self):
self.new_trip()
def no_network(url, timeout=None):
raise AssertionError("must not hit the network when --rate is given")
self.ok("add", "--type", "flight", "--title", "Vuelo interno",
"--from", "Ciudad Norte", "--to", "Puerto Sur", "--one-way",
"--date", "2 sep", "--amount", "630 USD", "--rate", "0.87",
getter=no_network)
item = self.bundle()["items"][0]
self.assertEqual(item["converted"], 548.10)
self.assertEqual(item["rate_source"], "manual")
def test_rate_is_frozen_and_survives_a_rate_change(self):
self.new_trip()
self.ok("add", "--type", "meal", "--title", "Cena", "--date", "2 sep",
"--amount", "110 USD")
first = self.bundle()["items"][0]["converted"]
# A later, different rate table must not move an already-added item.
moved = json.dumps({"result": "success", "rates": {"EUR": 1, "USD": 2.0}})
self.ok("show", "--json", getter=lambda url, timeout=None: moved)
self.assertEqual(self.bundle()["items"][0]["converted"], first)
def test_missing_title_or_date_is_explained(self):
self.new_trip()
rc, out, err = self.cli("add", "--type", "meal", "--date", "2 sep")
self.assertEqual(rc, 1)
self.assertIn("--title", err)
rc, out, err = self.cli("add", "--type", "meal", "--title", "Cena")
self.assertEqual(rc, 1)
self.assertIn("--date", err)
def test_duplicate_guard(self):
self.new_trip()
args = ("add", "--type", "meal", "--title", "Cena", "--date", "2 sep",
"--amount", "40")
self.ok(*args)
rc, out, err = self.cli(*args)
self.assertEqual(rc, 1)
self.assertIn("duplicate", err)
self.ok(*args, "--force")
self.assertEqual(len(self.bundle()["items"]), 2)
def test_edit_rm_and_undo(self):
self.new_trip()
self.ok("add", "--type", "stay", "--title", "Hotel Acme",
"--date", "1-5 sep", "--amount", "800")
self.ok("edit", "1", "--amount", "900", "--status", "pending")
item = self.bundle()["items"][0]
self.assertEqual(item["converted"], 900.0)
self.assertEqual(item["status"], "pending")
self.ok("rm", "1")
self.assertEqual(self.bundle()["items"], [])
self.ok("undo")
self.assertEqual(len(self.bundle()["items"]), 1)
def test_currency_rebasing_recomputes_from_the_originals(self):
self.new_trip(currency="EUR")
self.ok("add", "--type", "meal", "--title", "Cena", "--date", "2 sep",
"--amount", "110 USD")
self.ok("set", "--currency", "USD", "--quiet")
item = self.bundle()["items"][0]
self.assertEqual(item["currency"], "USD")
self.assertEqual(item["converted"], 110.0)
self.assertEqual(item["rate_source"], "same-currency")
def test_list_and_use_switch_the_active_trip(self):
self.new_trip(name="Demo")
self.new_trip(name="Otro", start="2026-10-01", end="2026-10-05")
listing = json.loads(self.ok("list", "--json"))
self.assertEqual(listing["active"], "otro-2026-10")
self.assertEqual(len(listing["trips"]), 2)
self.ok("use", "demo-2026-09")
self.assertEqual(self.bundle()["trip"]["slug"], "demo-2026-09")
def test_language_is_per_trip_and_overridable(self):
self.new_trip(lang="en", budget=1000)
out = self.ok("show")
self.assertIn("ITINERARY", out)
self.assertIn("BUDGET", out)
self.assertIn("ITINERARIO", self.ok("show", "--lang", "es"))
class TestWarnings(TempTrips):
def test_gap_overlap_outside_and_budget_warnings(self):
self.new_trip(budget=1000)
self.ok("add", "--type", "stay", "--title", "Hotel Acme",
"--date", "1-3 sep", "--amount", "300")
warnings = " | ".join(self.bundle()["warnings"])
self.assertIn("Sin alojamiento", warnings)
self.ok("add", "--type", "stay", "--title", "Hostal Norte",
"--start", "2 sep", "--end", "4 sep", "--amount", "100")
warnings = " | ".join(self.bundle()["warnings"])
self.assertIn("solapados", warnings)
self.ok("add", "--type", "activity", "--title", "Excursión previa",
"--date", "20 ago", "--amount", "50", "--status", "pending")
warnings = " | ".join(self.bundle()["warnings"])
self.assertIn("Fuera de las fechas", warnings)
self.assertIn("Pendiente de confirmar", warnings)
self.ok("add", "--type", "other", "--title", "Extras", "--date", "3 sep",
"--amount", "900")
warnings = " | ".join(self.bundle()["warnings"])
self.assertIn("Presupuesto superado", warnings)
def test_item_without_amount_is_flagged(self):
self.new_trip()
self.ok("add", "--type", "stay", "--title", "Por decidir",
"--date", "1-10 sep")
b = self.bundle()
self.assertIsNone(b["items"][0]["converted"])
self.assertIn("Sin importe", " | ".join(b["warnings"]))
self.assertEqual(b["totals"]["spent"], 0)
class TestFlights(TempTrips):
def test_a_flight_without_a_route_is_refused_with_what_to_ask(self):
self.new_trip()
rc, out, err = self.cli("add", "--type", "flight", "--title", "Vuelo",
"--date", "1 sep", "--amount", "630 USD")
self.assertEqual(rc, 1)
self.assertIn("route", err)
self.assertIn("--from", err)
self.assertIn("--one-way", err)
def test_a_flight_without_a_direction_is_refused(self):
self.new_trip()
rc, out, err = self.cli("add", "--type", "flight", "--title", "Vuelo",
"--from", "Madrid", "--to", "Ciudad Norte",
"--date", "1 sep", "--amount", "100")
self.assertEqual(rc, 1)
self.assertIn("one-way or a return", err)
def test_route_can_come_from_place_and_direction_shows_in_the_tables(self):
self.new_trip()
out = self.ok("add", "--type", "flight", "--title", "Vuelo",
"--place", "Madrid → Ciudad Norte", "--roundtrip",
"--start", "1 sep", "--end", "10 sep", "--amount", "100")
# itinerary: one row per leg; budget: a single "ida y vuelta" line
self.assertIn("Madrid → Ciudad Norte", out)
self.assertIn("Ciudad Norte → Madrid", out)
self.assertIn("ida y vuelta", out)
item = self.bundle()["items"][0]
self.assertEqual(item["origin"], "Madrid")
self.assertEqual(item["destination"], "Ciudad Norte")
self.assertTrue(item["roundtrip"])
self.assertEqual(item["place"], "Madrid ⇄ Ciudad Norte")
def test_a_return_flight_with_no_return_date_warns(self):
self.new_trip()
self.ok("add", "--type", "flight", "--title", "Vuelo", "--from", "A",
"--to", "B", "--roundtrip", "--date", "1 sep", "--amount", "100")
self.assertIn("sin fecha de regreso", " | ".join(self.bundle()["warnings"]))
def test_a_return_flight_is_two_itinerary_rows_but_one_budget_line(self):
self.new_trip()
self.ok("add", "--type", "flight", "--title", "Vuelo Aerolinea",
"--from", "Madrid", "--to", "Ciudad Norte", "--roundtrip",
"--start", "1 sep", "--end", "10 sep", "--amount", "100",
"--quiet")
b = self.bundle()
self.assertEqual(len(b["items"]), 1) # one purchase
self.assertEqual(len(b["itinerary"]), 2) # two legs
out_leg, back_leg = b["itinerary"]
self.assertEqual(out_leg["leg"], "outbound")
self.assertEqual((out_leg["start"], out_leg["end"]),
("2026-09-01", "2026-09-01"))
self.assertEqual(out_leg["display"]["place"], "Madrid → Ciudad Norte")
self.assertIn("(ida)", out_leg["display"]["activity"])
self.assertEqual(back_leg["leg"], "return")
self.assertEqual((back_leg["start"], back_leg["end"]),
("2026-09-10", "2026-09-10"))
self.assertEqual(back_leg["display"]["place"], "Ciudad Norte → Madrid")
self.assertIn("(vuelta)", back_leg["display"]["activity"])
# the leg rows carry no direction note — the row *is* the direction
self.assertNotIn("ida y vuelta", out_leg["display"]["notes"])
self.assertIn("ida y vuelta", b["items"][0]["display"]["notes"])
def test_the_return_leg_sorts_by_its_own_date(self):
self.new_trip()
self.ok("add", "--type", "flight", "--title", "Vuelo", "--from", "Madrid",
"--to", "Ciudad Norte", "--roundtrip", "--start", "1 sep",
"--end", "10 sep", "--amount", "100", "--quiet")
self.ok("add", "--type", "activity", "--title", "Excursión",
"--date", "3 sep", "--amount", "50", "--quiet")
rows = self.bundle()["itinerary"]
self.assertEqual([r["start"] for r in rows],
["2026-09-01", "2026-09-03", "2026-09-10"])
def test_a_one_way_flight_stays_a_single_row(self):
self.new_trip()
self.ok("add", "--type", "flight", "--title", "Vuelo", "--from", "Madrid",
"--to", "Ciudad Norte", "--one-way", "--date", "1 sep",
"--amount", "100", "--quiet")
rows = self.bundle()["itinerary"]
self.assertEqual(len(rows), 1)
self.assertNotIn("leg", rows[0])
self.assertEqual(rows[0]["display"]["place"], "Madrid → Ciudad Norte")
def test_a_return_flight_with_no_return_date_stays_a_single_row(self):
self.new_trip()
self.ok("add", "--type", "flight", "--title", "Vuelo", "--from", "Madrid",
"--to", "Ciudad Norte", "--roundtrip", "--date", "1 sep",
"--amount", "100", "--quiet")
rows = self.bundle()["itinerary"]
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["display"]["place"], "Madrid ⇄ Ciudad Norte")
def test_non_flight_items_need_no_route(self):
self.new_trip()
self.ok("add", "--type", "meal", "--title", "Cena", "--date", "1 sep",
"--amount", "30")
class TestSummary(TempTrips):
def stocked_trip(self):
self.new_trip(budget=6000, travelers=2)
self.ok("add", "--type", "flight", "--title", "Vuelo", "--from", "Madrid",
"--to", "Ciudad Norte", "--roundtrip", "--start", "1 sep",
"--end", "10 sep", "--amount", "500", "--per-person", "--quiet")
self.ok("add", "--type", "stay", "--title", "Hotel Acme",
"--date", "1-10 sep", "--amount", "1200", "--quiet")
self.ok("add", "--type", "activity", "--title", "Excursión",
"--date", "3 sep", "--amount", "180", "--quiet")
def test_every_mutating_command_invites_the_user_to_say_when_done(self):
self.new_trip()
for out in (self.ok("add", "--type", "meal", "--title", "Cena",
"--date", "1 sep", "--amount", "30"),
self.ok("edit", "1", "--amount", "35"),
self.ok("rm", "1")):
self.assertIn("Cuando termines de añadir gastos", out)
def test_per_day_multiplies_by_the_items_days(self):
self.new_trip(travelers=2)
self.ok("add", "--type", "meal", "--title", "Comidas", "--start", "1 sep",
"--end", "10 sep", "--amount", "30", "--per-day", "--per-person",
"--quiet")
# 30 € × 10 days × 2 travelers
self.assertEqual(self.bundle()["items"][0]["converted"], 600.0)
def test_breakdown_totals_by_category(self):
self.stocked_trip()
rows = {r["key"]: r for r in self.bundle()["totals"]["breakdown"]}
self.assertEqual(rows["flights"]["amount"], 1000.0) # 500 × 2 people
self.assertEqual(rows["lodging"]["amount"], 1200.0)
self.assertEqual(rows["activities"]["amount"], 180.0)
self.assertNotIn("food", rows, "empty categories are not listed")
self.assertAlmostEqual(sum(r["amount"] for r in rows.values()), 2380.0)
self.assertAlmostEqual(rows["lodging"]["pct"], 50.4, places=1)
self.assertEqual(rows["lodging"]["per_day"], 120.0) # 10 days
self.assertEqual(rows["lodging"]["per_person"], 600.0)
def test_summary_reports_average_per_day_and_the_four_categories(self):
self.stocked_trip()
out = self.ok("summary")
self.assertIn("DESGLOSE DEL PRESUPUESTO", out)
for label in ("Vuelos", "Alojamiento", "Actividades"):
self.assertIn(label, out)
self.assertIn("Gasto medio por día", out)
self.assertIn("Media por persona y día", out)
self.assertIn("238,00 €", out) # 2380 / 10 days
def test_checks_ask_for_lodging_gaps_food_and_misc(self):
self.stocked_trip()
checks = self.bundle()["checks"]
self.assertFalse(checks["has_food"])
self.assertFalse(checks["has_misc"])
self.assertTrue(checks["lodging_ok"]) # 1-10 sep covers all 9 nights
self.assertEqual({q["key"] for q in checks["questions"]}, {"food", "misc"})
out = self.ok("summary")
self.assertIn("PREGUNTAR AL USUARIO", out)
self.assertIn("--per-day --per-person", out)
def test_lodging_gap_question_points_at_the_gap_not_the_whole_trip(self):
self.new_trip()
self.ok("add", "--type", "stay", "--title", "Hotel Acme",
"--date", "1-7 sep", "--amount", "700", "--quiet")
checks = self.bundle()["checks"]
self.assertEqual(checks["nights_missing"], 3)
q = [q for q in checks["questions"] if q["key"] == "lodging"][0]
self.assertIn("--start 2026-09-07 --end 2026-09-10", q["command"])
def test_a_complete_plan_reports_ready_with_no_questions(self):
self.stocked_trip()
self.ok("add", "--type", "meal", "--title", "Comidas", "--start", "1 sep",
"--end", "10 sep", "--amount", "30", "--per-day", "--quiet")
self.ok("add", "--type", "other", "--title", "Varios", "--start", "1 sep",
"--end", "10 sep", "--amount", "20", "--per-day", "--quiet")
checks = self.bundle()["checks"]
self.assertTrue(checks["ready"])
self.assertEqual(checks["questions"], [])
self.assertIn("El plan está completo", self.ok("summary"))
def test_summary_exports(self):
self.stocked_trip()
md = self.ok("summary", "--markdown")
self.assertIn("DESGLOSE DEL PRESUPUESTO", md)
self.assertIn("| **TOTAL** |", md)
path = os.path.join(self.dir, "s.html")
self.ok("summary", "--html", "-o", path)
with open(path, encoding="utf-8") as fh:
page = fh.read()
self.assertIn("DESGLOSE DEL PRESUPUESTO", page)
self.assertIn("COMPROBACIONES", page)
class TestSafety(TempTrips):
def test_trip_path_is_contained(self):
base = tp.resolve_dir(self.dir)
for bad in ("../escape", "/etc/passwd", "..", "sub/dir", "Bad Slug"):
with self.subTest(bad=bad), self.assertRaises(tp.TripError):
tp.trip_path(base, bad)
def test_control_characters_are_stripped_from_text_output(self):
self.new_trip()
self.ok("add", "--type", "meal", "--title", "Cena\x1b[31mroja",
"--date", "2 sep", "--amount", "20")
out = self.ok("show")
self.assertNotIn("\x1b", out)
self.assertIn("Cena[31mroja", out)
def test_links_must_be_http(self):
self.new_trip()
rc, out, err = self.cli("add", "--type", "meal", "--title", "Cena",
"--date", "2 sep", "--link", "javascript:alert(1)")
self.assertEqual(rc, 1)
self.assertIn("http", err)
def test_out_path_refuses_to_clobber_without_overwrite(self):
target = os.path.join(self.dir, "out.html")
with open(target, "w", encoding="utf-8") as fh:
fh.write("keep me")
with self.assertRaises(tp.TripError):
tp.safe_out_path(target)
self.assertEqual(tp.safe_out_path(target, overwrite=True),
os.path.join(os.path.realpath(self.dir), "out.html"))
def test_notes_come_from_a_file_without_shell_interpolation(self):
self.new_trip()
note = os.path.join(self.dir, "note.txt")
with open(note, "w", encoding="utf-8") as fh:
fh.write("$(whoami) `id` — plain text")
self.ok("add", "--type", "other", "--title", "Nota", "--date", "2 sep",
"--notes-file", note)
self.assertIn("$(whoami)", self.bundle()["items"][0]["notes"])
class TestExportsAndHelpers(TempTrips):
def test_show_writes_html_and_ics_in_one_command(self):
self.new_trip(budget=2000)
self.ok("add", "--type", "stay", "--title", "Hotel Acme",
"--date", "1-5 sep", "--amount", "400")
html_path = os.path.join(self.dir, "trip.html")
ics_path = os.path.join(self.dir, "trip.ics")
self.ok("show", "--html", "-o", html_path)
self.ok("show", "--ics", "-o", ics_path)
with open(html_path, encoding="utf-8") as fh:
page = fh.read()
self.assertIn("<!doctype html>", page)
self.assertIn("Hotel Acme", page)
with open(ics_path, encoding="utf-8") as fh:
cal = fh.read()
self.assertIn("BEGIN:VEVENT", cal)
self.assertIn("DTSTART;VALUE=DATE:20260901", cal)
def test_markdown_output(self):
self.new_trip()
self.ok("add", "--type", "meal", "--title", "Cena", "--date", "2 sep",
"--amount", "30")
out = self.ok("show", "--markdown")
self.assertIn("| Fecha | Ciudad/Lugar |", out)
self.assertIn("Cena", out)
def test_convert_command(self):
self.new_trip()
payload = json.loads(self.ok("convert", "--amount", "630 USD", "--json"))
self.assertEqual(payload["from"], "USD")
self.assertEqual(payload["to"], "EUR")
self.assertAlmostEqual(payload["converted"], 572.73, places=2)
def test_maps_prints_links_and_a_disclaimer_without_network(self):
def no_network(url, timeout=None):
raise AssertionError("maps must never hit the network")
out = self.ok("maps", "--from", "Ciudad Norte", "--to", "Puerto Sur",
getter=no_network)
self.assertIn("google.com/maps/dir", out)
self.assertIn("estimate", out.lower())
def test_check_runs_offline(self):
out = self.ok("check", "--offline")
self.assertIn("trips folder", out)
if __name__ == "__main__":
unittest.main(verbosity=2)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |