From: <lu...@us...> - 2010-06-09 15:38:03
|
Revision: 474 http://pyscard.svn.sourceforge.net/pyscard/?rev=474&view=rev Author: ludov Date: 2010-06-09 15:37:57 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py 2010-06-09 15:32:12 UTC (rev 473) +++ trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py 2010-06-09 15:37:57 UTC (rev 474) @@ -34,7 +34,7 @@ import unittest # define the apdus used in this script -GET_RESPONSE = [0XA0, 0XC0, 00, 00 ] +GET_RESPONSE = [0XA0, 0XC0, 00, 00] SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] @@ -46,29 +46,33 @@ from smartcard.ExclusiveTransmitCardConnection import ExclusiveTransmitCardConnection from smartcard.util import toHexString -def signalEvent( evt ): + +def signalEvent(evt): '''A simple callback that signals an event.''' evt.set() -class testthread( threading.Thread ): - '''A test thread that repetitevely sends APDUs to a card within a transaction.''' - def __init__(self, threadindex ): + +class testthread(threading.Thread): + '''A test thread that repetitevely sends APDUs to a card within a + transaction.''' + + def __init__(self, threadindex): '''Connect to a card with an ExclusiveTransmitCardConnection.''' threading.Thread.__init__(self) - self.threadindex=threadindex + self.threadindex = threadindex # request any card type cardtype = AnyCardType() - cardrequest = CardRequest( timeout=5, cardType=cardtype ) + cardrequest = CardRequest(timeout=5, cardType=cardtype) cardservice = cardrequest.waitforcard() # attach our decorator - cardservice.connection = ExclusiveTransmitCardConnection( cardservice.connection ) + cardservice.connection = ExclusiveTransmitCardConnection(cardservice.connection) # uncomment to attach the console tracer #observer=ConsoleCardConnectionObserver() - #cardservice.connection.addObserver( observer ) + #cardservice.connection.addObserver(observer) # connect to the card cardservice.connection.connect() @@ -79,11 +83,10 @@ self.evtStop = threading.Event() # this timer will set the event stop event in 30s - timer = threading.Timer( 30, signalEvent, [self.evtStop] ) + timer = threading.Timer(30, signalEvent, [self.evtStop]) timer.start() - self.countTransmitted=0 + self.countTransmitted = 0 - def run(self): '''Transmit APDUS with a random interval to the card.''' connection = self.cardservice.connection @@ -91,16 +94,16 @@ try: connection.lock() - apdu = SELECT+DF_TELECOM - response, sw1, sw2 = connection.transmit( apdu ) + apdu = SELECT + DF_TELECOM + response, sw1, sw2 = connection.transmit(apdu) - if 0x90==(sw1 & 0xF0): + if 0x90 == (sw1 & 0xF0): apdu = GET_RESPONSE + [sw2] - response, sw1, sw2 = connection.transmit( apdu ) + response, sw1, sw2 = connection.transmit(apdu) finally: connection.unlock() - self.countTransmitted=self.countTransmitted+1 - time.sleep( float(random.uniform( 1, 3 ))*0.01) + self.countTransmitted = self.countTransmitted + 1 + time.sleep(float(random.uniform(1, 3)) * 0.01) class testcase_cardmonitor(unittest.TestCase): @@ -108,17 +111,18 @@ def testcase_cardmonitorthread(self): threads = [] - for i in range( 0, 4 ): - t = testthread( i ) - threads.append( t ) + for i in range(0, 4): + t = testthread(i) + threads.append(t) for t in threads: t.start() for t in threads: t.join() for t in threads: - if 0==1: - print 'Thread %d: transmitted %ld apdus.' % (t.threadindex, t.countTransmitted ) + if 0 == 1: + print 'Thread %d: transmitted %ld apdus.' % (t.threadindex, t.countTransmitted) + def suite(): suite1 = unittest.makeSuite(testcase_cardmonitorthread) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py 2010-06-09 15:32:12 UTC (rev 473) +++ trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py 2010-06-09 15:37:57 UTC (rev 474) @@ -32,118 +32,118 @@ from smartcard.scard import resourceManager -if 'winscard'==resourceManager: +if 'winscard' == resourceManager: + class testcase_readergroups(unittest.TestCase): """Test smartcard framework readersgroups.""" - pinpadgroup='Pinpad$Readers' - biogroup='Biometric$Readers' + pinpadgroup = 'Pinpad$Readers' + biogroup = 'Biometric$Readers' def testcase_readergroup_add(self): """tests groups=groups+[newgroups]""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups=groups+[self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups = groups + [self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time and biometric once - groups=groups+[self.biogroup,self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups = groups + [self.biogroup, self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) def testcase_readergroup_iadd(self): """test groups+=[newgroups]""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups+=[self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups += [self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time and biometric once - groups+=[self.biogroup,self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups += [self.biogroup, self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) - def testcase_readergroup_radd(self): """test groups=[newgroups]+groups""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - zgroups=[self.pinpadgroup]+groups - self.assertEquals( groups, groupssnapshot ) - self.assertEquals( zgroups, groupssnapshot+[self.pinpadgroup] ) - self.assert_( isinstance( zgroups, type([]) ) ) - self.assert_( isinstance( groups, type(readergroups()) ) ) + zgroups = [self.pinpadgroup] + groups + self.assertEquals(groups, groupssnapshot) + self.assertEquals(zgroups, groupssnapshot + [self.pinpadgroup]) + self.assert_(isinstance(zgroups, type([]))) + self.assert_(isinstance(groups, type(readergroups()))) # add pinpad a tiwce and biometric once - zgroups=[self.pinpadgroup,self.biogroup,self.pinpadgroup]+groups - self.assertEquals( groups, groupssnapshot ) - self.assertEquals( zgroups, groupssnapshot+[self.pinpadgroup,self.biogroup] ) - self.assert_( isinstance( zgroups, type([]) ) ) - self.assert_( isinstance( groups, type(readergroups()) ) ) + zgroups = [self.pinpadgroup, self.biogroup, self.pinpadgroup] + groups + self.assertEquals(groups, groupssnapshot) + self.assertEquals(zgroups, groupssnapshot + [self.pinpadgroup, self.biogroup]) + self.assert_(isinstance(zgroups, type([]))) + self.assert_(isinstance(groups, type(readergroups()))) def testcase_readergroup_append(self): """test groups.append(newgroups)""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups.append(self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.append(self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time - groups.append(self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.append(self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add biometric once - groups.append( self.biogroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups.append(self.biogroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) def testcase_readergroup_insert(self): """test groups.insert(i,newgroups)""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups.insert(0,self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.insert(0, self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time - groups.insert(1,self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.insert(1, self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add biometric once - groups.insert( 1, self.biogroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups.insert(1, self.biogroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) def suite(): suite1 = unittest.makeSuite(testcase_readergroups) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |