Best Python code snippet using tox_python
test_z_cmdline.py
Source:test_z_cmdline.py
...433 result = cmd()434 result.assert_fail()435 assert result.outlines[-1].startswith("ERROR: python: InvocationError for command ")436@pytest.fixture437def example123(initproj):438 yield initproj(439 "example123-0.5",440 filedefs={441 "tests": {442 "test_hello.py": """443 def test_hello(pytestconfig):444 pass445 """,446 },447 "tox.ini": """448 [testenv]449 changedir=tests450 commands= pytest --basetemp={envtmpdir} \451 --junitxml=junit-{envname}.xml...
getStockInfo.py
Source:getStockInfo.py
1import requests2from bs4 import BeautifulSoup as bs3import json4import sys,os5import time6############################################################################7# ì´ getStockInfo.py를 기ì¤ì¼ë¡ 1ë¨ê³ ìì ëë í 리 ë 벨ì ìì ìë resourceíì¼ì ê°ì ¸ì¤ê¸° ìí´8# import sys, os를 ì¬ì©íê³ , sys.path.append(...)ë¡ ì´ë¥¼ ê°ë¥íê² íë¤.9sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))10# resource íì¼ ë´ì getWonwhaStringì´ë 모ë(*.py)ì ê°ì ¸ì¨ë¤.11from resource.sub_function_used_globally import getWonwhaString12# ë¡ê¹
ì²ë¦¬ í¨ì ë¶ë¬ì¤ê¸°13from resource.sub_function_used_globally.printCommandLog import printCommandLog as printCommandLog14############################################################################15def getStockInfo(fromWho, companyName):16 _START_TIME = time.time()17 if getStockCode(companyName) == 404: # ì¢
목 ìì ìë¬ ì½ë18 return 404 # í¨ì ì¢
ë£19 try:20 companyCode = getStockCode(companyName)21 printCommandLog(fromWho, "show stock --search {} (Function)".format(companyName), "RUNNING", "Getting Stock Information : " + companyName)22 #print("getting information about : " + companyName)23 url = "https://finance.daum.net/api/quote/A" + companyCode + "/sectors"24 response = requests.get(url)25 headers = {26 'Referer' : 'https://finance.daum.net/quotes/A' + companyCode,27 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Whale/2.9.116.15 Safari/537.36'28 }29 response = requests.get(url, headers=headers, timeout=0.9)30 except:31 printCommandLog("show stock --search {} (Function)".format(companyName), "RUNNING", "NO_RESPONSE_RETURNED")32 return 404, 404, 404, 404, 404, 404, 40433 stockData = response.json()34 #print(type(stockData)) # Dictionary íì
35 stockData = list(stockData.values())36 #print(type(stockData))37 # print("ì¢
목ì½ë : " + stockData[0][0].get("symbolCode"))38 # print("ì¢
목ì´ë¦ : " + stockData[0][0].get("name"))39 # print("ì¢
목ê°ê²© : " + str(stockData[0][0].get("tradePrice")).replace('.0','') + " ì")40 # print("ì¢
목ê°ê²© ë³ëë : " + str(stockData[0][0].get("changePrice")) + " ì")41 # print("ì¢
목ê°ê²© ë³ëë¥ : " + str(stockData[0][0].get("changeRate") * 100) + " %")42 # print("ìê°ì´ì¡ : â " + str(stockData[0][0].get("marketCap")).replace('.0','')[:6] + " ìµ ì")43 symbolCode = stockData[0][0].get("symbolCode")[1:] # ì¢
목 ì½ë44 companyName = stockData[0][0].get("name") # ì¢
목 ì´ë¦45 46 tradePrice = str(stockData[0][0].get("tradePrice")).replace('.0','') # ì¢
목 ê°ê²©47 tradePrice = "{:,}".format(int(tradePrice)) + " ì" # 1,000 ë¨ìë§ë¤ ì½¤ë§ ë¶ì´ê¸°, ì ê¸°í¸ 48 changePrice = str(stockData[0][0].get("changePrice")).replace('.0','') # ì¢
목 ê°ê²© ë³ëë49 changePrice = "{:,}".format(int(changePrice)) + " ì" # 1,000 ë¨ìë§ë¤ ì½¤ë§ ë¶ì´ê¸°, ì 기í¸50 changeRate = str(round((stockData[0][0].get("changeRate") * 100),2)) + " %" # ì¢
목 ê°ê²© ë³ëë¥ 51 52 marketCap = str(stockData[0][0].get("marketCap")).replace('.0','') # ìê°ì´ì¡53 marketCap = "â " + getWonwhaString.getWonhwaString(int(marketCap)) + " ì" 54 resultForPrintCommandLog = "RESULT > {} | {} | {} | {} | {} | {}".format(symbolCode, companyName, tradePrice, changePrice, changeRate, marketCap)55 printCommandLog(fromWho, "show stock --search {}(Function)".format(companyName), "RUNNING", resultForPrintCommandLog)56 57 _END_TIME = time.time()58 running_time = round((_END_TIME - _START_TIME), 4)59 printCommandLog(fromWho, "show stock --search {}(Function)".format(companyName), "RUNNING", "running time : " + str(running_time) + " sec/pass")60 #print("running time : ", str(running_time) + " SEC.")61 return symbolCode, companyName, tradePrice, changePrice, changeRate, marketCap, str(running_time)62def getStockCode(companyName):63 file = open('./resource/stock_function_data/stockCodeList.txt','rt', encoding='UTF8')64 65 try:66 while True:67 line = file.readline()68 if companyName == line.split()[0]: #ì íí íì¬ëª
ë§ ê²ì69 code = line.split('\t')[1].strip()70 break71 if not line:72 return 40473 except: # ì ëë¡ ì
ë ¥íì§ ìì ìì¸ê° ì기면 모ë 404 ìë¬ì²ë¦¬74 return 40475 file.close()76 return code77# print(getStockInfo("fromWhoExample123", "ì¼ì±ì ì"))78# print(getStockInfo("fromWhoExample123", "LG"))79# print(getStockInfo("fromWhoExample123", "CJëííµì´"))80# print(getStockInfo("fromWhoExample123", "ì¹´ì¹´ì¤"))81# print(getStockInfo("fromWhoExample123", "BGF리í
ì¼"))82# print(getStockInfo("fromWhoExample123", "CJì ì¼ì ë¹"))83# print(getStockInfo("fromWhoExample123", "ëííê³µ"))84# print(getStockInfo("fromWhoExample123", "롯ë°ì ê³¼"))85# print(getStockInfo("fromWhoExample123", "ì´í¸ë¡ "))86# print(getStockInfo("fromWhoExample123", "ì¨ì "))87# print(getStockInfo("fromWhoExample123", "ì모ë í¼ìí½"))88# print(getStockInfo("fromWhoExample123", "ìì¨ìíí¸"))89# print(getStockInfo("fromWhoExample123", "íêµì ë ¥"))90# print(getStockInfo("fromWhoExample123", "ì¼ì±ìëª
"))91# print(getStockInfo("fromWhoExample123", "KT"))92# print(getStockInfo("fromWhoExample123", "ë·ë§ë¸"))...
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!!