From d4d9b9fb75525873b291028a622aac70c44a5065 Mon Sep 17 00:00:00 2001 From: Sebastian Luna Valero Date: Mon, 26 Feb 2018 13:24:52 +0000 Subject: [PATCH] portability tweaks for OS X --- CGATCore/IOTools.py | 4 ++ CGATCore/Pipeline/Parameters.py | 3 ++ tests/test_pipeline_execution.py | 63 ++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/CGATCore/IOTools.py b/CGATCore/IOTools.py index 7b8c10f..d8947d9 100644 --- a/CGATCore/IOTools.py +++ b/CGATCore/IOTools.py @@ -1421,6 +1421,7 @@ def mount_file(fn): def remote_file_exists(filename, hostname=None, expect=False): + ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: @@ -1428,6 +1429,9 @@ def remote_file_exists(filename, hostname=None, expect=False): except paramiko.SSHException as ex: # disable test on VM, key issues. return expect + except TimeoutError as ex: + # times out on OS X, localhost + return expect stdin, stdout, ssh_stderr = ssh.exec_command("ls -d {}".format(filename)) out = stdout.read().decode("utf-8") diff --git a/CGATCore/Pipeline/Parameters.py b/CGATCore/Pipeline/Parameters.py index 44268d4..602a1b2 100644 --- a/CGATCore/Pipeline/Parameters.py +++ b/CGATCore/Pipeline/Parameters.py @@ -10,6 +10,7 @@ import collections import os import sys +import platform import configparser import getpass import logging @@ -92,6 +93,8 @@ def __call__(self): 'jobs_limit_db': 10, # ruffus job limits for R 'jobs_limit_R': 1, + # operating system we are running on + 'os': platform.system(), } # After all configuration files have been read, some diff --git a/tests/test_pipeline_execution.py b/tests/test_pipeline_execution.py index 3f49396..72cffb9 100644 --- a/tests/test_pipeline_execution.py +++ b/tests/test_pipeline_execution.py @@ -142,39 +142,46 @@ def test_job_should_fail_if_too_little_memory_required(self): outfile = os.path.join(self.work_dir, "out") - self.assertRaises( - OSError, - P.run, - "python -c 'import numpy; " - "a = numpy.array(numpy.arange(0, {memory}), numpy.int8); " - "out = open(\"{outfile}\", \"w\"); " - "out.write(str(len(a)) + \"\\n\"); " - "out.close()'".format( - memory=self.test_memory_size, - outfile=outfile), - to_cluster=self.to_cluster, - job_memory="{}G".format( - 0.5 * self.test_memory_size / 10**9)) + if P.get_parameters()['os'] == 'Linux': + self.assertRaises( + OSError, + P.run, + "python -c 'import numpy; " + "a = numpy.array(numpy.arange(0, {memory}), numpy.int8); " + "out = open(\"{outfile}\", \"w\"); " + "out.write(str(len(a)) + \"\\n\"); " + "out.close()'".format( + memory=self.test_memory_size, + outfile=outfile), + to_cluster=self.to_cluster, + job_memory="{}G".format( + 0.5 * self.test_memory_size / 10**9)) + else: + pass def test_job_should_fail_if_too_little_memory_required_in_second_statement(self): outfile = os.path.join(self.work_dir, "out") infile = "arv=by_id/glon1-4zz18-3cbje7tmr0nitut/study_list.txt" - self.assertRaises( - OSError, - P.run, - "hostname > {outfile}; " - "python -c 'import numpy; " - "a = numpy.array(numpy.arange(0, {memory}), numpy.int8); " - "out = open(\"{outfile}\", \"w\"); " - "out.write(str(len(a)) + \"\\n\"); " - "out.close()'".format( - memory=self.test_memory_size, - infile=infile, - outfile=outfile), - to_cluster=self.to_cluster, - job_memory="{}G".format( - 0.5 * self.test_memory_size / 10**9)) + + if P.get_parameters()['os'] == 'Linux': + self.assertRaises( + OSError, + P.run, + "hostname > {outfile}; " + "python -c 'import numpy; " + "a = numpy.array(numpy.arange(0, {memory}), numpy.int8); " + "out = open(\"{outfile}\", \"w\"); " + "out.write(str(len(a)) + \"\\n\"); " + "out.close()'".format( + memory=self.test_memory_size, + infile=infile, + outfile=outfile), + to_cluster=self.to_cluster, + job_memory="{}G".format( + 0.5 * self.test_memory_size / 10**9)) + else: + pass def test_job_should_pass_if_enough_memory_required(self): outfile = os.path.join(self.work_dir, "out")