How to use stuff method in pytest-benchmark

Best Python code snippet using pytest-benchmark

SimpleJSONReadTest.py

Source:SimpleJSONReadTest.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import absolute_import3from __future__ import division4from __future__ import print_function5from __future__ import unicode_literals6import sys7import unittest8import math9from thrift.protocol import TSimpleJSONProtocol, TProtocol10from thrift.transport.TTransport import TMemoryBuffer11from thrift.util import Serializer12from SimpleJSONRead.ttypes import SomeStruct, Stuff13def writeToJSON(obj):14 trans = TMemoryBuffer()15 proto = TSimpleJSONProtocol.TSimpleJSONProtocol(trans)16 obj.write(proto)17 return trans.getvalue()18def readStuffFromJSON(jstr, struct_type=Stuff):19 stuff = struct_type()20 trans = TMemoryBuffer(jstr)21 proto = TSimpleJSONProtocol.TSimpleJSONProtocol(trans,22 struct_type.thrift_spec)23 stuff.read(proto)24 return stuff25class TestSimpleJSONRead(unittest.TestCase):26 def test_primitive_type(self):27 stuff = Stuff(28 aString="hello",29 aShort=10,30 anInteger=23990,31 aLong=123456789012,32 aDouble=1234567.9,33 aBool=True)34 j = writeToJSON(stuff)35 stuff_read = readStuffFromJSON(j)36 self.assertEqual(stuff_read.aString, "hello")37 self.assertEqual(stuff_read.aShort, 10)38 self.assertEqual(stuff_read.anInteger, 23990)39 self.assertEqual(stuff_read.aLong, 123456789012)40 self.assertEqual(stuff_read.aDouble, 1234567.9)41 self.assertTrue(stuff_read.aBool)42 def test_escape_string(self):43 stuff = Stuff(44 aString=b'\\"hello')45 j = writeToJSON(stuff)46 stuff_read = readStuffFromJSON(j)47 self.assertEqual(stuff_read.aString, '\\"hello')48 def test_unicode_in_binary_escape(self):49 stuff = Stuff(50 aBinary=b'\\"hello'.decode('utf-8'))51 j = writeToJSON(stuff)52 self.assertEqual(j, b'{\n "aBinary": "\\\\\\"hello"\n}')53 stuff_read = readStuffFromJSON(j)54 self.assertEqual(stuff_read.aBinary, b'\\"hello')55 def test_unicode_string(self):56 stuff = Stuff(57 aString='año'.encode('utf-8'))58 j = writeToJSON(stuff)59 stuff_read = readStuffFromJSON(j)60 if sys.version_info[0] == 3:61 self.assertEqual(stuff_read.aString, 'año')62 else:63 self.assertEqual(stuff_read.aString, 'año'.encode('utf-8'))64 def test_unusual_numbers(self):65 j = '{ "aListOfDouble": ["inf", "-inf", "nan"]}'66 stuff_read = readStuffFromJSON(j)67 self.assertEqual(len(stuff_read.aListOfDouble), 3)68 self.assertTrue(math.isinf(stuff_read.aListOfDouble[0]))69 self.assertTrue(math.isinf(stuff_read.aListOfDouble[1]))70 self.assertTrue(math.isnan(stuff_read.aListOfDouble[2]))71 def test_unexpected_field(self):72 j = '{ "anInteger": 101, "unexpected": 111.1}'73 struct_read = readStuffFromJSON(j, struct_type=SomeStruct)74 self.assertEqual(struct_read.anInteger, 101)75 def test_map(self):76 stuff = Stuff(77 aMap={1: {"hello": [1,2,3,4],78 "world": [5,6,7,8]},79 2: {"good": [100, 200],80 "bye": [300, 400]}81 },82 anotherString="Hey")83 j = writeToJSON(stuff)84 stuff_read = readStuffFromJSON(j)85 self.assertEqual(len(stuff_read.aMap), 2)86 self.assertEqual(stuff_read.aMap[1]["hello"], [1,2,3,4])87 self.assertEqual(stuff_read.aMap[1]["world"], [5,6,7,8])88 self.assertEqual(stuff_read.aMap[2]["good"], [100, 200])89 self.assertEqual(stuff_read.aMap[2]["bye"], [300, 400])90 self.assertEqual(stuff_read.anotherString, "Hey")91 def test_list(self):92 stuff = Stuff(93 aList=[94 [[["hello", "world"], ["good", "bye"]]],95 [[["what", "is"], ["going", "on"]]]],96 anotherString="Hey")97 j = writeToJSON(stuff)98 stuff_read = readStuffFromJSON(j)99 self.assertEqual(len(stuff_read.aList), 2)100 self.assertEqual(stuff_read.aList[0][0][0], ["hello", "world"])101 self.assertEqual(stuff_read.aList[0][0][1], ["good", "bye"])102 self.assertEqual(stuff_read.aList[1][0][0], ["what", "is"])103 self.assertEqual(stuff_read.aList[1][0][1], ["going", "on"])104 self.assertEqual(stuff_read.anotherString, "Hey")105 def test_set(self):106 stuff = Stuff(107 aListOfSet=[set(["hello"]), set(["world"])],108 anotherString="Hey")109 j = writeToJSON(stuff)110 stuff_read = readStuffFromJSON(j)111 self.assertEqual(len(stuff_read.aListOfSet), 2)112 self.assertEqual(stuff_read.aListOfSet[0], set(["hello"]))113 self.assertEqual(stuff_read.aListOfSet[1], set(["world"]))114 self.assertEqual(stuff_read.anotherString, "Hey")115 def test_struct(self):116 stuff = Stuff(117 aStruct=SomeStruct(anInteger=12,118 aMap={"hi": 1.5}),119 aListOfStruct=[120 SomeStruct(anInteger=10,121 aMap={"good": 2.0}),122 SomeStruct(anInteger=11,123 aMap={"bye": 1.0})],124 anotherString="Hey"125 )126 j = writeToJSON(stuff)127 stuff_read = readStuffFromJSON(j)128 self.assertEqual(len(stuff_read.aListOfStruct), 2)129 self.assertEqual(stuff_read.aListOfStruct[0].anInteger, 10)130 self.assertEqual(stuff_read.aListOfStruct[0].aMap["good"], 2.0)131 self.assertEqual(stuff_read.aListOfStruct[1].anInteger, 11)132 self.assertEqual(stuff_read.aListOfStruct[1].aMap["bye"], 1.0)133 self.assertEqual(stuff_read.anotherString, "Hey")134 def test_deserializer(self):135 j = '{"aShort": 1, "anInteger": 2, "aLong": 3}'136 stuff = Stuff()137 Serializer.deserialize(138 TSimpleJSONProtocol.TSimpleJSONProtocolFactory(), j, stuff)139 self.assertEqual(stuff.aShort, 1)140 self.assertEqual(stuff.anInteger, 2)141 self.assertEqual(stuff.aLong, 3)142 def test_foreign_json(self):143 """144 Not all JSON that we decode will be encoded by this python thrift145 protocol implementation. E.g. this encode implementation stuffs raw146 unicode into the output, but we may use this implementation to decode147 JSON from other implementations, which escape unicode (sometimes148 incorrectly e.g. PHP). And we may use this implementation to decode149 JSON that was not encoded by thrift at all, which may contain nulls.150 """151 s = "a fancy e looks like \u00e9"152 j = '{"aString": "a fancy e looks like \\u00e9", "anotherString": null, "anInteger": 10, "unknownField": null}'153 stuff = Stuff()154 Serializer.deserialize(155 TSimpleJSONProtocol.TSimpleJSONProtocolFactory(), j, stuff)156 self.assertEqual(stuff.aString, s)157 def should_throw():158 j = '{"aString": "foo", "anotherString": nullcorrupt}'159 stuff = Stuff()160 Serializer.deserialize(161 TSimpleJSONProtocol.TSimpleJSONProtocolFactory(), j, stuff)162 self.assertRaises(TProtocol.TProtocolException, should_throw)163if __name__ == '__main__':...

