Пример #1
0
 def test_return_type_user(self):
     # note that user functions _CANT_ have return types
     # in zbrush, so this ignores the python.  The compiler
     # raises an error for this
     p = prepass.Prepass()
     raw = '''def userfunc():\n    return 1'''
     p.visit(ast.parse(raw))
     call = ast.Call(ast.Name("usefunc"))
     assert not p.has_return_type(call)
Пример #2
0
 def test_has_return_type(self):
     p = prepass.Prepass()
     raw = '''import zbrush, math, random'''
     p.visit(ast.parse(raw))
     call = ast.Call(ast.Name("GetActiveToolPath"))
     assert p.has_return_type(call)
Пример #3
0
 def test_get_call_name_zfunc(self):
     p = prepass.Prepass()
     example = ast.parse('''zbrush.IClick("a:b:c")''', mode='eval')
     assert (p.get_call_name(example.body)) == ('zbrush', 'IClick')
Пример #4
0
 def test_user_function_negative(self):
     p = prepass.Prepass()
     raw = '''def userfunc():\n    return 1'''
     p.visit(ast.parse(raw))
     call = ast.Call(ast.Name("not_userfunc"))
     assert not p.is_user_function(call)
Пример #5
0
 def test_no_other_math_import_aliased(self):
     p = prepass.Prepass()
     raw = '''import csv as xyz'''
     def bad(): return p.visit(ast.parse(raw))
     self.assertRaises(prepass.ParseError, bad)
Пример #6
0
 def test_no_other_import_plain(self):
     p = prepass.Prepass()
     raw = '''import csv'''
     def bad(): return p.visit(ast.parse(raw))
     self.assertRaises(prepass.ParseError, bad)
Пример #7
0
 def test_allows_random_import(self):
     p = prepass.Prepass()
     raw = '''import random'''
     p.visit(ast.parse(raw))
Пример #8
0
 def test_allows_math_import(self):
     p = prepass.Prepass()
     raw = '''import math'''
     p.visit(ast.parse(raw))
Пример #9
0
 def test_get_zfunc_signature(self):
     p = prepass.Prepass()
     raw = '''from zbrush import IClick as blah'''
     p.visit(ast.parse(raw))
     assert isinstance(p.get_signature('IClick'), inspect.FullArgSpec)
Пример #10
0
 def test_get_zfunc_func_alias(self):
     p = prepass.Prepass()
     raw = '''from zbrush import IClick as blah'''
     p.visit(ast.parse(raw))
     example = ast.parse('''blah("A")''', mode='eval')
     assert (p.is_zbrush_function(example.body))
Пример #11
0
 def test_get_zfunc_mod_alias(self):
     p = prepass.Prepass()
     raw = '''import zbrush as zb\nzb.IClick()'''
     p.visit(ast.parse(raw))
     example = ast.parse('''zb.IClick("A")''', mode='eval')
     assert (p.is_zbrush_function(example.body))
Пример #12
0
 def test_get_is_zfunc_fail_unrecognized(self):
     p = prepass.Prepass()
     raw = '''import zbrush\nzbrush.IClick()'''
     p.visit(ast.parse(raw))
     example = ast.parse('''dummy("A")''', mode='eval')
     assert (not p.is_zbrush_function(example.body))
Пример #13
0
 def test_get_call_name_raw(self):
     p = prepass.Prepass()
     example = ast.parse('''somefunction()''', mode='eval')
     assert (p.get_call_name(example.body)) == ('', 'somefunction')
Пример #14
0
 def parse (self, stringval):
     tree = ast.parse(stringval)
     p = prepass.Prepass()
     p.visit(tree)
     analyzer = compiler.Analyzer(0, input_file="dummy", prepass=p)
     return analyzer, tree
Пример #15
0
 def test_return_type_random(self):
     p = prepass.Prepass()
     raw = '''import zbrush, math, random'''
     p.visit(ast.parse(raw))
     call = ast.Call(ast.Name("randint"))
     assert p.has_return_type(call)
Пример #16
0
 def test_has_return_type_neg(self):
     p = prepass.Prepass()
     raw = '''import zbrush, math, random'''
     p.visit(ast.parse(raw))
     call = ast.Call(ast.Name("MTransformSet"))
     assert not p.has_return_type(call)