def test_inclusive_range(self): r = Restriction("[1.0]") assert str(r.lower_bound) == "1.0" assert r.lower_bound_inclusive assert str(r.upper_bound) == "1.0" assert r.upper_bound_inclusive assert "0.8" not in r assert "1.0" in r assert "1.1" not in r assert "2.0" not in r r = Restriction("[1.2,1.3]") assert str(r.lower_bound) == "1.2" assert r.lower_bound_inclusive assert str(r.upper_bound) == "1.3" assert r.upper_bound_inclusive assert "0.8" not in r assert "1.1" not in r assert "1.2" in r assert "1.2.1" in r assert "1.3" in r assert "1.3.1" not in r assert "2.0" not in r
def test_no_lower_limit(self): r = Restriction("(,1.0]") assert r.lower_bound is None assert not r.lower_bound_inclusive assert str(r.upper_bound) == "1.0" assert r.upper_bound_inclusive assert "0.1" in r assert "1.0" in r assert "1.1" not in r assert "2.0" not in r
def test_exclusive_lower_bound(self): r = Restriction("(1.0,2.0]") assert str(r.lower_bound) == "1.0" assert not r.lower_bound_inclusive assert str(r.upper_bound) == "2.0" assert r.upper_bound_inclusive assert "0.1" not in r assert "1.0" not in r assert "1.1" in r
def test_everyting_spec(self): r = Restriction("[,)") assert r.lower_bound is None assert r.lower_bound_inclusive assert r.upper_bound is None assert not r.upper_bound_inclusive assert "0.1.0" in r assert "1.0" in r assert "2.0" in r
def test_exclusive_upper_bound(self): r = Restriction("[1.0,2.0)") assert str(r.lower_bound) == "1.0" assert r.lower_bound_inclusive assert str(r.upper_bound) == "2.0" assert not r.upper_bound_inclusive assert "0.8" not in r assert "1.0" in r assert "1.9" in r assert "2.0" not in r assert "3.0" not in r r = Restriction("[1.5,)") assert str(r.lower_bound) == "1.5" assert r.lower_bound_inclusive assert r.upper_bound is None assert not r.upper_bound_inclusive assert "0.8" not in r assert "1.4" not in r assert "1.5" in r assert "100.3" in r
def test_string_repr(self): for input in ("[1.0]", "[1.0,)", "[1.0,2.0]", "[1.0,2.0)", "(1.0,2.0)", "[,2.0]", "[,2.0)", "(,2.0)"): actual = str(Restriction(input)) assert input == actual, \ "Restriction(%s) == %s, wanted %s" % (input, actual, input)
def test_compare(self): r1 = Restriction("(1.0,2.0]") assert r1 == r1 assert r1 == "(1.0,2.0]" assert 1 < r1