Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- postgresql
- kitura
- appium server
- STF_PortForwarding
- rethinkdb
- sshpass
- ftp
- mysql
- ssh
- nohup
- PYTHON
- perfect
- postgres
- centos
- GoCD
- nGrinder
- Materials
- SWIFT
- openpyxl
- create table
- 28015
- nmap
- Jupyter
- port forwarding
- Jupyter Notebook
- appium
- 실행권한
- STF
- insert
- ubuntu
Archives
- Today
- Total
don't stop believing
hecate 실습 (geth) 2 본문
terminal based application (cli tool) 테스트에 사용하려고 templit을 만들어 봤습니다.
참고해서 사용하면 좋을 것 같습니다.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127# coding=utf-8import hecate.runner as rfrom hecate.hecate import Runner, AbnormalExitimport sys, osimport time, datetimeimport signalimport unittestRunner.print_on_exit = Falseclass TestUtils():def getDateStrings(self):# 날짜를 확인하기 위해 여러 형태로 날자 데이터를 불러옵니다.i = datetime.datetime.now()dt = datetime.datetime(i.year, i.month, i.day, i.hour, i.minute, i.second)ts = time.mktime(dt.timetuple())# 날짜 데이터를 이용해 로그파일 이름을 지정합니다.logFileName = datetime.datetime.fromtimestamp(int(ts)).strftime('%Y%m%d%H%M%S') + ".log"return (logFileName)def getAppearByEnding(self, first):# list에서 모든 공백을 제거하고 가장 마지막에서 찾습니다.f = list(filter(None, first.splitlines()))c = len(f) - 1if f[c] == ">": del f[-1]return f[-1]def getAppearByReverse(self, first, command):# list의 순서를 역순으로 변경하고 index로 찾습니다.screenReverseArray = first.splitlines()[::-1]searchindex = screenReverseArray.index("> " + command)return (searchindex, screenReverseArray[searchindex - 1])def writeLog(self, logFileName, searchIndex, writeData):# 로그 파일에 Testing 시작을 기록합니다.with open(logFileName, 'at') as f:if writeData == "Start":data = "------------ Testing Start -------------" + "\n"elif writeData == "Finish":data = "------------ Testing Finish ------------" + "\n"else:data = "[IDX:" + str(searchIndex) + "][" + str(datetime.datetime.now()) + "] " + writeDataprint(data)f.write(data)class TestingGeth(unittest.TestCase):def test_geth(self):t = TestUtils()rows, columns = os.popen('stty size', 'r').read().split()logFileName = t.getDateStrings()testingLines = 1000avgSleepTime = 0.5t.writeLog(logFileName, testingLines, 'Start')with Runner( "/usr/local/bin/geth","--networkid" ,"45","--nodiscover","--maxpeers", "0","--datadir", "/Users/tongchunkim/Documents/Test_Ethereum/data_testnet","console","2>>", "/Users/tongchunkim/Documents/Test_Ethereum/data_testnet/geth.log",width=columns, height=testingLines) as h:h.await_text("Welcome to the Geth JavaScript console!", 5)# 로그파일 확인을 위해 같은 테스트를 10번 반복합니다.for i in range(0, 10):# coinbase를 확인합니다.command = "eth.coinbase"h.write(command)h.press("Enter")time.sleep(avgSleepTime)searchindex, value = t.getAppearByReverse(h.screenshot(), command)data = command + ": " + valuet.writeLog(logFileName, searchindex, data)# 명령에 대한 결과값을 assert 명령으로 처리할 수 있습니다.self.assertEqual(value, '"0x78ce083531ff41d26c7002efcf4eec1fd11deaa0"')# blockNumber를 확인합니다.command = "eth.blockNumber"h.write(command)h.press("Enter")time.sleep(avgSleepTime)searchindex, value = t.getAppearByReverse(h.screenshot(), command)data = command + ": " + valuet.writeLog(logFileName, searchindex, data)assert 0 < int(value), "BlockNumber is less then 0."command = "exit"h.write(command)h.press("Enter")searchindex, value = t.getAppearByReverse(h.screenshot(), command)data = command + ": " + valuet.writeLog(logFileName, searchindex, data)h.await_exit()# 테스트를 종료합니다.t.writeLog(logFileName, 0, 'Finish')if __name__== "__main__":unittest.main()
'Python > hecate & tmux' 카테고리의 다른 글
tmux 설치 (on CentOS, Ubuntu) (0) | 2018.10.15 |
---|---|
hecate 실습 (geth) 1 (0) | 2018.09.17 |
hecate python module 설치와 기본 사용 (on Mac) (0) | 2018.09.16 |
Comments