Exemplo n.º 1
0
def make_tokenizer(text, should_resolve=True, **kwargs):
    reader = Reader(StringIO(text))
    variable = EnvironmentVariable(kwargs)
    expanding = Expansion(reader, variable)
    tokenizer = MathTokenizer(At("", -1, -1), reader, expanding,
                              should_resolve)
    return tokenizer
Exemplo n.º 2
0
 def test_expand_math_neg_number_2(self):
     expanding = make_expanding("($A * ---4)!", A="-4")
     self.assertEqual("16", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 3
0
 def test_expand_with_quotes(self):
     expanding = make_expanding("{A:sql,attr}!", A="ab'\"cd")
     self.assertEqual("ab''"cd", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 4
0
 def test_expand_math_precedence_op(self):
     expanding = make_expanding("(4/3*0)!")
     self.assertEqual("0", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 5
0
 def test_expand_math_neg_number_1(self):
     expanding = make_expanding("(- 4)!")
     self.assertEqual("-4", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 6
0
 def test_expand_math_nested_paren(self):
     expanding = make_expanding("( ( $A ) )!", A="321")
     self.assertEqual("321", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 7
0
 def test_expand_math_precedence_op(self):
     expanding = make_expanding("($A+3*4)!", A="321")
     self.assertEqual("333", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 8
0
 def test_expand_with_nested_resolved(self):
     expanding = make_expanding("{FOO|12${ABC}3}!", FOO="BAR")
     self.assertEqual("BAR", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 9
0
 def test_expand_math(self):
     expanding = make_expanding("(123)!")
     self.assertEqual("123", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 10
0
 def test_expand_with_default_resolvable(self):
     expanding = make_expanding("{FOO|12\\}3}!", FOO="BAR")
     self.assertEqual("BAR", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 11
0
 def test_expand_with_default_quoted(self):
     expanding = make_expanding("{ABC|12\\}3}!", FOO="BAR")
     self.assertEqual("12}3", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 12
0
 def test_expand_with_nothing_special(self):
     expanding = make_expanding("{FOO}!", FOO="BAR")
     self.assertEqual("BAR", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
Exemplo n.º 13
0
 def test_expand_simple_missing_value(self):
     expanding = make_expanding("ABC!", FOO="BAR")
     self.assertRaises(Exception, expanding.expand, At("", -1, -1))
Exemplo n.º 14
0
 def test_expand_simple(self):
     expanding = make_expanding("FOO!", FOO="BAR")
     self.assertEqual("BAR", expanding.expand(At("", -1, -1)))
     self.assertEqual("!", expanding._reader.get())
     self.assertRaises(Exception, expanding.expand, At("", -1, -1))