mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +02:00
added tests for common.calculate_math_string
This commit is contained in:
parent
24b20d7668
commit
6b1f242d25
@ -3224,6 +3224,8 @@ def calculate_math_string(expr):
|
||||
raise SyntaxError(node)
|
||||
|
||||
try:
|
||||
if '#' in expr:
|
||||
raise SyntaxError('no comments allowed')
|
||||
return execute_ast(ast.parse(expr, mode='eval').body)
|
||||
except SyntaxError as e:
|
||||
raise SyntaxError("could not parse expression '{expr}', "
|
||||
|
@ -779,6 +779,19 @@ class CommonTest(unittest.TestCase):
|
||||
self.assertEqual(('1.0-free', '1', 'com.kunzisoft.fdroidtest.applicationidsuffix'),
|
||||
fdroidserver.common.parse_androidmanifests(paths, app))
|
||||
|
||||
def test_calculate_math_string(self):
|
||||
self.assertEqual(1234, fdroidserver.common.calculate_math_string('1234'))
|
||||
self.assertEqual(4, fdroidserver.common.calculate_math_string('(1+1)*2'))
|
||||
self.assertEqual(2, fdroidserver.common.calculate_math_string('(1-1)*2+3*1-1'))
|
||||
with self.assertRaises(SyntaxError):
|
||||
fdroidserver.common.calculate_math_string('__import__("urllib")')
|
||||
with self.assertRaises(SyntaxError):
|
||||
fdroidserver.common.calculate_math_string('self')
|
||||
with self.assertRaises(SyntaxError):
|
||||
fdroidserver.common.calculate_math_string('1+1; print(1)')
|
||||
with self.assertRaises(SyntaxError):
|
||||
fdroidserver.common.calculate_math_string('1-1 # no comment')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = optparse.OptionParser()
|
||||
|
Loading…
Reference in New Issue
Block a user