Full Screen

Full Screen

test_integration.py

Source:test_integration.py Github

copy

Full Screen

1import responses2from django.core.urlresolvers import reverse3from sentry.models import Integration4from sentry.testutils import APITestCase5from six.moves.urllib.parse import quote6class BitbucketIntegrationTest(APITestCase):7 def setUp(self):8 self.base_url = "https://api.bitbucket.org"9 self.shared_secret = "234567890"10 self.subject = "connect:1234567"11 self.integration = Integration.objects.create(12 provider="bitbucket",13 external_id=self.subject,14 name="sentryuser",15 metadata={16 "base_url": self.base_url,17 "shared_secret": self.shared_secret,18 "subject": self.subject,19 },20 )21 self.login_as(self.user)22 self.integration.add_organization(self.organization, self.user)23 self.path = reverse(24 "sentry-extensions-bitbucket-search", args=[self.organization.slug, self.integration.id]25 )26 @responses.activate27 def test_get_repositories_with_uuid(self):28 uuid = "{a21bd75c-0ce2-402d-b70b-e57de6fba4b3}"29 self.integration.metadata["uuid"] = uuid30 url = "https://api.bitbucket.org/2.0/repositories/{}".format(quote(uuid))31 responses.add(32 responses.GET,33 url,34 json={"values": [{"full_name": "sentryuser/stuf"}]},35 )36 installation = self.integration.get_installation(self.organization)37 result = installation.get_repositories()38 assert result == [{"identifier": "sentryuser/stuf", "name": "sentryuser/stuf"}]39 @responses.activate40 def test_get_repositories_exact_match(self):41 responses.add(42 responses.GET,43 "https://api.bitbucket.org/2.0/repositories/sentryuser?name=stuf",44 json={"values": [{"full_name": "sentryuser/stuf"}]},45 )46 responses.add(47 responses.GET,48 "https://api.bitbucket.org/2.0/repositories/sentryuser?name~stuf",49 json={50 "values": [51 {"full_name": "sentryuser/stuff"},52 {"full_name": "sentryuser/stuff-2010"},53 {"full_name": "sentryuser/stuff-2011"},54 {"full_name": "sentryuser/stuff-2012"},55 {"full_name": "sentryuser/stuff-2013"},56 {"full_name": "sentryuser/stuff-2014"},57 {"full_name": "sentryuser/stuff-2015"},58 {"full_name": "sentryuser/stuff-2016"},59 {"full_name": "sentryuser/stuff-2016"},60 {"full_name": "sentryuser/stuff-2017"},61 {"full_name": "sentryuser/stuff-2018"},62 {"full_name": "sentryuser/stuff-2019"},63 ]64 },65 )66 installation = self.integration.get_installation(self.organization)67 result = installation.get_repositories("stuf")68 assert result == [69 {"identifier": "sentryuser/stuf", "name": "sentryuser/stuf"},70 {"identifier": "sentryuser/stuff", "name": "sentryuser/stuff"},71 {"identifier": "sentryuser/stuff-2010", "name": "sentryuser/stuff-2010"},72 {"identifier": "sentryuser/stuff-2011", "name": "sentryuser/stuff-2011"},73 {"identifier": "sentryuser/stuff-2012", "name": "sentryuser/stuff-2012"},74 {"identifier": "sentryuser/stuff-2013", "name": "sentryuser/stuff-2013"},75 {"identifier": "sentryuser/stuff-2014", "name": "sentryuser/stuff-2014"},76 {"identifier": "sentryuser/stuff-2015", "name": "sentryuser/stuff-2015"},77 {"identifier": "sentryuser/stuff-2016", "name": "sentryuser/stuff-2016"},78 {"identifier": "sentryuser/stuff-2017", "name": "sentryuser/stuff-2017"},79 {"identifier": "sentryuser/stuff-2018", "name": "sentryuser/stuff-2018"},80 {"identifier": "sentryuser/stuff-2019", "name": "sentryuser/stuff-2019"},81 ]82 @responses.activate83 def test_get_repositories_no_exact_match(self):84 responses.add(85 responses.GET,86 "https://api.bitbucket.org/2.0/repositories/sentryuser?name~stuf",87 json={88 "values": [89 {"full_name": "sentryuser/stuff"},90 {"full_name": "sentryuser/stuff-2010"},91 {"full_name": "sentryuser/stuff-2011"},92 {"full_name": "sentryuser/stuff-2012"},93 {"full_name": "sentryuser/stuff-2013"},94 {"full_name": "sentryuser/stuff-2014"},95 {"full_name": "sentryuser/stuff-2015"},96 {"full_name": "sentryuser/stuff-2016"},97 {"full_name": "sentryuser/stuff-2016"},98 {"full_name": "sentryuser/stuff-2017"},99 {"full_name": "sentryuser/stuff-2018"},100 {"full_name": "sentryuser/stuff-2019"},101 ]102 },103 )104 responses.add(105 responses.GET,106 "https://api.bitbucket.org/2.0/repositories/sentryuser?name=stuf",107 json={"values": []},108 )109 installation = self.integration.get_installation(self.organization)110 result = installation.get_repositories("stu")111 assert result == [112 {"identifier": "sentryuser/stuff", "name": "sentryuser/stuff"},113 {"identifier": "sentryuser/stuff-2010", "name": "sentryuser/stuff-2010"},114 {"identifier": "sentryuser/stuff-2011", "name": "sentryuser/stuff-2011"},115 {"identifier": "sentryuser/stuff-2012", "name": "sentryuser/stuff-2012"},116 {"identifier": "sentryuser/stuff-2013", "name": "sentryuser/stuff-2013"},117 {"identifier": "sentryuser/stuff-2014", "name": "sentryuser/stuff-2014"},118 {"identifier": "sentryuser/stuff-2015", "name": "sentryuser/stuff-2015"},119 {"identifier": "sentryuser/stuff-2016", "name": "sentryuser/stuff-2016"},120 {"identifier": "sentryuser/stuff-2017", "name": "sentryuser/stuff-2017"},121 {"identifier": "sentryuser/stuff-2018", "name": "sentryuser/stuff-2018"},122 {"identifier": "sentryuser/stuff-2019", "name": "sentryuser/stuff-2019"},...

Full Screen

Full Screen

Weather.py

Source:Weather.py Github

copy

Full Screen

1# -*- coding: cp1252 -*-2import urllib,xml.sax.handler3# S10 COMPATIABLE4def message(data):5 if data["type"] == "PRIVMSG":6 try:7 splitdata = data["content"].lower().split(" ")8 if splitdata[0] == ":weather" and len(splitdata) > 1:9 data = Weather(" ".join(splitdata[1:]))10 11 data["conn"].privmsg(data["target"],"Weather for "+data[1]+": "+data[0])12 return True13 except KeyError:14 print "WUT"15 else:16 return -117def Weather(question):18 question = question.replace("ä","a")19 url = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query="+question20 opener = urllib.FancyURLopener({})21 f = opener.open(url)22 data = f.read()23 f.close()24 bufferi = []25 seen = False26 for i in data.split("\n"):27 if "<temperature_string>" in i:28 stuff = cutter(i,"<temperature_string>")29 if len(stuff) > 7:30 bufferi.append("Temperature: "+stuff)31 elif "<observation_time>" in i:32 stuff = cutter(i,"<observation_time>")33 if len(stuff) > 19:34 bufferi.append(stuff)35 elif "<weather>" in i:36 stuff = cutter(i,"<weather>")37 if len(stuff) > 0:38 bufferi.append("Weather: "+stuff)39 elif "<relative_humidity>" in i:40 stuff = cutter(i,"<relative_humidity>")41 if len(stuff) > 0:42 bufferi.append("Humidity: "+stuff)43 elif "<wind_string>" in i:44 stuff = cutter(i,"<wind_string>")45 if len(stuff) > 0:46 bufferi.append("Wind blows "+stuff)47 elif "<pressure_string>" in i:48 stuff = cutter(i,"<pressure_string>")49 if len(stuff) > 9:50 bufferi.append("Air pressure is "+stuff)51 elif "<full>" in i and seen == False:52 seen = True53 where = cutter(i,"<full>")54 if len(where) == 4:55 where = "Location doesn't exist"56 return [", ".join(bufferi),where]57def cutter(fullstring,cut):58 fullstring = fullstring.replace(cut,"")59 fullstring = fullstring.replace("</"+cut[1:],"")60 fullstring = fullstring.replace("\t","") ...

Full Screen

Full Screen

dictionaries.py

Source:dictionaries.py Github

copy

Full Screen

1my_stuff = {"key1":"value","key2":"value2"}2print(my_stuff)3my_stuff = {"key1":"value","key2":"value2"}4print(my_stuff["key2"])5my_stuff = {"key1":123,"key2":"value2","key3":{"123":[1,2,3]}}6print(my_stuff)7my_stuff = {"key1":123,"key2":"value2","key3":{"123":[1,2,'grabMe']}}8print(my_stuff["key3"]["123"][2])9my_stuff = {"key1":123,"key2":"value2","key3":{"123":[1,2,'grabMe']}}10print(my_stuff["key3"]["123"][2].upper())11my_stuff = {"lunch":"pizza","breakfast":"eggs"}12print(my_stuff)13my_stuff = {"lunch":"pizza","breakfast":"eggs"}14print(my_stuff["lunch"])15my_stuff = {"lunch":"pizza","breakfast":"eggs"}16my_stuff["lunch"] = "burger"17print(my_stuff["lunch"])18print(my_stuff)19my_stuff = {"lunch":"pizza","breakfast":"eggs"}20my_stuff["lunch"] = "burger"21my_stuff["dinner"] = "chowmein"22print(my_stuff)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful