python.or.kr에 제 블로그가
링크된 기념(...)
파이썬 자동 테스트는 확인해보면 사실 간단한 코드져. 일정시간동안 슬립하면서 변경된 파일이 있다면, 단위 테스트를 다시 돌리는 프로그램입니다.
예전 포스팅에서는 snarl을 이용해서 윈도에서 notify를 했었는데요. 지금은 리눅스에서 /usr/local/bin에 넣어놓고,
pynotify를 이용하고 있습니다.
#!/usr/bin/env python
import glob,os,stat,time,string,sys
class NoneNotifyViewer:
def __init__(self):
pass
def setNotification(self, topic, msg, staus, timeout):
pass
class GtkNotifyViewer:
def __init__(self):
import pygtk
pygtk.require('2.0')
import pynotify, gtk
if not pynotify.init("autotest"):
print "python-notify init error"
exit(1)
def setNotification(self, topic, msg, status, timeout):
import pynotify
n = pynotify.Notification(topic, msg, self.__getStatusImage(status))
n.set_timeout(timeout)
if not n.show():
print "Fail notify error"
sys.exit(1)
def __getStatusImage(self, status):
iconPath = 'file:///usr/local/share/icons/test_icons/'
if (status == 'fail'): return iconPath + 'fail.png'
elif (status == 'success'): return iconPath + 'success.png'
else: return iconPath + 'info.png'
class NoseNotify:
@staticmethod
def __getNotifyViewer():
return NoseNotify.__viewer
@staticmethod
def notify(topic, msg, status, timeout):
n = NoseNotify.__getNotifyViewer()
n.setNotification(topic, msg, status, timeout)
@staticmethod
def setNotifyViewer(viewer):
NoseNotify.__viewer = viewer
#init
__viewer = NoneNotifyViewer()
class AutoTest:
def __init__(self):
self.val = 0
def checkSum(self):
return self.__getCheckSum('.py') + self.__getCheckSum('.kid')
def __getCheckSum(self, fileType):
val = 0
for dirpath, dirs, files in os.walk("."):
for file in [file for file in files if file[-1 * len(fileType):] == fileType]:
f = os.path.join(dirpath, file)
stats = os.stat(f)
val += stats[stat.ST_SIZE] + stats[stat.ST_MTIME]
return val
def run(self):
while (True):
checkSum = self.checkSum()
if checkSum != self.val:
self.val = checkSum
# test run
result = os.popen3('/usr/bin/nosetests')[-1]
msg = result.readlines()
isPass = (msg[-1] == 'OK\n')
print string.join(msg, "")
r = "Test Success" if isPass else "Test Fail"
i = 'success' if isPass else 'fail'
notice_msg(r, string.join(msg[-3:]), i)
try:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
notice_msg("autotest", 'autotest was end', 'info')
sys.exit(0)
def notice_msg(title, msg, status='info', timeout=3000):
NoseNotify.notify(title, msg, status, timeout)
if __name__ == '__main__':
NoseNotify.setNotifyViewer(GtkNotifyViewer())
autoTest = AutoTest()
notice_msg("autotest", 'autotest was started')
autoTest.run()
# vim: ft=python ts=4 sw=4 et syn=on
아이콘 이미지는 어디선가 구해서(저도 어딘지 잘..) file:///usr/local/share/icons/test_icons/ 에 넣어놨구요
그냥 마구 야매인 코드라 보기엔 좀 힘드시지 않으실지;;;
뭐 저도 아무렇게나 짠거라(............)
동영상은 테스트 삼아 찍어봤는데 어딜 올려도 화질이 별로 안좋네요 그냥 올려봅니다(...)
나중에 생각나면 서버에 원본을 올리던지 그런식으로(.........)
유튜브에 올렸습니다. 그냥 사용동영상이니..;;