Esempio n. 1
0
    def evaluate_weight(self, src_value: float) -> float:
        """
        Evaluate weight of relation.

        :param src_value: float-value of source attribute
        :return: evaluated weight of relation
        """
        return float(safe_eval(self.evaluation.replace('x', str(src_value))))
Esempio n. 2
0
def test_full():
    d = """[
        '1',
        b'b',
        (1 + 2, 1 / 5, 3 ** 8),
        { 'help': {'1', 'x', 1 + 2}, 1 : 'yelp' }
    ]"""
    assert seval.safe_eval(d) == eval(d)
Esempio n. 3
0
def test_unsafe():
    with pytest.raises(ValueError):
        seval.safe_eval('pow(2,3)')
Esempio n. 4
0
def test_sequence(seq):
    for t in (list, set, tuple):
        assert seval.safe_eval(repr(t(seq))) == eval(repr(t(seq)))
Esempio n. 5
0
def test_dict():
    d = {'a': 1, 'a b c': 2, 1: 'a'}
    assert seval.safe_eval(repr(d)) == d
Esempio n. 6
0
def test_literal(literal):
    assert seval.safe_eval(literal) == eval(literal)
Esempio n. 7
0
def test_expression(exp):
    assert seval.safe_eval(exp) == eval(exp)
Esempio n. 8
0
def test_binary(op):
    l = _get_random_digit()
    r = _get_random_digit(non_zero=True)
    exp = _get_binary(op, l, r)
    assert seval.safe_eval(exp) == eval(exp)
Esempio n. 9
0
def test_unary(op):
    d = _get_random_digit()
    exp = _get_unary(op, d)
    assert seval.safe_eval(exp) == eval(exp)
Esempio n. 10
0
def test_num(number):
    assert seval.safe_eval(str(number)) == eval(number)