コード例 #1
0
def test_good_and():
    # combiner == 'AND'
    m = MultiType(
        Numbers(min_value=2e-3, max_value=5e4),
        PermissiveMultiples(divisor=1e-3),
        combiner="AND",
    )

    for v in [
            10, 11, 123, 1000, 49999.0, 49999.1, 49999.9, 50000.0, 0.1, 0.01,
            0.002
    ]:
        m.validate(v)

    # in py True == 1, so valid in this construction
    for v in [
            0,
            0.001,
            50000.1,
            "Q",
            "Qcode",
            None,
            -1,
            b"nice",
        [],
        {},
            a_func,
            AClass,
            AClass(),
            False,
    ]:
        with pytest.raises(ValueError):
            m.validate(v)

    assert (
        repr(m) ==
        "<MultiType: Numbers 0.002<=v<=50000.0, PermissiveMultiples, Multiples of 0.001 to within 1e-09>"
    )
    assert m.is_numeric
    assert not MultiType(Strings(), Enum(1, 2), combiner="AND").is_numeric
コード例 #2
0
 def test_valid_values(self):
     for div in self.divisors:
         pm = PermissiveMultiples(div)
         for val in pm.valid_values:
             pm.validate(val)
コード例 #3
0
 def test_precision(self):
     pm_lax = PermissiveMultiples(35e-9, precision=3e-9)
     pm_lax.validate(72e-9)
     pm_strict = PermissiveMultiples(35e-9, precision=1e-10)
     with self.assertRaises(ValueError):
         pm_strict.validate(70.2e-9)
コード例 #4
0
 def test_not_passing(self):
     for divind, div in enumerate(self.divisors):
         val = PermissiveMultiples(div)
         for mult in self.not_multiples[divind]:
             with self.assertRaises(ValueError):
                 val.validate(mult)
コード例 #5
0
 def test_passing(self):
     for divind, div in enumerate(self.divisors):
         val = PermissiveMultiples(div)
         for mult in self.multiples[divind]:
             val.validate(mult)
コード例 #6
0
def test_precision():
    pm_lax = PermissiveMultiples(35e-9, precision=3e-9)
    pm_lax.validate(72e-9)
    pm_strict = PermissiveMultiples(35e-9, precision=1e-10)
    with pytest.raises(ValueError):
        pm_strict.validate(70.2e-9)
コード例 #7
0
def test_not_passing():
    for divind, div in enumerate(divisors):
        val = PermissiveMultiples(div)
        for mult in not_multiples[divind]:
            with pytest.raises(ValueError):
                val.validate(mult)