import json from utils import metric2imperial from classes import Film if __name__ == "__main__": film = Film(1) film.get_all_cross_refs() for char in film.characters: char["mass"] = metric2imperial(char["mass"], "kg", "lb") char["height"] = metric2imperial(char["height"], "cm", "ft") with open("task_two.json", "w") as f: f.write(json.dumps(film.write_contents(), indent=2))
def test_cm2ft(self): self.assertEqual(metric2imperial(100, "cm", "ft"), 3.28)
def test_kg2lb(self): self.assertEqual(metric2imperial(100, "kg", "lb"), 220.5)
def test_failure(self): with self.assertRaises(KeyError): metric2imperial(100, "in", "ft")
def test_invalid(self): self.assertEqual(metric2imperial("unknown", "cm", "ft"), "unknown")
def test_cm2ft(self): self.assertEqual(metric2imperial(178, "cm", "ft"), 5.84)