don't stop believing

hecate 실습 (geth) 2 본문

Python/hecate & tmux

hecate 실습 (geth) 2

Tongchun 2018. 9. 20. 19:31

terminal based application (cli tool) 테스트에 사용하려고 templit을 만들어 봤습니다.


참고해서 사용하면 좋을 것 같습니다.


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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# coding=utf-8
import hecate.runner as r
from hecate.hecate import Runner, AbnormalExit
import sys, os
import time, datetime
import signal
import unittest
Runner.print_on_exit = False
class 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) - 1
if 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()) + "] " + writeData
print(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 = 1000
avgSleepTime = 0.5
t.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 + ": " + value
t.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 + ": " + value
t.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 + ": " + value
t.writeLog(logFileName, searchindex, data)
h.await_exit()
# .
t.writeLog(logFileName, 0, 'Finish')
if __name__== "__main__":
unittest.main()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


'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