Constant tests extract to a different file
type conversions test added
This commit is contained in:
@@ -11,26 +11,13 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import types
|
||||
|
||||
import unittest
|
||||
from yaql.tests import YaqlTest
|
||||
|
||||
|
||||
class TestSystemFunctions(YaqlTest):
|
||||
def test_string_constant(self):
|
||||
self.assertEquals("abc", self.eval("abc"))
|
||||
self.assertEquals("100", self.eval("'100'"))
|
||||
self.assertEquals('some mw const', self.eval("'some mw const'"))
|
||||
|
||||
def test_numeric_constant(self):
|
||||
self.assertEquals(0, self.eval('0'))
|
||||
self.assertEquals(100, self.eval('100'))
|
||||
self.assertEquals(0, self.eval("0"))
|
||||
self.assertEquals(100, self.eval("100"))
|
||||
|
||||
def test_negative_constant(self):
|
||||
self.assertEquals(-10, self.eval('-10'))
|
||||
|
||||
class TestArithmetic(YaqlTest):
|
||||
def test_int_arithmetic(self):
|
||||
self.assertEquals(20, self.eval('15+5'))
|
||||
self.assertEquals(20, self.eval('15+10-5'))
|
||||
@@ -49,6 +36,15 @@ class TestSystemFunctions(YaqlTest):
|
||||
self.assertEquals(-25, self.eval('-20 + -5'))
|
||||
self.assertEquals(-25, self.eval('-20 - +5'))
|
||||
|
||||
def test_int_conversion(self):
|
||||
self.assertNotEquals(types.IntType, type(self.eval('123.45')))
|
||||
self.assertEquals(types.IntType, type(self.eval('int(123.45)')))
|
||||
|
||||
def test_float_conversion(self):
|
||||
self.assertNotEquals(types.FloatType, type(self.eval('123')))
|
||||
self.assertEquals(types.FloatType, type(self.eval('float(123)')))
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
52
yaql/tests/test_const.py
Normal file
52
yaql/tests/test_const.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2014 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import unittest
|
||||
from yaql.tests import YaqlTest
|
||||
|
||||
|
||||
class TestConst(YaqlTest):
|
||||
def test_string_constant(self):
|
||||
self.assertEquals("abc", self.eval("abc"))
|
||||
self.assertEquals("100", self.eval("'100'"))
|
||||
self.assertEquals('some mw const', self.eval("'some mw const'"))
|
||||
self.assertEquals('i\'m fine', self.eval("'i\\'m fine'"))
|
||||
|
||||
def test_numeric_constant(self):
|
||||
self.assertEquals(0, self.eval('0'))
|
||||
self.assertEquals(100, self.eval('100'))
|
||||
self.assertEquals(0, self.eval("0"))
|
||||
self.assertEquals(100, self.eval("100"))
|
||||
|
||||
def test_negative_constant(self):
|
||||
self.assertEquals(-10, self.eval('-10'))
|
||||
|
||||
def test_boolean_constant(self):
|
||||
self.assertEquals(True, self.eval('true'))
|
||||
self.assertEquals(False, self.eval('false'))
|
||||
self.assertNotEquals(True, self.eval('True'))
|
||||
self.assertNotEquals(False, self.eval('False'))
|
||||
|
||||
def test_r_multiline(self):
|
||||
self.assertEval(10, '3 +\r 7')
|
||||
|
||||
def test_n_multiline(self):
|
||||
self.assertEval(10, '3 +\n 7')
|
||||
|
||||
def test_rn_multiline(self):
|
||||
self.assertEval(10, '3\r\n +\r\n 7')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user