Added RPMCallback test, and fixed some issues in YumGuiRPMCallback
[yumguicore.git] / tests / __init__.py
blob01233628eac2b58abb1c2b1f00b97dde490b69fe
1 import time
2 import rpm
3 from yumguicore.gui import doGtkEvents
4 from yum.constants import *
6 def testProgress(progress):
7 '''
8 test function for the Progress class
9 @param progress: instance of the Progress class to test
10 '''
11 progress.set_markup('<b>Testing the Progress class</b>')
12 for x in range(1001):
13 frac = float(x)/1000.0
14 percent = int(float(x)/999.0*100)
15 progress.set_pbar_text('%i %%' % percent)
16 progress.set_fraction(frac)
17 time.sleep(.05)
18 progress.reset()
20 def testTextViewConsole(console):
21 '''
22 Test function for the TextViewConsole class
23 @param console: instance of the TextViewConsole class
24 '''
25 console.write_line('Testing TextViewConsole class\n')
26 txt = 'Line of text (default style)\n' * 5
27 console.write_line(txt)
28 txt = 'Line of text (style_err)\n' * 5
29 console.write_line(txt,console.style_err)
30 doGtkEvents()
33 def testRPMCallback(callback):
34 ''' test the YumGuiRPMCallback class '''
35 class fakeTxMember:
36 ''' Simulate txmbr '''
37 def __init__(self):
38 self.output_state = TS_INSTALL
40 class fakeTsInfo:
41 ''' Simulate tsInfo '''
42 def __init__(self):
43 pass
45 def getMembers(self,pkgtup):
46 return [fakeTxMember()]
48 def fakeRPMHeader(tup):
49 ''' Generate a dictinary to simulate an rpm header '''
50 hdr = {}
51 hdr['name'], hdr['arch'], hdr['epoch'], hdr['version'], hdr['release'] = tup
52 return hdr
54 files = [(('foo','i386','0','1.0','1.fc7'),100000),
55 (('foo1','noarch','1','1.1','4.fc7'),200000),
56 (('foo2','i386','0','2.0','5.fc7'),300000),
57 (('foo3','i386','0','3.0','7.fc7'),400000)]
58 tsInfo = fakeTsInfo()
59 callback.tsInfo = tsInfo
60 what = rpm.RPMCALLBACK_TRANS_START
61 callback.callback(what,6,len(files),None,None)
62 for tup,size in files:
63 cursize = 0
64 hdr = fakeRPMHeader(tup)
65 rpmloc = '%s-%s-%s.%s.rpm' % (hdr['name'], hdr['version'], hdr['release'],hdr['arch'])
66 h = (hdr,rpmloc)
67 what = rpm.RPMCALLBACK_INST_PROGRESS
68 while cursize < size:
69 cursize += 100
70 callback.callback(what,cursize,size,h,None)
71 what = rpm.RPMCALLBACK_TRANS_STOP
72 callback.callback(what,None,None,None,None)
73 callback.progress.reset()
76 if __name__ == "__main__":
77 pass