Best Python code snippet using autotest_python
test_proxy_internals.py
Source:test_proxy_internals.py
...12 self.obj = obj13 14 def perform(self, name, *args, **kwargs):15 return getattr(self.obj, name)(*args, **kwargs)16 def get_proxy(f):17 from __pypy__ import tproxy as proxy18 return proxy(type(f), Controller(f).perform)19 return get_proxy20 """)21class AppTestProxyInterpOnly(AppProxy):22 def setup_class(cls):23 if cls.runappdirect:24 py.test.skip("interp only test")25 from pypy.interpreter.typedef import TypeDef, interp2app26 from pypy.interpreter.baseobjspace import Wrappable27 class W_Stuff(Wrappable):28 pass29 def descr_new(space, w_subtype):30 return W_Stuff()31 W_Stuff.typedef = TypeDef(32 'Stuff',33 __new__ = interp2app(descr_new),34 )35 cls.w_Stuff = cls.space.gettypefor(W_Stuff)36 def test_unproxyable(self):37 raises(TypeError, self.get_proxy, self.Stuff())38class AppTestProxyInternals(AppProxy):39 def test_traceback_basic(self):40 try:41 1/042 except:43 import sys44 e = sys.exc_info()45 46 tb = self.get_proxy(e[2])47 assert tb.tb_frame is e[2].tb_frame48 def test_traceback_catch(self):49 try:50 try:51 1/052 except ZeroDivisionError, e:53 ex = self.get_proxy(e)54 raise ex55 except ZeroDivisionError:56 pass57 else:58 raise AssertionError("Did not raise")59 def test_traceback_reraise(self):60 #skip("Not implemented yet")61 try:62 1/063 except:64 import sys65 e = sys.exc_info()66 67 tb = self.get_proxy(e[2])68 raises(ZeroDivisionError, "raise e[0], e[1], tb")69 raises(ZeroDivisionError, "raise e[0], self.get_proxy(e[1]), tb")70 import traceback71 assert len(traceback.format_tb(tb)) == 172 def test_simple_frame(self):73 import sys74 frame = sys._getframe(0)75 fp = self.get_proxy(frame)76 assert fp.f_locals == frame.f_locals77class AppTestProxyTracebackController(AppProxy):78 def test_controller(self):79 import types80 import sys81 import traceback82 83 def get_proxy(f):84 from __pypy__ import tproxy as proxy85 return proxy(type(f), Controller(f).perform)86 87 class FakeTb(object):88 def __init__(self, tb):89 self.tb_lasti = tb.tb_lasti90 self.tb_lineno = tb.tb_lineno91 if tb.tb_next:92 self.tb_next = FakeTb(tb.tb_next)93 else:94 self.tb_next = None95 self.tb_frame = get_proxy(tb.tb_frame)96 97 class Controller(object):98 def __init__(self, tb):99 if isinstance(tb, types.TracebackType):100 self.obj = FakeTb(tb)101 else:102 self.obj = tb103 104 def perform(self, name, *args, **kwargs):105 return getattr(self.obj, name)(*args, **kwargs)106 107 def f():108 1/0109 110 def g():111 f()112 113 try:114 g()115 except:116 e = sys.exc_info()117 118 last_tb = e[2]119 tb = get_proxy(e[2])120 try:121 raise e[0], e[1], tb122 except:123 e = sys.exc_info()124 125 assert traceback.format_tb(last_tb) == traceback.format_tb(e[2])126 127 def test_proxy_get(self):128 from __pypy__ import tproxy, get_tproxy_controller129 l = [1,2,3]130 def f(name, *args, **kwargs):131 return getattr(l, name)(*args, **kwargs)132 lst = tproxy(list, f)133 assert get_tproxy_controller(lst) is f...
test_proxy_function.py
Source:test_proxy_function.py
...10 self.obj = obj11 12 def perform(self, name, *args, **kwargs):13 return getattr(self.obj, name)(*args, **kwargs)14 def get_proxy(f):15 import types16 from __pypy__ import tproxy as proxy17 return proxy(types.FunctionType, Controller(f).perform)18 return get_proxy19 """)20 21 def test_function_noargs(self):22 def f():23 return 324 25 fun = self.get_proxy(f)26 assert fun() == f()27 28 def test_simple_function(self):29 def f(x):30 return x31 fun = self.get_proxy(f)32 assert fun(3) == f(3)33 def test_function_args(self):34 def f(x, y):35 return x36 37 fun = self.get_proxy(f)38 raises(TypeError, "fun(3)")39 assert fun(1,2) == 140 def test_method_bind(self):41 def f(self):42 return 343 44 class A(object):45 pass46 47 fun = self.get_proxy(f)48 assert fun.__get__(A())() == 349 def test_function_repr(self):50 def f():51 pass52 53 fun = self.get_proxy(f)54 assert repr(fun).startswith("<function f")55 def test_func_code(self):56 def f():57 pass58 59 fun = self.get_proxy(f)60 assert fun.func_code is f.func_code61 def test_funct_prop_setter_del(self):62 def f():63 pass64 65 fun = self.get_proxy(f)66 fun.__doc__ = "aaa"67 assert f.__doc__ == 'aaa'68 del fun.__doc__69 assert f.__doc__ is None70 def test_proxy_bind_method(self):71 class A(object):72 pass73 74 def f(self):75 return 376 77 class AA(object):78 pass79 ...
save_proxy.py
Source:save_proxy.py
1# -*- coding: utf-8 -*-2import requests3import random4import json5import os6import sys7sys.path.append('/spider_tycweb_enterprise/')8from db.client_db import proxy_ip, admin_heap, login_ip9from db.get_path import get_path10class Proxy(object):11 def __init__(self):12 # self.get_proxy = 'http://47.103.37.73:8001/v1/info?username=zmhttp829052&remark=dx320301_2'13 self.get_proxy = 'http://47.103.37.73:8001/v1/info?username=tuoluo&remark=dx341701_3'14 # self.dial_set = 'http://47.103.37.73:8001/v1/dialer?username=zmhttp829052&remark=dx320301_2'15 self.dial_set = 'http://47.103.37.73:8001/v1/dialer?username=tuoluo&remark=dx341701_3'16 self.proxy = {17 'https': 'https://{}'18 }19 def index_request(self):20 get_proxy = requests.get(self.get_proxy, timeout=5)21 print(type(json.loads(get_proxy.text)))22 if (json.loads(get_proxy.text)) and ((json.loads(get_proxy.text)).get('success', False)):23 ip_u = [f'{i["s5_ip"]}:{i["s5_port"]}-{i["ipid"]}' for i in (json.loads(get_proxy.text)).get('data')]24 print(ip_u)25 # for ip_proxy in ip_u:26 # vals = proxy_ip.lpush('proxy_pool', ip_proxy)27 # if vals:28 # login_ip.lpush('login_ip', ip_proxy.split('-')[0])29 # return True30class VipUser(object):31 def __init__(self):32 pass33 def read_file(self):34 print(get_path, '#'*80)35 # with open(r'D:\tyc_project\spider_tycweb_enterprise-master\db\vip_user_pd.txt', 'r') as rf:36 with open(get_path, 'r') as rf:37 info_user = rf.read()38 user_list = [i.replace('éå¤ç´°', '') for i in info_user.split('\n') if 'éå¤ç´°' in i]39 pd_list = [i.replace('çµåç´°', '') for i in info_user.split('\n') if 'çµåç´°' in i]40 vip_item = dict(map(lambda x,y:[x,y],user_list,pd_list))41 print(vip_item)42 # for vip_admin in vip_item:43 # admin_heap.lpush('admin_heap', vip_admin+'-'+vip_item[vip_admin])44 # return True45def main():46 obj = Proxy()47 proxy = obj.index_request()48 obj = VipUser()49 vip_user = obj.read_file()50 return proxy, vip_user51if __name__ == '__main__':52 import time53 while True:54 func = main()55 print(func)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!