def get_all_funcs(self): mainfunc = pafy._get_mainfunc_from_js(JAVASCRIPT) otherfuncs = pafy._get_other_funcs(mainfunc, JAVASCRIPT) # store all functions in Pafy.funcmap pafy.Pafy.funcmap = {"jsurl": {mainfunc['name']: mainfunc}} pafy.Pafy.funcmap["jsurl"]["mainfunction"] = mainfunc for funcname, func in otherfuncs.items(): pafy.Pafy.funcmap['jsurl'][funcname] = func return mainfunc, otherfuncs
def test_get_other_funcs(self): """ Test extracting javascript functions. """ js = "function f$(x,y){var X=x[1];var Y=y[1];return X;}" primary_func = dict(body="a=f$(12,34);b=f$(56,67)") otherfuncs = pafy._get_other_funcs(primary_func, js) # otherfuncs should be: #{'f$': {'body': var X=x[1];var Y=y[1];return X;", # 'name': 'f$', 'parameters': ['x', 'y']}} expected_body = 'var X=x[1];var Y=y[1];return X;' self.assertEqual(otherfuncs['f$']['body'], expected_body) self.assertEqual(otherfuncs['f$']['name'], 'f$') self.assertEqual(otherfuncs['f$']['parameters'], ['x', 'y'])