interpy
interpy copied to clipboard
Test suite fails because of IndentationError with interpy
If I use interpy in my testing suite and run python -m tabnanny [file]
it doesn't show any errors. But when i run nosetests [file]
I get an IndentationError:
E
======================================================================
ERROR: Failure: IndentationError (unindent does not match any outer indentation level (server_communication_test.py, line 19))
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/brendanberman/.pyenv/versions/2.7.10/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/Users/brendanberman/.pyenv/versions/2.7.10/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/brendanberman/.pyenv/versions/2.7.10/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/xxx/tests/server/server_communication_test.py", line 19
websocket_testing_port = 9876
^
IndentationError: unindent does not match any outer indentation level
----------------------------------------------------------------------
Ran 1 test in 0.006s
FAILED (errors=1)
# coding: interpy
__author__ = 'pcflmb'
import unittest
import os
from nose.tools import *
import cherrypy
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from ws4py.websocket import EchoWebSocket
class ServerCommunicationTest(unittest.TestCase):
"""
Test to make sure our server is correctly createing a websocket,
receiving data, and reconnecting on dropped connections.
"""
websocket_testing_port = 9876
@classmethod
def setup_class(self):
cherrypy.config.update({'server.socket_port': ServerCommunicationTest.websocket_testing_port})
WebSocketPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()
cherrypy.quickstart(Root(), '/', config={'/ws': {'tools.websocket.on': True,
'tools.websocket.handler_cls': EchoWebSocket}})
@classmethod
def teardown_class(self):
pass
def test_websocket_connecting(self):
websocket_client = ServerCommunication("ws://localhost:#{ServerCommunicationTest.websocket_testing_port}/ws")
def test_websocket_connecting(self):
pass
class Root(object):
@cherrypy.expose
def index(self):
return 'some HTML with a websocket javascript connection'
@cherrypy.expose
def ws(self):
# you can access the class instance through
handler = cherrypy.request.ws_handler
Similar issue trying to execute a simple for loop:
#!/usr/bin/env python
# coding: interpy
import psycopg2, random
NUM_ACCOUNTS = 5
conn = psycopg2.connect("dbname=pgbench user=tag")
cur = conn.cursor()
for account in range(NUM_ACCOUNTS):
balance = random.randrange(1000)
cur.execute("UPDATE pgbench_accounts SET abalance = #{balance} WHERE aid = #{account+1};")
conn.commit()
cur.close()
conn.close()
Error:
$ ./randomizedb.py
File "./randomizedb.py", line 11
cur.execute( "UPDATE pgbench_accounts SET abalance = "+unicode(balance)+" WHERE aid = "+unicode(account+1 )+";" )
^
IndentationError: unindent does not match any outer indentation level