def testPartsArentNone(): """ FractionValue can't be initialized nor modified to have None as number or fraction part. """ with pytest.raises(TypeError): FractionValue(1, None) with pytest.raises(TypeError): FractionValue(None, (0 / 1)) with pytest.raises(TypeError): FractionValue(None, None) f = FractionValue(1, Fraction(0, 1)) with pytest.raises(TypeError): f.SetNumber(None) with pytest.raises(TypeError): f.SetFraction(None)
def testBasicUsage(): f = FractionValue(3, Fraction(5, 3)) assert f.number == 3 assert f.fraction == Fraction(5, 3) f.number = 5.5 f.fraction = Fraction(6, 5) assert f.number == 5.5 assert f.fraction == Fraction(6, 5) with pytest.raises(TypeError): f.SetNumber("hello") with pytest.raises(TypeError): f.SetFraction("hello") with pytest.raises(ValueError): f.SetFraction((1, 2, 3)) assert FractionValue(3).GetFraction() == Fraction(0, 1)