Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78310

Re: Syntax error in python unittest script

Newsgroups comp.lang.python
Date 2014-09-24 13:06 -0700
References <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com>
Message-ID <7807b4fc-fde2-41ea-a1d8-23bb93a50b8c@googlegroups.com> (permalink)
Subject Re: Syntax error in python unittest script
From Milson Munakami <milsonmun@gmail.com>

Show all headers | View raw


On Wednesday, September 24, 2014 1:33:35 PM UTC-6, Milson Munakami wrote:
> Hi,
> 
> 
> 
> I am learning to use unittest with python and walkthrough with this example
> 
> http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html
> 
> 
> Thanks
> so my test script is like this:
> 
> import json
> 
> import urllib
> 
> #import time
> 
> #from util import *
> 
> import httplib
> 
> #import sys
> 
> #from scapy.all import *
> 
> import unittest
> 
> 
> 
> import os, sys, socket, struct, select, time 
> 
> from threading import Thread
> 
> 
> 
> import logging
> 
> import traceback
> 
> 
> 
> 
> 
> 
> 
> class testFirewall( unittest.TestCase ):
> 
> 	def setUp(self):
> 
> 		"""
> 
> 
> 
>         	set up data used in the tests.
> 
> 
> 
>         	setUp is called before each test function execution.
> 
> 
> 
>         	"""
> 
> 
> 
>         	self.controllerIp="127.0.0.1"
> 
> 		self.switches = ["00:00:00:00:00:00:00:01"]
> 
> 		self.startTime_ = time.time()
> 
> 		self.failed = False
> 
> 		self.reportStatus_ = True
> 
> 		self.name_ = "Firewall"
> 
> 		self.log = logging.getLogger("unittest")
> 
> 
> 
> 	def tearDown(self):
> 
> 		if self.failed:
> 
> 			return
> 
> 		duration = time.time() - self.startTime_
> 
> 		self.cleanup(True)
> 
> 		if self.reportStatus_:
> 
> 			self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration
> 
> 
> 
> 	def cleanup(self, success):
> 
> 		sys.excepthook = sys.__excepthook__
> 
> 		try:
> 
> 			return
> 
> 		except NameError:
> 
> 			self.log.error("Exception hit during cleanup, bypassing:\n%s\n\n" % traceback.format_exc())
> 
> 			pass
> 
> 		else:
> 
> 
> 
>     			fail("Expected a NameError")
> 
> 		
> 
> 
> 
> 	def testStatusFirewall(self):
> 
> 		command = "http://%s:8080/wm/firewall/module/status/json" % self.controllerIp
> 
> 		x = urllib.urlopen(command).read()
> 
> 		parsedResult = json.loads(x)
> 
> 		return parsedResult['result']
> 
> 
> 
> 
> 
> 	def suite():
> 
> 
> 
>     		suite = unittest.TestSuite()
> 
> 
> 
>     		suite.addTest(unittest.makeSuite(testFirewall))
> 
> 
> 
>     		return suite	
> 
> 
> 
> if __name__ == '__main__':
> 
> 	logging.basicConfig(filename='/tmp/testfirewall.log', level=logging.DEBUG, 
> 
>                     format='%(asctime)s %(levelname)s %(name)s %(message)s')
> 
> 	logger=logging.getLogger(__name__)	
> 
> 
> 
> 	suiteFew = unittest.TestSuite()
> 
> 
> 
>     	suiteFew.addTest(testFirewall("testStatusFirewall"))
> 
> 
> 
>     	unittest.TextTestRunner(verbosity=2).run(suiteFew)
> 
> 
> 
> 	#unittest.main()
> 
> 
> 
>     	#unittest.TextTestRunner(verbosity=2).run(suite())
> 
> 
> 
> 
> 
> while running it in console using python <FileName>.py
> 
> 
> 
> It gives me errror   
> 
> 
> 
> File "TestTest.py", line 44
> 
>     def cleanup(self, success):
> 
>       ^
> 
> SyntaxError: invalid syntax
> 
> 
> 
> I guess it is due to time module but as you can see I already had import time.
> 
> 
> 
> what can be the reason if I comment those line containing the time it works.
> 
> 
> 
> But i need to keep track of duration 
> 
> 
> 
> Please help and suggest.
> 
> 
> 
> Thanks,
> 
> Milson

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Syntax error in python unittest script Milson Munakami <milsonmun@gmail.com> - 2014-09-24 12:33 -0700
  Re: Syntax error in python unittest script Emile van Sebille <emile@fenx.com> - 2014-09-24 12:40 -0700
  Re: Syntax error in python unittest script Peter Otten <__peter__@web.de> - 2014-09-24 21:41 +0200
  Re: Syntax error in python unittest script Milson Munakami <milsonmun@gmail.com> - 2014-09-24 13:06 -0700
    Re: Syntax error in python unittest script Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-24 21:28 +0100
  Re: Syntax error in python unittest script Terry Reedy <tjreedy@udel.edu> - 2014-09-24 17:39 -0400

csiph-web