Best Python code snippet using hypothesis
searchcars.py
Source:searchcars.py
1import os2import jinja23import webapp24from google.appengine.api import users5from google.appengine.ext import ndb6from vehicles import Vehicles7JINJA_ENVIRONMENT = jinja2.Environment(8 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),9 extensions=['jinja2.ext.autoescape'],10 autoescape=True11)12class SearchCars(webapp2.RequestHandler):13 def get(self):14 self.response.headers['Content-Type'] = 'text/html'15 url = ''16 login_status = ''17 user = users.get_current_user()18 if user:19 url = users.create_logout_url(self.request.uri)20 login_status = 'Logout'21 else:22 url = users.create_login_url(self.request.uri)23 login_status = 'Login'24 total_query = Vehicles.query()25 count = 026 for i in total_query:27 count = count + 128 template_values = {29 'user': user,30 'url': url,31 'login_status': login_status,32 'total_query': total_query,33 'count': count34 }35 template = JINJA_ENVIRONMENT.get_template('search-cars.html')36 self.response.write(template.render(template_values))37 def post(self):38 self.response.headers['Content-Type'] = 'text/html'39 url = ''40 login_status = ''41 user = users.get_current_user()42 if user:43 url = users.create_logout_url(self.request.uri)44 login_status = 'Logout'45 else:46 url = users.create_login_url(self.request.uri)47 login_status = 'Login'48 action = self.request.get('Search')49 count = 050 if action == 'Search':51 name = self.request.get('vehicleName')52 manufacturer = self.request.get('manufacturer')53 lower_year = self.request.get('lower_year')54 upper_year = self.request.get('upper_year')55 battery_lower = self.request.get('battery_lower')56 battery_upper = self.request.get('battery_upper')57 range_lower = self.request.get('range_lower')58 range_upper = self.request.get('range_upper')59 cost_lower = self.request.get('cost-lower')60 cost_upper = self.request.get('cost-upper')61 power_lower = self.request.get('power-lower')62 power_upper = self.request.get('power-upper')63 # Values if empty64 if len(lower_year) == 0:65 lower_year = int(2010)66 if len(upper_year) == 0:67 upper_year = int(2022)68 if len(battery_lower) == 0:69 battery_lower = float(50)70 if len(battery_upper) == 0:71 battery_upper = float(550)72 if len(range_lower) == 0:73 range_lower = 20074 if len(range_upper) == 0:75 range_upper = 85076 if len(cost_lower) == 0:77 cost_lower = int(20000)78 if len(cost_upper) == 0:79 cost_upper = int(80000)80 if len(power_lower) == 0:81 power_lower = int(50)82 if len(power_upper) == 0:83 power_upper = int(300)84 # Year Comparison85 if int(lower_year) >= 2010 and int(lower_year) <= 2022:86 year_lower_error_message = ''87 year_lower_error_style = ''88 else:89 year_lower_error_message = 'Year is below 2010 or above 2022'90 year_lower_error_style = 'error_style'91 if int(upper_year) >= 2010 and int(upper_year) <= 2022:92 year_higher_error_message = ''93 year_higher_error_style = ''94 else:95 year_higher_error_message = 'Year is below 2010 or above 2022'96 year_higher_error_style = 'error_style'97 # Battery Comparison98 if float(battery_lower) >= 50.0 and float(battery_lower) <= 550.0:99 battery_lower_error_message = ''100 battery_lower_error_style = ''101 else:102 battery_lower_error_message = 'Battery size is below 50.0Kwh or above 550.0Kwh'103 battery_lower_error_style = 'error_style'104 if float(battery_upper) >= 50.0 and float(battery_upper) <= 550.0:105 battery_higher_error_message = ''106 battery_higher_error_style = ''107 else:108 battery_higher_error_message = 'Battery size is below 50.0Kwh or above 550.0Kwh'109 battery_higher_error_style = 'error_style'110 # Range Comparison111 if int(range_lower) >= 200 and int(range_lower) <= 850:112 range_lower_error_message = ''113 range_lower_error_style = ''114 else:115 range_lower_error_message = 'Range is below 200km or above 850km'116 range_lower_error_style = 'error_style'117 if int(range_upper) >= 200 and int(range_upper) <= 850:118 range_higher_error_message = ''119 range_higher_error_style = ''120 else:121 range_higher_error_message = 'Range is below 200km or above 850km'122 range_higher_error_style = 'error_style'123 # Cost Comparison124 if int(cost_lower) >= 20000 and int(cost_lower) <= 80000:125 cost_lower_error_message = ''126 cost_lower_error_style = ''127 else:128 cost_lower_error_message = 'Cost is below 20,000 or above 80,000'129 cost_lower_error_style = 'error_style'130 if int(cost_upper) >= 20000 and int(cost_upper) <= 80000:131 cost_higher_error_message = ''132 cost_higher_error_style = ''133 else:134 cost_higher_error_message = 'Cost is below 20,000 or above 80,000'135 cost_higher_error_style = 'error_style'136 # Power Comparison137 if int(power_lower) >= 50 and int(power_lower) <= 300:138 power_lower_error_message = ''139 power_lower_error_style = ''140 else:141 power_lower_error_message = 'Power is below 50kW or above 300kW'142 power_lower_error_style = 'error_style'143 if int(power_upper) >= 50 and int(power_upper) <= 300:144 power_upper_error_message = ''145 power_upper_error_style = ''146 else:147 power_upper_error_message = 'Power is below 50kW or above 300kW'148 power_upper_error_style = 'error_style'149 # manufacturer = str(manufacturer)150 lower_year = int(lower_year)151 upper_year = int(upper_year)152 battery_lower = float(battery_lower)153 battery_upper = float(battery_upper)154 range_lower = int(range_lower)155 range_upper = int(range_upper)156 cost_lower = int(cost_lower)157 cost_upper = int(cost_upper)158 power_lower = int(power_lower)159 power_upper = int(power_upper)160 car_query = Vehicles.query()161 year_query = car_query.filter(Vehicles.year >= lower_year, Vehicles.year <= upper_year).fetch(keys_only=True)162 battery_query = car_query.filter(Vehicles.batterySize >= battery_lower,163 Vehicles.batterySize <= battery_upper).fetch(keys_only=True)164 range_query = car_query.filter(Vehicles.WLTP_range >= range_lower, Vehicles.WLTP_range <= range_upper).fetch(165 keys_only=True)166 cost_query = car_query.filter(Vehicles.cost >= cost_lower, Vehicles.cost <= cost_upper).fetch(keys_only=True)167 power_query = car_query.filter(Vehicles.power >= power_lower, Vehicles.power <= power_upper) \168 .fetch(keys_only=True)169 if len(name) == 0 and len(manufacturer) == 0:170 total_query = ndb.get_multi(set(year_query).intersection(battery_query).intersection(range_query)171 .intersection(cost_query).intersection(power_query))172 for i in total_query:173 count = count + 1174 elif len(name) == 0:175 manufacturer_query = Vehicles.query(Vehicles.manufacturer == manufacturer).fetch(keys_only=True)176 total_query = ndb.get_multi(set(manufacturer_query).intersection(year_query).intersection(battery_query)177 .intersection(range_query).intersection(cost_query).intersection(power_query))178 for i in total_query:179 count = count + 1180 elif len(manufacturer) == 0:181 name_query = Vehicles.query(Vehicles.name == name).fetch(keys_only=True)182 total_query = ndb.get_multi(set(name_query).intersection(year_query).intersection(battery_query)183 .intersection(range_query).intersection(cost_query).intersection(power_query))184 for i in total_query:185 count = count + 1186 else:187 name_query = Vehicles.query(Vehicles.name == name).fetch(keys_only=True)188 manufacturer_query = Vehicles.query(Vehicles.manufacturer == manufacturer).fetch(keys_only=True)189 total_query = ndb.get_multi(set(name_query).intersection(manufacturer_query).intersection(year_query)190 .intersection(battery_query).intersection(range_query).intersection(cost_query)191 .intersection(power_query))192 for i in total_query:193 count = count + 1194 template_values = {195 'user': user,196 'url': url,197 'login_status': login_status,198 'name': name,199 'manufacturer': manufacturer,200 'lower_year': lower_year,201 'upper_year': upper_year,202 'battery_lower': battery_lower,203 'battery_upper': battery_upper,204 'range_lower': range_lower,205 'range_upper': range_upper,206 'year_lower_error_message': year_lower_error_message,207 'year_lower_error_style': year_lower_error_style,208 'year_higher_error_message': year_higher_error_message,209 'year_higher_error_style': year_higher_error_style,210 'battery_lower_error_message': battery_lower_error_message,211 'battery_lower_error_style': battery_lower_error_style,212 'battery_higher_error_message': battery_higher_error_message,213 'battery_higher_error_style': battery_higher_error_style,214 'range_lower_error_message': range_lower_error_message,215 'range_lower_error_style': range_lower_error_style,216 'range_higher_error_message': range_higher_error_message,217 'range_higher_error_style': range_higher_error_style,218 'cost_lower_error_message': cost_lower_error_message,219 'cost_lower_error_style': cost_lower_error_style,220 'cost_higher_error_message': cost_higher_error_message,221 'cost_higher_error_style': cost_higher_error_style,222 'power_lower_error_message': power_lower_error_message,223 'power_lower_error_style': power_lower_error_style,224 'power_upper_error_message': power_upper_error_message,225 'power_upper_error_style': power_upper_error_style,226 'year_query': year_query,227 'battery_query': battery_query,228 'range_query': range_query,229 'cost_query': cost_query,230 'power_query': power_query,231 'total_query': total_query,232 'count': count233 # 'success_message': success_message234 }235 template = JINJA_ENVIRONMENT.get_template('search-cars.html')236 self.response.write(template.render(template_values))237 # query = car_query.filter(Vehicles.name == name, Vehicles.manufacturer == manufacturer,...
test_makeunicode.py
Source:test_makeunicode.py
...192 def test_to_ascii(self):193 s = " ée à a çc "194 self.assertEqual(sppasUnicode(s).to_ascii(), u(" _e _a _c "))195 # -----------------------------------------------------------------------196 def test_lower(self):197 for key, value in LowerDict.items():198 self.assertEqual(value, sppasUnicode(key).to_lower())199 # -----------------------------------------------------------------------200 def test_strip(self):201 self.assertEqual(sppasUnicode(' \n Ỹ \t\r á» ').to_strip(), u('Ỹ á»'))...
_Box3D.py
Source:_Box3D.py
1# This Python file uses the following encoding: utf-82"""autogenerated by genpy from j2_mono/Box3D.msg. Do not edit."""3import codecs4import sys5python3 = True if sys.hexversion > 0x03000000 else False6import genpy7import struct8import j2_mono.msg9class Box3D(genpy.Message):10 _md5sum = "d2a4c3bc64f81e95d0c37d470dea3708"11 _type = "j2_mono/Box3D"12 _has_header = False # flag to mark the presence of a Header object13 _full_text = """Point lower_lt14Point lower_lb15Point lower_rb16Point lower_rt17Point upper_lt18Point upper_lb19Point upper_rb20Point upper_rt21float32 conf22================================================================================23MSG: j2_mono/Point24float32 x25float32 y26float32 z27"""28 __slots__ = ['lower_lt','lower_lb','lower_rb','lower_rt','upper_lt','upper_lb','upper_rb','upper_rt','conf']29 _slot_types = ['j2_mono/Point','j2_mono/Point','j2_mono/Point','j2_mono/Point','j2_mono/Point','j2_mono/Point','j2_mono/Point','j2_mono/Point','float32']30 def __init__(self, *args, **kwds):31 """32 Constructor. Any message fields that are implicitly/explicitly33 set to None will be assigned a default value. The recommend34 use is keyword arguments as this is more robust to future message35 changes. You cannot mix in-order arguments and keyword arguments.36 The available fields are:37 lower_lt,lower_lb,lower_rb,lower_rt,upper_lt,upper_lb,upper_rb,upper_rt,conf38 :param args: complete set of field values, in .msg order39 :param kwds: use keyword arguments corresponding to message field names40 to set specific fields.41 """42 if args or kwds:43 super(Box3D, self).__init__(*args, **kwds)44 # message fields cannot be None, assign default values for those that are45 if self.lower_lt is None:46 self.lower_lt = j2_mono.msg.Point()47 if self.lower_lb is None:48 self.lower_lb = j2_mono.msg.Point()49 if self.lower_rb is None:50 self.lower_rb = j2_mono.msg.Point()51 if self.lower_rt is None:52 self.lower_rt = j2_mono.msg.Point()53 if self.upper_lt is None:54 self.upper_lt = j2_mono.msg.Point()55 if self.upper_lb is None:56 self.upper_lb = j2_mono.msg.Point()57 if self.upper_rb is None:58 self.upper_rb = j2_mono.msg.Point()59 if self.upper_rt is None:60 self.upper_rt = j2_mono.msg.Point()61 if self.conf is None:62 self.conf = 0.63 else:64 self.lower_lt = j2_mono.msg.Point()65 self.lower_lb = j2_mono.msg.Point()66 self.lower_rb = j2_mono.msg.Point()67 self.lower_rt = j2_mono.msg.Point()68 self.upper_lt = j2_mono.msg.Point()69 self.upper_lb = j2_mono.msg.Point()70 self.upper_rb = j2_mono.msg.Point()71 self.upper_rt = j2_mono.msg.Point()72 self.conf = 0.73 def _get_types(self):74 """75 internal API method76 """77 return self._slot_types78 def serialize(self, buff):79 """80 serialize message into buffer81 :param buff: buffer, ``StringIO``82 """83 try:84 _x = self85 buff.write(_get_struct_25f().pack(_x.lower_lt.x, _x.lower_lt.y, _x.lower_lt.z, _x.lower_lb.x, _x.lower_lb.y, _x.lower_lb.z, _x.lower_rb.x, _x.lower_rb.y, _x.lower_rb.z, _x.lower_rt.x, _x.lower_rt.y, _x.lower_rt.z, _x.upper_lt.x, _x.upper_lt.y, _x.upper_lt.z, _x.upper_lb.x, _x.upper_lb.y, _x.upper_lb.z, _x.upper_rb.x, _x.upper_rb.y, _x.upper_rb.z, _x.upper_rt.x, _x.upper_rt.y, _x.upper_rt.z, _x.conf))86 except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self)))))87 except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))88 def deserialize(self, str):89 """90 unpack serialized message in str into this message instance91 :param str: byte array of serialized message, ``str``92 """93 codecs.lookup_error("rosmsg").msg_type = self._type94 try:95 if self.lower_lt is None:96 self.lower_lt = j2_mono.msg.Point()97 if self.lower_lb is None:98 self.lower_lb = j2_mono.msg.Point()99 if self.lower_rb is None:100 self.lower_rb = j2_mono.msg.Point()101 if self.lower_rt is None:102 self.lower_rt = j2_mono.msg.Point()103 if self.upper_lt is None:104 self.upper_lt = j2_mono.msg.Point()105 if self.upper_lb is None:106 self.upper_lb = j2_mono.msg.Point()107 if self.upper_rb is None:108 self.upper_rb = j2_mono.msg.Point()109 if self.upper_rt is None:110 self.upper_rt = j2_mono.msg.Point()111 end = 0112 _x = self113 start = end114 end += 100115 (_x.lower_lt.x, _x.lower_lt.y, _x.lower_lt.z, _x.lower_lb.x, _x.lower_lb.y, _x.lower_lb.z, _x.lower_rb.x, _x.lower_rb.y, _x.lower_rb.z, _x.lower_rt.x, _x.lower_rt.y, _x.lower_rt.z, _x.upper_lt.x, _x.upper_lt.y, _x.upper_lt.z, _x.upper_lb.x, _x.upper_lb.y, _x.upper_lb.z, _x.upper_rb.x, _x.upper_rb.y, _x.upper_rb.z, _x.upper_rt.x, _x.upper_rt.y, _x.upper_rt.z, _x.conf,) = _get_struct_25f().unpack(str[start:end])116 return self117 except struct.error as e:118 raise genpy.DeserializationError(e) # most likely buffer underfill119 def serialize_numpy(self, buff, numpy):120 """121 serialize message with numpy array types into buffer122 :param buff: buffer, ``StringIO``123 :param numpy: numpy python module124 """125 try:126 _x = self127 buff.write(_get_struct_25f().pack(_x.lower_lt.x, _x.lower_lt.y, _x.lower_lt.z, _x.lower_lb.x, _x.lower_lb.y, _x.lower_lb.z, _x.lower_rb.x, _x.lower_rb.y, _x.lower_rb.z, _x.lower_rt.x, _x.lower_rt.y, _x.lower_rt.z, _x.upper_lt.x, _x.upper_lt.y, _x.upper_lt.z, _x.upper_lb.x, _x.upper_lb.y, _x.upper_lb.z, _x.upper_rb.x, _x.upper_rb.y, _x.upper_rb.z, _x.upper_rt.x, _x.upper_rt.y, _x.upper_rt.z, _x.conf))128 except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self)))))129 except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))130 def deserialize_numpy(self, str, numpy):131 """132 unpack serialized message in str into this message instance using numpy for array types133 :param str: byte array of serialized message, ``str``134 :param numpy: numpy python module135 """136 codecs.lookup_error("rosmsg").msg_type = self._type137 try:138 if self.lower_lt is None:139 self.lower_lt = j2_mono.msg.Point()140 if self.lower_lb is None:141 self.lower_lb = j2_mono.msg.Point()142 if self.lower_rb is None:143 self.lower_rb = j2_mono.msg.Point()144 if self.lower_rt is None:145 self.lower_rt = j2_mono.msg.Point()146 if self.upper_lt is None:147 self.upper_lt = j2_mono.msg.Point()148 if self.upper_lb is None:149 self.upper_lb = j2_mono.msg.Point()150 if self.upper_rb is None:151 self.upper_rb = j2_mono.msg.Point()152 if self.upper_rt is None:153 self.upper_rt = j2_mono.msg.Point()154 end = 0155 _x = self156 start = end157 end += 100158 (_x.lower_lt.x, _x.lower_lt.y, _x.lower_lt.z, _x.lower_lb.x, _x.lower_lb.y, _x.lower_lb.z, _x.lower_rb.x, _x.lower_rb.y, _x.lower_rb.z, _x.lower_rt.x, _x.lower_rt.y, _x.lower_rt.z, _x.upper_lt.x, _x.upper_lt.y, _x.upper_lt.z, _x.upper_lb.x, _x.upper_lb.y, _x.upper_lb.z, _x.upper_rb.x, _x.upper_rb.y, _x.upper_rb.z, _x.upper_rt.x, _x.upper_rt.y, _x.upper_rt.z, _x.conf,) = _get_struct_25f().unpack(str[start:end])159 return self160 except struct.error as e:161 raise genpy.DeserializationError(e) # most likely buffer underfill162_struct_I = genpy.struct_I163def _get_struct_I():164 global _struct_I165 return _struct_I166_struct_25f = None167def _get_struct_25f():168 global _struct_25f169 if _struct_25f is None:170 _struct_25f = struct.Struct("<25f")...
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!!