def test_attribute_forwarding(self): q = Sexagesimal("1;0,1,31") * degree with pytest.raises(AttributeError): q._from_string() with pytest.raises(AttributeError): q.does_not_exist() assert q.truncate(2).value.equals(q.value.truncate(2)) assert q.left == (1, ) assert round(q, 2).value.equals(round(q.value, 2))
def test_init(): assert (Sexagesimal( (1, 2, 31), (6, ), sign=-1, remainder=Decimal("0.3")).__repr__() == "-01,02,31 ; 06 |r0.3") # From float assert Sexagesimal.from_float(-0.016666666666666666, 2) == -Sexagesimal( (0, ), (1, )) assert Sexagesimal.from_float(0.5, 4).equals(Sexagesimal("0; 30, 0, 0, 0")) with pytest.raises(TypeError): Sexagesimal.from_float("s", 1) # From int assert Sexagesimal.from_int(5, 2) == Sexagesimal(5) with pytest.raises(TypeError): Sexagesimal.from_int("s") # From Decimal assert Sexagesimal.from_decimal(Decimal(5), 2) == Sexagesimal(5) with pytest.raises(TypeError): Sexagesimal.from_decimal(5, 1) # From Fraction assert Sexagesimal.from_fraction(Fraction(5, 1)).equals(Sexagesimal(5)) assert Sexagesimal.from_fraction(Fraction(5, 2)) == Sexagesimal("2;30") with pytest.raises(TypeError): Sexagesimal.from_fraction(5) # From str assert Sexagesimal("21,1,6,3;34") == Sexagesimal((21, 1, 6, 3), (34, )) assert Sexagesimal("0,0,0,0;").equals(Sexagesimal(0)) with pytest.raises(TypeError): Sexagesimal._from_string(5) with pytest.raises(EmptyStringException): Sexagesimal("") with pytest.raises(TooManySeparators): Sexagesimal("1;2;3") # From Sequence with pytest.raises(IllegalBaseValueError) as err: Sexagesimal((-6, 3), ()) assert "should be in the range" in str(err.value) with pytest.raises(IllegalFloatError) as err: Sexagesimal((0.3, 5), (6, 8)) assert "An illegal float" in str(err.value) # From BasedReal assert Sexagesimal(Historical("3;15"), 1).equals(Sexagesimal("3;15")) class MNumber(BasedReal, base=([5, 2], [3, 4])): pass n = MNumber.from_float(234.6777, 0) assert Sexagesimal(n, 3) == Sexagesimal.from_float(float(n), 3) # From multiple ints with pytest.raises(ValueError): Sexagesimal(3, 5, remainder=Decimal(-5)) with pytest.raises(ValueError): Sexagesimal(3, 5, remainder=0.6) # Incorrect parameters with pytest.raises(TypeError): BasedReal() with pytest.raises(ValueError): Sexagesimal(Decimal(5)) with pytest.raises(ValueError): Sexagesimal("", "") with pytest.raises(ValueError): Sexagesimal("", "", "", "") with pytest.raises(TypeError): Sexagesimal(("a", 2), (1, 2)) with pytest.raises(ValueError): Sexagesimal(1, sign=2)