Skip to content
Snippets Groups Projects
Commit c46010eb authored by John Chilton's avatar John Chilton
Browse files

More bug fixes discovered through Python 3 testing.

Also improved unicode handling and testing.
parent 5b6039ca
No related branches found
No related tags found
No related merge requests found
...@@ -146,6 +146,7 @@ class Controller(object): ...@@ -146,6 +146,7 @@ class Controller(object):
resp = self.__build_response(result) resp = self.__build_response(result)
return resp(environ, start_response) return resp(environ, start_response)
controller_replacement.func = func controller_replacement.func = func
controller_replacement.response_type = self.response_type controller_replacement.response_type = self.response_type
controller_replacement.body = self.body controller_replacement.body = self.body
......
...@@ -123,6 +123,7 @@ class LocalJobManagerInterface(object): ...@@ -123,6 +123,7 @@ class LocalJobManagerInterface(object):
} }
def execute(self, command, args={}, data=None, input_path=None, output_path=None): def execute(self, command, args={}, data=None, input_path=None, output_path=None):
# If data set, should be unicode (on Python 2) or str (on Python 3).
from lwr import routes from lwr import routes
from lwr.framework import build_func_args from lwr.framework import build_func_args
controller = getattr(routes, command) controller = getattr(routes, command)
...@@ -139,7 +140,7 @@ class LocalJobManagerInterface(object): ...@@ -139,7 +140,7 @@ class LocalJobManagerInterface(object):
def __build_body(self, data, input_path): def __build_body(self, data, input_path):
if data is not None: if data is not None:
return BytesIO(data) return BytesIO(data.encode('utf-8'))
elif input_path is not None: elif input_path is not None:
return open(input_path, 'rb') return open(input_path, 'rb')
else: else:
......
from os.path import abspath, basename, join, exists from os.path import abspath, basename, join, exists
from os import listdir, sep from os import listdir, sep
from re import findall from re import findall
from io import open
from .action_mapper import FileActionMapper from .action_mapper import FileActionMapper
...@@ -24,22 +25,24 @@ class JobInputs(object): ...@@ -24,22 +25,24 @@ class JobInputs(object):
>>> import tempfile >>> import tempfile
>>> tf = tempfile.NamedTemporaryFile() >>> tf = tempfile.NamedTemporaryFile()
>>> def setup_inputs(tf): >>> def setup_inputs(tf):
... open(tf.name, "w").write("world /path/to/input the rest") ... open(tf.name, "w").write(u"world /path/to/input the rest")
... inputs = JobInputs("hello /path/to/input", [tf.name]) ... inputs = JobInputs(u"hello /path/to/input", [tf.name])
... return inputs ... return inputs
>>> inputs = setup_inputs(tf) >>> inputs = setup_inputs(tf)
>>> inputs.rewrite_paths("/path/to/input", 'C:\\input') >>> inputs.rewrite_paths(u"/path/to/input", u'C:\\input')
>>> inputs.rewritten_command_line >>> inputs.rewritten_command_line == u'hello C:\\\\input'
'hello C:\\\\input' True
>>> inputs.rewritten_config_files[tf.name] >>> inputs.rewritten_config_files[tf.name] == u'world C:\\\\input the rest'
'world C:\\\\input the rest' True
>>> tf.close() >>> tf.close()
>>> tf = tempfile.NamedTemporaryFile() >>> tf = tempfile.NamedTemporaryFile()
>>> inputs = setup_inputs(tf) >>> inputs = setup_inputs(tf)
>>> inputs.find_referenced_subfiles('/path/to') >>> inputs.find_referenced_subfiles('/path/to') == [u'/path/to/input']
['/path/to/input'] True
>>> inputs.path_referenced('/path/to') >>> inputs.path_referenced('/path/to')
True True
>>> inputs.path_referenced(u'/path/to')
True
>>> inputs.path_referenced('/path/to/input') >>> inputs.path_referenced('/path/to/input')
True True
>>> inputs.path_referenced('/path/to/notinput') >>> inputs.path_referenced('/path/to/notinput')
...@@ -340,9 +343,9 @@ def submit_job(client, tool, command_line, config_files, input_files, output_fil ...@@ -340,9 +343,9 @@ def submit_job(client, tool, command_line, config_files, input_files, output_fil
def _read(path): def _read(path):
""" """
Utility method to quickly read small files (config files and tool Utility method to quickly read small files (config files and tool
wrappers) into memory as strings. wrappers) into memory as bytes.
""" """
input = open(path, "r") input = open(path, "r", encoding="utf-8")
try: try:
return input.read() return input.read()
finally: finally:
......
...@@ -3,7 +3,6 @@ try: ...@@ -3,7 +3,6 @@ try:
from Queue import Queue from Queue import Queue
except ImportError: except ImportError:
from queue import Queue from queue import Queue
import sys
import threading import threading
import traceback import traceback
...@@ -79,7 +78,7 @@ class QueueManager(Manager): ...@@ -79,7 +78,7 @@ class QueueManager(Manager):
self._run(job_id, command_line, async=False) self._run(job_id, command_line, async=False)
except: except:
log.warn("Uncaught exception running job with job_id %s" % job_id) log.warn("Uncaught exception running job with job_id %s" % job_id)
traceback.print_exc(file=sys.stdout) traceback.print_exc()
class PersistedJobStore(JobMetadataStore): class PersistedJobStore(JobMetadataStore):
......
import shelve import shelve
from threading import Lock from threading import Lock
import traceback import traceback
import sys
class PersistenceStore(object): class PersistenceStore(object):
...@@ -31,7 +30,7 @@ class PersistenceStore(object): ...@@ -31,7 +30,7 @@ class PersistenceStore(object):
try: try:
return func() return func()
except: except:
traceback.print_exc(file=sys.stdout) traceback.print_exc()
if not suppress_exception: if not suppress_exception:
raise raise
......
...@@ -49,8 +49,8 @@ def run(options): ...@@ -49,8 +49,8 @@ def run(options):
__write_to_file(temp_config_path, EXPECTED_OUTPUT) __write_to_file(temp_config_path, EXPECTED_OUTPUT)
__write_to_file(temp_tool_path, TEST_SCRIPT) __write_to_file(temp_tool_path, TEST_SCRIPT)
empty_input = "/foo/bar/x" empty_input = u"/foo/bar/x"
command_line = 'python %s "%s" "%s" "%s" "%s"' % (temp_tool_path, temp_config_path, temp_input_path, temp_output_path, empty_input) command_line = u'python %s "%s" "%s" "%s" "%s"' % (temp_tool_path, temp_config_path, temp_input_path, temp_output_path, empty_input)
config_files = [temp_config_path] config_files = [temp_config_path]
input_files = [temp_input_path, empty_input] input_files = [temp_input_path, empty_input]
output_files = [temp_output_path] output_files = [temp_output_path]
...@@ -69,10 +69,10 @@ def run(options): ...@@ -69,10 +69,10 @@ def run(options):
__check_output(temp_output_path) __check_output(temp_output_path)
__exercise_errors(options, client, temp_output_path, temp_directory) __exercise_errors(options, client, temp_output_path, temp_directory)
except BaseException as e: except BaseException:
if not options.suppress_output: if not options.suppress_output:
traceback.print_exc(e) traceback.print_exc()
raise e raise
finally: finally:
shutil.rmtree(temp_directory) shutil.rmtree(temp_directory)
...@@ -81,7 +81,7 @@ def __check_output(temp_output_path): ...@@ -81,7 +81,7 @@ def __check_output(temp_output_path):
""" """
Verified the correct outputs were written (i.e. job ran properly). Verified the correct outputs were written (i.e. job ran properly).
""" """
output_file = open(temp_output_path, 'r') output_file = open(temp_output_path, 'rb')
try: try:
output_contents = output_file.read() output_contents = output_file.read()
assert output_contents == EXPECTED_OUTPUT, "Invalid output_contents: %s" % output_contents assert output_contents == EXPECTED_OUTPUT, "Invalid output_contents: %s" % output_contents
...@@ -98,9 +98,9 @@ def __exercise_errors(options, client, temp_output_path, temp_directory): ...@@ -98,9 +98,9 @@ def __exercise_errors(options, client, temp_output_path, temp_directory):
if getattr(options, 'test_errors', False): if getattr(options, 'test_errors', False):
try: try:
client.fetch_output(temp_output_path + "x", temp_directory) client.fetch_output(temp_output_path + "x", temp_directory)
except BaseException as e: except BaseException:
if not options.suppress_output: if not options.suppress_output:
traceback.print_exc(e) traceback.print_exc()
def __client(options): def __client(options):
......
...@@ -66,10 +66,10 @@ class IntegrationTests(BaseIntegrationTest): ...@@ -66,10 +66,10 @@ class IntegrationTests(BaseIntegrationTest):
self._run(private_token=None, transport="curl", **self.default_kwargs) self._run(private_token=None, transport="curl", **self.default_kwargs)
def test_integration_token(self): def test_integration_token(self):
self._run(app_conf={"private_key": "testtoken"}, private_token="testtoken", transport="curl", **self.default_kwargs) self._run(app_conf={"private_key": "testtoken"}, private_token="testtoken", **self.default_kwargs)
def test_integration_errors(self): def test_integration_errors(self):
self._run(app_conf={"private_key": "testtoken"}, private_token="testtoken", transport="curl", test_errors=True, **self.default_kwargs) self._run(app_conf={"private_key": "testtoken"}, private_token="testtoken", test_errors=True, **self.default_kwargs)
@skipUnlessModule("drmaa") @skipUnlessModule("drmaa")
def test_integration_drmaa(self): def test_integration_drmaa(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment