"""Held-out tests for shipping.py: do NOT give this file to the AI. They pin behaviour the
visible tests do not cover. Run it yourself after the refactor:
python3 -m unittest test_shipping_extra.py"""
import unittest

from shipping import shipping_cost


def order(country="US", weight=1.0, subtotal=1000, express=False, **extra):
    o = {"country": country, "weight_kg": weight, "subtotal_cents": subtotal, "express": express}
    o.update(extra)
    return o


class ShippingCostExtraTest(unittest.TestCase):
    def test_fractional_weights_truncate_each_band(self):
        self.assertEqual(shipping_cost(order(weight=1.99)), 648)
        self.assertEqual(shipping_cost(order(weight=5.5, express=True)), 2400)

    def test_express_is_never_free(self):
        self.assertEqual(shipping_cost(order(weight=0.2, subtotal=99999, express=True)), 1200)

    def test_free_threshold_is_us_standard_only(self):
        self.assertEqual(shipping_cost(order("CA", weight=1, subtotal=99999)), 1500)

    def test_member_discount_rounds_down_the_discount(self):
        self.assertEqual(shipping_cost(order(weight=1.5, member=True)), 518)
        self.assertEqual(shipping_cost(order(weight=8, subtotal=6000, member=True)), 0)

    def test_member_false_or_missing(self):
        self.assertEqual(shipping_cost(order(weight=3, member=False)), 800)

    def test_too_heavy_checked_after_country(self):
        with self.assertRaises(ValueError) as e:
            shipping_cost(order("FR", weight=40))
        self.assertIn("FR", str(e.exception))

    def test_too_heavy_even_when_free(self):
        with self.assertRaises(ValueError):
            shipping_cost(order(weight=31, subtotal=99999))

    def test_exactly_30_kg_ships(self):
        self.assertEqual(shipping_cost(order(weight=30)), 8600)

    def test_lowercase_country_is_not_supported(self):
        with self.assertRaises(ValueError):
            shipping_cost(order("us"))


if __name__ == "__main__":
    unittest.main()
