How to use consumable_iterator method in Ddt

Best Python code snippet using ddt_python

main.py

Source:main.py Github

copy

Full Screen

1import json2import csv3from rauth import OAuth2Service45BASE_URL = "https://classic.warcraftlogs.com"6TOKEN_URL = f"{BASE_URL}/oauth/token"7API_URL = f"{BASE_URL}/api/v2/client"8910def main():1112 # set true for test mode13 test_mode = False1415 oauth_file = open("../auth/oauth2_client_info.json")16 oauth_info = json.load(oauth_file)1718 CLIENT_ID = oauth_info["client_id"]19 CLIENT_SECRET = oauth_info["client_secret"]2021 warcraftlogs = OAuth2Service(22 client_id=CLIENT_ID,23 client_secret=CLIENT_SECRET,24 name="warcraftlogs",25 access_token_url=TOKEN_URL,26 base_url=API_URL27 )2829 data = {"grant_type": "client_credentials"}3031 session = warcraftlogs.get_auth_session(data=data, decoder=json.loads)3233 # guild ID or report ID are necessary to specify a certain log34 guild_id = ""35 report_id = ""3637 # create menu38 # if I want to automatically get the most recent log, let me do that, otherwise, let me throw in custom information39 custom_selector = False40 while custom_selector is False:41 custom_report = input("Would you like an automatic report for the most recent log? (y/n) ")4243 if custom_report == "y":44 guild_id = str(input("Guild ID (visible in your guild's wcl url, e.g. warcraftlogs.com/guild/id/######): "))45 custom_selector = True46 elif custom_report == "n":47 report_id = str(input("Report ID (visible on your wcl report url, e.g. warcraftlogs.com/reports/################): "))48 custom_selector = True49 elif custom_report == 0:50 exit(0)51 else:52 print("Invalid response. Try again, or enter 0 to exit.")5354 # if user wants an automatic report, we need to get the report for them55 if report_id == "":56 # query returns the N=1 most recent report for the guild_id57 query = """query {58 reportData {59 reports(guildID: %s, limit: 1) {60 data {61 code62 endTime63 }64 }65 }66 }67 """ % guild_id68 # store the api response69 response = session.post(API_URL, json={'query': query})70 # parse the response71 response_object = json.loads(response.text)72 # then grab the report id from it73 report_id = str(response_object["data"]["reportData"]["reports"]["data"][0]["code"])74 # test to make sure we're getting the right ID75 if test_mode is True:76 print(report_id)77 print(type(report_id))7879 # now that we have the report, we need to look at the fights within80 # this query returns all fight IDs81 query = """query {82 reportData {83 report(code: "%s") {84 fights {85 id,86 startTime,87 endTime88 }89 }90 }91 }92 """ % report_id93 # store the api response94 response = session.post(API_URL, json={'query': query})95 # parse the response96 fight_ids = json.loads(response.text)97 # test the parse was successful98 if test_mode is True:99 print(fight_ids)100101 # we also need the player IDs102 # this query returns all the player actors found in the report103 query = """query {104 reportData {105 report(code: "%s") {106 masterData{107 actors(type: "player"){108 name,109 id110 }111 }112 }113 }114 }115 """ % report_id116 # store the api response117 response = session.post(API_URL, json={'query': query})118 # parse the response119 player_ids = json.loads(response.text)120121 # now, we will need to add up all of the time within the raid that was spent in an encounter122 # to do that, we want to iterate through each fight and add up the difference between their endTime and startTime123 combat_time = 0124 fight_iterator = 0125 # we will add a sneaky endTime grabber here for later, as knowing when the raid ends will be important126 raid_end = 0127 for i in fight_ids["data"]["reportData"]["report"]["fights"]:128 start_time = int(fight_ids["data"]["reportData"]["report"]["fights"][fight_iterator]["startTime"])129 end_time = int(fight_ids["data"]["reportData"]["report"]["fights"][fight_iterator]["endTime"])130 raid_end = end_time131 fight_time = end_time - start_time132 combat_time += fight_time133 fight_iterator += 1134 # test to see if this is adding up time135 if test_mode is True:136 print(combat_time)137138 # now that we have most of the API information we need, we need to consider which buffs we care about139 # we will open a csv file containing the buffs we care about and their information140 buff_file = open("../consumables/consumables.csv", 'r', encoding='utf-8')141 # first we load the csv142 reader = csv.DictReader(buff_file)143 # then write these to an json object, row by row144 buffs = []145 for row in reader:146 buffs.append(row)147 # now dump these into json format148 buffs = json.loads(json.dumps(buffs))149 # test buffs to make sure it looks like the json object we're expecting150 if test_mode is True:151 print(buffs)152153 # now we just need to check our players buffs against the buffs we care about154 # before we do that, we need a dictionary to hold buff information155 # auras = [{"auraName", "guid", "totalUptime", "activeFlag", "consumableName", "consumableID"}]156 auras = [{}]157 # since we want a nice square table at the end, we can prefill a lot of this information, knowing some will have 0 uptime158 auras_iterator = 0159 for i in buffs:160 temp_info = {"auraName": buffs[auras_iterator]["spell_name"],161 "guid": buffs[auras_iterator]["spell_id"],162 "consumableName": buffs[auras_iterator]["consumable_name"],163 "consumableID": buffs[auras_iterator]["item_id"],164 "totalUptime": 0,165 "activeFlag": False}166 auras.append(temp_info)167168 # the following is commented out for posterity, this was an alternative way to achieve the same effect -I BELIEVE-169 # auras[auras_iterator]["auraName"] = buffs[auras_iterator]["spell_name"]170 # auras[auras_iterator]["guid"] = buffs[auras_iterator]["spell_id"]171 # auras[auras_iterator]["consumableName"] = buffs[auras_iterator]["consumable_name"]172 # auras[auras_iterator]["consumableID"] = buffs[auras_iterator]["item_id"]173 # auras[auras_iterator]["totalUptime"] = 0174 # auras[auras_iterator]["activeFlag"] = False175176 auras_iterator += 1177 # the list has no initial values, so the first element is empty, pop it off178 auras.pop(0)179180 # test print auras to make sure it looks right181 if test_mode is True:182 temp_iterator = 0183 for i in auras:184 print(auras[temp_iterator]["guid"])185 temp_iterator += 1186187 # now that's settled, we also need a dictionary to identify players, where we will nest auras188 players = [{}]189190 # now, we should populate it for each player191 # we need a variable to iterate through each player and each fight192 player_iterator = 0193 for i in player_ids["data"]["reportData"]["report"]["masterData"]["actors"]:194 # for each player, we need to query the api to find their buffs195 # to do that, we need their unique player ID, we'll store their name as well196 player_name = player_ids["data"]["reportData"]["report"]["masterData"]["actors"][player_iterator]["name"]197 player_id = player_ids["data"]["reportData"]["report"]["masterData"]["actors"][player_iterator]["id"]198 # test this player's name and id199 if test_mode is True:200 print(player_name)201 print(player_id)202 # this query reports all buffs for a given target, within a given time frame, from a given report203 query = """query {204 reportData {205 report(code: "%s") {206 table(dataType: Buffs, startTime: 0, endTime: %s, targetID: %s) 207 }208 }209 }210 """ % (report_id, raid_end, player_id)211 # store the api response212 response = session.post(API_URL, json={'query': query})213 # test the response214 if test_mode is True:215 print(response.text)216 # parse the response217 player_buff_info = json.loads(response.text)218 # parse that down to auras219 player_auras = player_buff_info["data"]["reportData"]["report"]["table"]["data"]["auras"]220 # test print this player's auras221 if test_mode is True:222 temp_iterator = 0223 for i in player_auras:224 print(player_auras[temp_iterator])225 temp_iterator += 1226227 # now that we have all the buff info, we need to look only at the uptime for auras we're interested in228 buff_iterator = 0229 for i in auras:230 # we don't want to write any erroneous data, so let's set totalUptime back to 0 and activeFlag back to false for each iteration231 auras[buff_iterator]["totalUptime"] = 0232 auras[buff_iterator]["activeFlag"] = False233234 # we want to search our player's auras (from the log) for the auras we care about, so grab that spell id to search against235 search_aura = int(auras[buff_iterator]["guid"])236 # test search aura to make sure we're searching for something237 if test_mode is True:238 print(search_aura)239 # test to make sure I'm not sending any false true flags240 if test_mode is True:241 print(bool(list(filter(lambda x: x["guid"] == search_aura, player_auras))))242243 if list(filter(lambda x: x["guid"] == search_aura, player_auras)):244 auras[buff_iterator]["totalUptime"] = float(list(filter(lambda x: x["guid"] == search_aura, player_auras))[0]["totalUptime"])/float(combat_time)245 auras[buff_iterator]["activeFlag"] = True246 buff_iterator += 1247248 # now that we've updated all the relevant information in auras, we can toss that into our player dictionary249 # first, we want to write that list into a json object250 auras_json = json.loads(json.dumps(auras))251 # then we need a temp list to hold our information252 player_info = {"name": player_name, "id": player_id, "auras": auras_json}253 # then we need to append that onto our player list254 players.append(player_info)255 player_iterator += 1256257 # now that we've iterated through all of our players, we should have all the relevant information in a dictionary258 # given the same method of populating players as auras, we need to pop the first, empty players element259 players.pop(0)260 # then, we should write that list into a json object261 players = json.loads(json.dumps(players))262263 # test print players to be sure we're getting accurate data264 if test_mode is True:265 temp_iterator = 0266 for i in players:267 print(players[temp_iterator])268 temp_iterator += 1269270 # printing players will print in json format271 chosen = False272 while chosen is not True:273 print_choice = input("In what format would you like this printed? (json or csv) ")274 if print_choice == "json":275 # players is already a json object, simply print it276 print(players)277 # we can also dump it to a json file278 json_file = open("../consumables/consumable_uptime_json.json", "w", encoding="utf-8")279 json.dump(players, json_file, ensure_ascii=False, indent=4)280 json_file.close()281 # chosen = True282 elif print_choice == "csv":283 # since we have nested json objects, we want to print only the data we need284 # player name, and consumable names will be the headers, first column will be player names, the rest will be uptimes285 players_csv = []286 # initiate the header string287 # interate through auras to create a list of consumable names288 header_array = ["Player Name"]289 temp_iterator = 0290 for i in players[0]["auras"]:291 header_array.append(players[0]["auras"][temp_iterator]["consumableName"])292 temp_iterator += 1293 # combine that array into one csv string294 temp_header = ",".join(header_array)295 # then append it to the total csv296 players_csv.append(temp_header)297298 #now, we can loop through all players299 player_iterator = 0300 for i in players:301 entry_array = []302 entry_array.append(players[player_iterator]["name"])303 # now, loop through their consumables304 consumable_iterator = 0305 for j in players[player_iterator]["auras"]:306 # and append their consumable uptime (consumables are always in the same order, no need to check307 entry_array.append(str(players[player_iterator]["auras"][consumable_iterator]["totalUptime"]))308 consumable_iterator += 1309 # now that we have their name and all consumable uptime, join that into one string310 temp_consumables = ",".join(entry_array)311 # then append it to the total csv312 players_csv.append(temp_consumables)313 player_iterator += 1314315 # all players and their consumable uptimes should now be present for printing316 # we will also create/overwrite an existing consumable uptime file at the same time317 csv_file = open("../consumables/consumable_uptime_csv.csv", "w", encoding="utf-8")318 print_iterator = 0319 for i in players_csv:320 print(players_csv[print_iterator])321 csv_file.write(players_csv[print_iterator] + '\n')322 print_iterator += 1323 csv_file.close()324 print("This data was also written to ../consumables/consumable_uptime.csv")325 # chosen = True326 elif print_choice == "0":327 exit(0)328 else:329 print("Invalid selection. Try again, or enter 0 to exit.")330331332 ...

Full Screen

Full Screen

test_functional.py

Source:test_functional.py Github

copy

Full Screen

...186 expected_tests = [187 "test_something_{:02d}_{}".format(i + 1, v) for i, v in enumerate(payload)188 ]189 assert sorted(tests) == sorted(expected_tests)190def test_idata_consumable_iterator():191 """192 Test that using ``idata`` with a consumable iterator still generates the193 expected tests.194 """195 payload = [51, 78, 2]196 def consumable_iterator():197 # Not using `yield from` for Python 2.7.198 for i in payload:199 yield i200 @ddt201 class Dummy(object):202 @idata(consumable_iterator())203 def test_something(self, value):204 return value205 tests = list(filter(_is_test, Dummy.__dict__))206 expected_tests = [207 "test_something_{:1d}_{}".format(i + 1, v) for i, v in enumerate(payload)208 ]209 assert sorted(tests) == sorted(expected_tests)210def test_file_data_test_creation():211 """212 Test that the ``file_data`` decorator creates two tests213 """214 tests = len(list(filter(_is_test, FileDataDummy.__dict__)))215 assert tests == 2216def test_file_data_test_names_dict():...

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 Ddt 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