本文整理汇总了Python中transform.Transform.format方法的典型用法代码示例。如果您正苦于以下问题:Python Transform.format方法的具体用法?Python Transform.format怎么用?Python Transform.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transform.Transform
的用法示例。
在下文中一共展示了Transform.format方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mytest
# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import format [as 别名]
class Mytest(unittest.TestCase):
def setUp(self):
self.transform = Transform()
def tearDown(self):
pass
def testFormat(self):
exp = "3+2-6/1*4"
self.assertEqual(self.transform.format(exp), exp)
exp = "-3+2-6/1*4"
self.assertEqual(self.transform.format(exp), "0-3+2-6/1*4")
exp = "-3+(-2-6/1*4)"
self.assertEqual(self.transform.format(exp), "0-3+(0-2-6/1*4)")
exp = "+3+2-6/1*4"
self.assertEqual(self.transform.format(exp), "0+3+2-6/1*4")
exp = "+3+(+2-6/1*4)"
self.assertEqual(self.transform.format(exp), "0+3+(0+2-6/1*4)")
def testIsNum(self):
num = "1"
self.assertTrue(self.transform.isnum(num))
num = "a"
self.assertFalse(self.transform.isnum(num))
def testIsOp(self):
for op in ['+', '-', '*', '/', '(', ')']:
self.assertTrue(self.transform.isop(op))
op = "123"
self.assertFalse(self.transform.isop(op))
def testGetLevel(self):
for e in ['+', '-']:
self.assertEqual(self.transform.getlevel(e), 1)
for e in ['*', '/']:
self.assertEqual(self.transform.getlevel(e), 2)
for e in ['(', ')']:
self.assertEqual(self.transform.getlevel(e), 3)
e = "123"
self.assertEqual(self.transform.getlevel(e), None)
def testCompare(self):
self.transform.get_level = MagicMock()
self.transform.compare(2, 1)
self.assertTrue(self.transform.get_level.is_called)
def testOrStack(self):
self.transform.or_stack("1")
self.assertEqual(self.transform.orstack, ["1"])
self.transform.or_stack("(")
self.assertEqual(self.transform.orstack, ["1", "("])
self.transform.or_stack("2")
self.assertEqual(self.transform.orstack, ["1", "(", "2"])
self.transform.or_stack(")")
self.assertEqual(self.transform.orstack, ["1"])
self.assertEqual(self.transform.odlist, ["2"])
self.transform.or_stack("+")
self.assertEqual(self.transform.orstack, ["1", "+"])
self.transform.or_stack("3")
self.assertEqual(self.transform.orstack, ["1", "3"])
self.assertEqual(self.transform.odlist, ["2", "+"])
def testIfToPf(self):
self.transform.format = MagicMock()
self.transform.isnum = MagicMock()
self.transform.isop = MagicMock()
exp = "3+2-5*0"
self.transform.format.return_value = exp
self.transform.isnum.return_value = True
self.transform.isop.return_value = False
self.assertEqual(self.transform.iftopf(exp), "3+2-5*0")
self.transform.odlist = []
self.transform.orstack = []
self.transform.isnum.return_value = False
self.transform.isop.return_value = True
self.transform.or_stack = MagicMock()
self.assertEqual(self.transform.iftopf(exp), "")
self.assertTrue(self.transform.or_stack.is_called)