Beispiel #1
0
def test_coerce_float_list():
    """Test coerce_float_list."""
    validator = ParsecValidator()
    # The good
    for value, results in [('', []), ('3', [3.0]),
                           ('2*3.141592654', [3.141592654, 3.141592654]),
                           ('12*8, 8*12.0', [8.0] * 12 + [12.0] * 8),
                           ('-3, -2, -1, -0.0, 1.0',
                            [-3.0, -2.0, -1.0, -0.0, 1.0]),
                           ('6.02e23, -1.6021765e-19, 6.62607004e-34',
                            [6.02e23, -1.6021765e-19, 6.62607004e-34])]:
        items = validator.coerce_float_list(value, ['whatever'])
        for item, result in zip(items, results):
            pytest.approx(item, result)
    # The bad
    for value in [
            'None', 'e, i, e, i, o', '[]', '[3.14]', 'pi, 2.72', '2*True'
    ]:
        with pytest.raises(IllegalValueError):
            validator.coerce_float_list(value, ['whatever'])
Beispiel #2
0
 def test_coerce_float_list(self):
     """Test coerce_float_list."""
     validator = ParsecValidator()
     # The good
     for value, results in [
         ('', []),
         ('3', [3.0]),
         ('2*3.141592654', [3.141592654, 3.141592654]),
         ('12*8, 8*12.0', [8.0] * 12 + [12.0] * 8),
         ('-3, -2, -1, -0.0, 1.0', [-3.0, -2.0, -1.0, -0.0, 1.0]),
         ('6.02e23, -1.6021765e-19, 6.62607004e-34',
          [6.02e23, -1.6021765e-19, 6.62607004e-34])
     ]:
         items = validator.coerce_float_list(value, ['whatever'])
         for item, result in zip(items, results):
             self.assertAlmostEqual(item, result)
     # The bad
     for value in [
         'None', 'e, i, e, i, o', '[]', '[3.14]', 'pi, 2.72', '2*True'
     ]:
         self.assertRaises(
             IllegalValueError,
             validator.coerce_float_list, value, ['whatever'])
Beispiel #3
0
def test_coerce_float_list__bad(value: str):
    with pytest.raises(IllegalValueError):
        ParsecValidator.coerce_float_list(value, ['whatever'])
Beispiel #4
0
def test_coerce_float_list(value: str, expected: List[float]):
    """Test coerce_float_list."""
    items = ParsecValidator.coerce_float_list(value, ['whatever'])
    assert items == approx(expected)