Commit 207cce64 authored by Mikaël Salson's avatar Mikaël Salson

server/: Convert unit tests to Python 3's print

parent df1fd249
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
import unittest import unittest
from gluon.globals import Request, Session, Storage, Response from gluon.globals import Request, Session, Storage, Response
from gluon.contrib.test_helpers import form_postvars from gluon.contrib.test_helpers import form_postvars
...@@ -99,7 +101,7 @@ class ConfigController(unittest.TestCase): ...@@ -99,7 +101,7 @@ class ConfigController(unittest.TestCase):
request.vars["id"] = id_config request.vars["id"] = id_config
resp = delete() resp = delete()
print resp print(resp)
self.assertEqual(resp.find('config deleted'), -1, "delete doesn't return a valid message") self.assertEqual(resp.find('config deleted'), -1, "delete doesn't return a valid message")
......
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
import unittest import unittest
import tempfile import tempfile
import gluon.contrib.simplejson import gluon.contrib.simplejson
...@@ -78,7 +80,7 @@ class DefaultController(unittest.TestCase): ...@@ -78,7 +80,7 @@ class DefaultController(unittest.TestCase):
def testCustomDataNoFile(self): def testCustomDataNoFile(self):
resp = gluon.contrib.simplejson.loads(get_custom_data()) resp = gluon.contrib.simplejson.loads(get_custom_data())
print resp['message'] print(resp['message'])
self.assertTrue(resp.has_key('success')) self.assertTrue(resp.has_key('success'))
self.assertEqual(resp['success'], 'false') self.assertEqual(resp['success'], 'false')
self.assertNotEqual(resp['message'].find('get_custom_data'), -1) self.assertNotEqual(resp['message'].find('get_custom_data'), -1)
...@@ -95,7 +97,7 @@ class DefaultController(unittest.TestCase): ...@@ -95,7 +97,7 @@ class DefaultController(unittest.TestCase):
def testCustomData(self): def testCustomData(self):
request.vars['custom'] = [str(fake_result_id2), str(fake_result_id2)] request.vars['custom'] = [str(fake_result_id2), str(fake_result_id2)]
resp = gluon.contrib.simplejson.loads(get_custom_data()) resp = gluon.contrib.simplejson.loads(get_custom_data())
print resp print(resp)
if resp.has_key('success') and resp['success'] == 'false': if resp.has_key('success') and resp['success'] == 'false':
self.assertTrue(defs.PORT_FUSE_SERVER is None, 'get_custom_data returns error without fuse server') self.assertTrue(defs.PORT_FUSE_SERVER is None, 'get_custom_data returns error without fuse server')
else: else:
......
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
import unittest import unittest
from mock import MagicMock, Mock, patch from mock import MagicMock, Mock, patch
from gluon.globals import Request, Session, Storage, Response from gluon.globals import Request, Session, Storage, Response
...@@ -202,7 +204,7 @@ class FileController(unittest.TestCase): ...@@ -202,7 +204,7 @@ class FileController(unittest.TestCase):
sequence_id = self.createDumbSequenceFile() sequence_id = self.createDumbSequenceFile()
request.vars['sequence_file_id'] = sequence_id request.vars['sequence_file_id'] = sequence_id
res = restart_pre_process() res = restart_pre_process()
print res print(res)
self.assertNotEqual(res.find('message'), -1, 'missing message in response') self.assertNotEqual(res.find('message'), -1, 'missing message in response')
def testRestartPreProcessInexistantFile(self): def testRestartPreProcessInexistantFile(self):
...@@ -211,5 +213,5 @@ class FileController(unittest.TestCase): ...@@ -211,5 +213,5 @@ class FileController(unittest.TestCase):
with patch.object(Scheduler, 'queue_task', return_value=fake_task) as mock_queue_task: with patch.object(Scheduler, 'queue_task', return_value=fake_task) as mock_queue_task:
request.vars['sequence_file_id'] = 666 request.vars['sequence_file_id'] = 666
res = restart_pre_process() res = restart_pre_process()
print res print(res)
self.assertNotEqual(res.find('"success":"false"'), -1, 'missing message in response') self.assertNotEqual(res.find('"success":"false"'), -1, 'missing message in response')
...@@ -34,6 +34,8 @@ ndegroot0@gmail.com ...@@ -34,6 +34,8 @@ ndegroot0@gmail.com
from __future__ import print_function
from gluon import current from gluon import current
import gluon import gluon
from gluon.tools import Auth from gluon.tools import Auth
...@@ -274,10 +276,10 @@ suite = unittest.TestSuite() ...@@ -274,10 +276,10 @@ suite = unittest.TestSuite()
def showfeedback(): def showfeedback():
exc_type, exc_value, exc_traceback = sys.exc_info() exc_type, exc_value, exc_traceback = sys.exc_info()
print '-'*60 print('-'*60)
for line in traceback.format_exception(exc_type, exc_value,exc_traceback): for line in traceback.format_exception(exc_type, exc_value,exc_traceback):
print line[:-1] print(line[:-1])
print '-'*60 print('-'*60)
def custom_execfile(test_file): def custom_execfile(test_file):
...@@ -302,7 +304,7 @@ appname = 'vidjil' ...@@ -302,7 +304,7 @@ appname = 'vidjil'
# find doctests in controller # find doctests in controller
path=os.path.join('applications',appname,'controllers','*.py') path=os.path.join('applications',appname,'controllers','*.py')
doc_test_files = glob.glob(path) doc_test_files = glob.glob(path)
print len(doc_test_files)," controller files with possible doctests found." print(len(doc_test_files)," controller files with possible doctests found.")
# get all files with tests # get all files with tests
test_files = glob.glob('applications/'+appname+'/tests/*/*.py') test_files = glob.glob('applications/'+appname+'/tests/*/*.py')
...@@ -311,7 +313,7 @@ if not len(test_files): ...@@ -311,7 +313,7 @@ if not len(test_files):
raise Exception("No files found for app: " + sys.argv[2]) raise Exception("No files found for app: " + sys.argv[2])
# Bring in all doc tests and submit them # Bring in all doc tests and submit them
print "Run doctests" if doc_test_files else "No doctests" print("Run doctests" if doc_test_files else "No doctests")
for f in doc_test_files: for f in doc_test_files:
g=custom_execfile(f) g=custom_execfile(f)
suite.addTest(doctest.DocFileSuite(f, globs=g, suite.addTest(doctest.DocFileSuite(f, globs=g,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment