From ee46da88864fc7db32aa708738d7b679d86de093 Mon Sep 17 00:00:00 2001
From: Yves Noirjean <yves.noirjean@id.ethz.ch>
Date: Wed, 2 May 2018 14:07:47 +0200
Subject: [PATCH] obis: fixing tests - always striping trailing whitespace on
 command output

---
 src/python/OBis/obis/dm/command_result.py | 8 ++++----
 src/python/OBis/obis/dm/git.py            | 4 ++--
 src/python/OBis/obis/dm/utils.py          | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/python/OBis/obis/dm/command_result.py b/src/python/OBis/obis/dm/command_result.py
index a39af2482ac..37bd5794323 100644
--- a/src/python/OBis/obis/dm/command_result.py
+++ b/src/python/OBis/obis/dm/command_result.py
@@ -1,15 +1,15 @@
 class CommandResult(object):
     """Encapsulate result from a subprocess call."""
 
-    def __init__(self, completed_process=None, returncode=None, output=None, strip_whitespace=True):
+    def __init__(self, completed_process=None, returncode=None, output=None, strip_leading_whitespace=True):
         """Convert a completed_process object into a ShellResult."""
         if completed_process:
             self.returncode = completed_process.returncode
             if completed_process.stderr:
-                self.output = completed_process.stderr.decode('utf-8')
+                self.output = completed_process.stderr.decode('utf-8').rstrip()
             else:
-                self.output = completed_process.stdout.decode('utf-8')
-            if strip_whitespace:
+                self.output = completed_process.stdout.decode('utf-8').rstrip()
+            if strip_leading_whitespace:
                 self.output = self.output.strip()
         else:
             self.returncode = returncode
diff --git a/src/python/OBis/obis/dm/git.py b/src/python/OBis/obis/dm/git.py
index 1e04941bf21..0e87cd14c3e 100644
--- a/src/python/OBis/obis/dm/git.py
+++ b/src/python/OBis/obis/dm/git.py
@@ -31,9 +31,9 @@ class GitWrapper(object):
 
     def git_status(self, path=None):
         if path is None:
-            return run_shell([self.git_path, "status", "--porcelain"], strip_whitespace=False)
+            return run_shell([self.git_path, "status", "--porcelain"], strip_leading_whitespace=False)
         else:
-            return run_shell([self.git_path, "status", "--porcelain", path], strip_whitespace=False)
+            return run_shell([self.git_path, "status", "--porcelain", path], strip_leading_whitespace=False)
 
     def git_annex_init(self, path, desc):
         cmd = [self.git_path, "-C", path, "annex", "init", "--version=6"]
diff --git a/src/python/OBis/obis/dm/utils.py b/src/python/OBis/obis/dm/utils.py
index c0712898d73..a8b445a704c 100644
--- a/src/python/OBis/obis/dm/utils.py
+++ b/src/python/OBis/obis/dm/utils.py
@@ -34,8 +34,8 @@ def default_echo(details):
         print(details['message'])
 
 
-def run_shell(args, shell=False, strip_whitespace=True, raise_exception_on_failure=False):
-    result = CommandResult(subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell), strip_whitespace=strip_whitespace)
+def run_shell(args, shell=False, strip_leading_whitespace=True, raise_exception_on_failure=False):
+    result = CommandResult(subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell), strip_leading_whitespace=strip_leading_whitespace)
     if raise_exception_on_failure == True and result.failure():
         raise CommandException(result)
     return result
-- 
GitLab