def test_convert_bad_dimensions(): """ Get Exception from converting to wrong dimensionality. """ u1 = Unit("Msun * Mpc**-2") q1 = Quantity(1e-29, "g * cm**-3") try: q1.convert_to(u1) except Exception: pass else: assert False
def test_convert_to(): """ Convert a density quantity from cgs to cosmological units. """ u1 = Unit("g * cm**-3") u2 = Unit("Msun * Mpc**-3") q1 = Quantity(1e-29, u1) assert q1.units == u1 q1.convert_to(u2) assert equal_sigfigs(q1.data, 1.47721e11, required_precision) assert q1.units == u2