def test_import_module_with_func(ut): # set up ps.addToPythonPath('tests') # exercise ps.checkString('import func_a') # verify result = first_in_history('func_a', ps) ut.assertTrue(isinstance(result, ps.ObjType)) ut.assertTrue('a' in result.attrs.keys()) ut.assertTrue(isinstance(result.attrs['a'], list)) ut.assertTrue(1, len(result.attrs['a'])) ut.assertTrue(isinstance(result.attrs['a'][0], ps.Closure))
#!/usr/bin/python import pysonar import sys import os import ast from collections import defaultdict # lookup arg in env if it is Name def convertName(arg, env): if pysonar.IS(arg, ast.Name): return pysonar.lookup(arg.id, env) return arg import cProfile if __name__ == '__main__': pysonar.addToPythonPath(os.path.dirname(sys.argv[1])) #cProfile.run('pysonar.checkFile("' + sys.argv[1] + '")') pysonar.checkFile(sys.argv[1]) constructor_params = defaultdict(set) for class_name, val in pysonar.getMethodInvocationInfo().items(): print class_name for constrargs, args, env in val: print constrargs, args if constrargs: for first_constructor_arg in constrargs[0]: pysonar.debug('first_constructor_arg:', first_constructor_arg.__class__) constructor_params[class_name].add(first_constructor_arg) # print '\t', constrargs, map(lambda arg: convertName(arg, env), args) print constructor_params
def test_huge_dict(): ps.addToPythonPath('tests') # exercise ps.checkString('import huge_dict')