Ejemplo n.º 1
0
def test_name_lookup_dict():
    numpy.testing.assert_almost_equal(
        evaluator({
            "pi": scipy.constants.pi,
            "golden": scipy.constants.golden
        }).evaluate(ast.parse("pi + golden")),
        scipy.constants.pi + scipy.constants.golden)
Ejemplo n.º 2
0
def test_name_lookup_callback():
  class custom_lookup:
    def __contains__(self, key):
      return key in ["pi", "golden"]
    def __getitem__(self, key):
      if key == "pi":
        return scipy.constants.pi
      elif key == "golden":
        return scipy.constants.golden
      else:
        raise KeyError()
  numpy.testing.assert_almost_equal(evaluator(custom_lookup()).evaluate(ast.parse("pi + golden")), scipy.constants.pi + scipy.constants.golden)
Ejemplo n.º 3
0
def test_name_lookup_callback():
    class custom_lookup:
        def __contains__(self, key):
            return key in ["pi", "golden"]

        def __getitem__(self, key):
            if key == "pi":
                return scipy.constants.pi
            elif key == "golden":
                return scipy.constants.golden
            else:
                raise KeyError()

    numpy.testing.assert_almost_equal(
        evaluator(custom_lookup()).evaluate(ast.parse("pi + golden")),
        scipy.constants.pi + scipy.constants.golden)
Ejemplo n.º 4
0
def test_not():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("not 1")), 0)
Ejemplo n.º 5
0
def test_rshift():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("8 >> 1")), 4)
Ejemplo n.º 6
0
def test_invert():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("~1")), -2)
Ejemplo n.º 7
0
def test_mod():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 % 3")), 2)
Ejemplo n.º 8
0
def test_bitand():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 & 3")), 2)
Ejemplo n.º 9
0
def test_invert():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("~1")), -2)
Ejemplo n.º 10
0
def test_rshift():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("8 >> 1")), 4)
Ejemplo n.º 11
0
def test_div():
  numpy.testing.assert_almost_equal(evaluator().evaluate(ast.parse("2/3")), 2.0/3.0)
Ejemplo n.º 12
0
def test_not():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("not 1")), 0)
Ejemplo n.º 13
0
def test_pow():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2**3")), 8)
Ejemplo n.º 14
0
def test_mult():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2*3")), 6)
Ejemplo n.º 15
0
def test_mod():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 % 3")), 2)
Ejemplo n.º 16
0
def test_lte():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 <= 3")), True)
Ejemplo n.º 17
0
def test_uadd():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("+(2+3)")), 5)
Ejemplo n.º 18
0
def test_sub():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 - 3")), -1)
Ejemplo n.º 19
0
def test_expr_1():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1+2*3")), 7)
Ejemplo n.º 20
0
def test_bitxor():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 ^ 3")), 1)
Ejemplo n.º 21
0
def test_floordiv():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2//3")), 0)
Ejemplo n.º 22
0
def test_floordiv():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2//3")), 0)
Ejemplo n.º 23
0
def test_uadd():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("+(2+3)")), 5)
Ejemplo n.º 24
0
def test_gte():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 >= 3")), False)
Ejemplo n.º 25
0
def test_div():
    numpy.testing.assert_almost_equal(evaluator().evaluate(ast.parse("2/3")),
                                      2.0 / 3.0)
Ejemplo n.º 26
0
def test_usub():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("-(2+3)")), -5)
Ejemplo n.º 27
0
def test_gte():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 >= 3")),
                               False)
Ejemplo n.º 28
0
def test_expr_1():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1+2*3")), 7)
Ejemplo n.º 29
0
def test_lte():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 <= 3")), True)
Ejemplo n.º 30
0
def test_boolean_expr_1():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1 < 2 and 2 < 3")), True)
Ejemplo n.º 31
0
def test_mult():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2*3")), 6)
Ejemplo n.º 32
0
def test_boolean_expr_2():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1 == 2 or 3 == 2 + 1")), True)
Ejemplo n.º 33
0
def test_pow():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2**3")), 8)
Ejemplo n.º 34
0
def test_name_lookup_dict():
  numpy.testing.assert_almost_equal(evaluator({"pi" : scipy.constants.pi, "golden" : scipy.constants.golden}).evaluate(ast.parse("pi + golden")), scipy.constants.pi + scipy.constants.golden)
Ejemplo n.º 35
0
def test_sub():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 - 3")), -1)
Ejemplo n.º 36
0
def test_bitand():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 & 3")), 2)
Ejemplo n.º 37
0
def test_usub():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("-(2+3)")), -5)
Ejemplo n.º 38
0
def test_boolean_expr_2():
    numpy.testing.assert_equal(
        evaluator().evaluate(ast.parse("1 == 2 or 3 == 2 + 1")), True)
Ejemplo n.º 39
0
def test_boolean_expr_1():
    numpy.testing.assert_equal(
        evaluator().evaluate(ast.parse("1 < 2 and 2 < 3")), True)
Ejemplo n.º 40
0
def test_bitxor():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 ^ 3")), 1)