Revision: e7633b178865
Branch:   default
Author:   Pekka Klärck
Date:     Tue Jan 28 16:58:11 2014 UTC
Log: Process: Fixed non-ASCII stuff on Windows after previous Jython non-ASCII fixes.

Also cleaned up tests related handling newlines. They shouldn't even be in the same suite as encoding tests, though.

Update issue 1638
Status: Done
The earlier fixes broke non-ASCII support on Windows pretty badly. Now those problems ought to be fixed. Tested on Linux w/ Python and Jython, and on Win7 w/ Python, Jython, and IronPython.
http://code.google.com/p/robotframework/source/detail?r=e7633b178865

Modified:
 /atest/robot/standard_libraries/process/newlines_and_encoding.txt
 /atest/testdata/standard_libraries/process/newlines_and_encoding.txt
 /src/robot/libraries/Process.py

=======================================
--- /atest/robot/standard_libraries/process/newlines_and_encoding.txt Tue Jan 28 14:24:45 2014 UTC +++ /atest/robot/standard_libraries/process/newlines_and_encoding.txt Tue Jan 28 16:58:11 2014 UTC
@@ -2,32 +2,22 @@
Suite Setup Run Tests ${EMPTY} standard_libraries/process/newlines_and_encoding.txt
 Force Tags       regression    pybot    jybot
 Resource         process_resource.txt
-Test Setup       Check Precondition

 *** Test Cases ***
-Non-ascii in command using shell=True
-    Check Test Case    ${TESTNAME}
-
-Non-ascii in command using shell=False
-    Check Test Case    ${TESTNAME}
-
-Non-ascii in command and output using shell=True
-    Check Test Case    ${TESTNAME}
-
-Non-ascii in command and output using shell=False
+Non-ASCII command and output
     Check Test Case    ${TESTNAME}

-Non-ascii in command and output with given stdout
+Non-ASCII command and output with custom stream
     Check Test Case    ${TESTNAME}

-Non-ascii in environment variables
+Non-ASCII in environment variables
     Check Test Case    ${TESTNAME}

-Newlines and trailing newline is removed
+Trailing newline is removed
     Check Test Case    ${TESTNAME}

-Newline test using shell=True
+Internal newlines are preserved
     Check Test Case    ${TESTNAME}

-Newline test using shell=False
+Newlines with custom stream
     Check Test Case    ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/process/newlines_and_encoding.txt Tue Jan 28 14:24:45 2014 UTC +++ /atest/testdata/standard_libraries/process/newlines_and_encoding.txt Tue Jan 28 16:58:11 2014 UTC
@@ -1,42 +1,38 @@
 *** Settings ***
 Resource          resource.txt

+*** Variables ***
+${STDOUT}         %{TEMPDIR}/process-stdout.txt
+
 *** Test Cases ***
-Non-ascii in command using shell=True
-    ${result}=   Run Process    python -c "print repr('ä')"   shell=True
-    Result should equal    ${result}    stdout='\\xc3\\xa4'
+Non-ASCII command and output
+    ${result}=   Run Process    echo hyvä   shell=True
+    Result should equal    ${result}    stdout=hyvä

-Non-ascii in command using shell=False
-    ${result}=   Run Process    python    -c    print repr('ä')
-    Result should equal    ${result}    stdout='\\xc3\\xa4'
+Non-ASCII command and output with custom stream
+    ${result}=   Run Process    echo hyvä   shell=True    stdout=${STDOUT}
+    Result should equal    ${result}    stdout=hyvä
+    [Teardown]   Safe Remove File    ${STDOUT}

-Non-ascii in command and output using shell=True
-    ${result}=   Run Process    python -c "print 'ä'"   shell=True
-    Result should equal    ${result}    stdout=ä
-
-Non-ascii in command and output using shell=False
-    ${result}=   Run Process    python    -c    print 'ä'
-    Result should equal    ${result}    stdout=ä
-
-Non-ascii in command and output with given stdout
-    ${path}=    Normalize Path    %{TEMPDIR}/process-stdout.txt
- ${result}= Run Process python -c print "ööåöåöå" shell=True stdout=${path}
-    Result should equal    ${result}    stdout=ööåöåöå
-    [Teardown]   Safe Remove File    ${path}
-
-Non-ascii in environment variables
-    [Setup]    Check Precondition    not sys.platform.startswith('java')
- ${result}= Run Process python -c "import os; print os.getenv('X_X')" shell=True env:X_X=Öoa
-    Result should equal    ${result}    stdout=Öoa
+Non-ASCII in environment variables
+    ${result}=   Run Process    python    -c
+ ... import os, sys; print os.getenv('X_X').decode(sys.getfilesystemencoding()) \=\= u'hyv\\xe4'
+    ...    env:X_X=hyvä    stderr=STDOUT
+    Result should equal    ${result}    stdout=True

-Newlines and trailing newline is removed
- ${result}= Run Process python -c "print 'first line\\nsecond line\\nthird line'" shell=True cwd=${CURDIR} - Result should equal ${result} stdout=first line\nsecond line\nthird line
+Trailing newline is removed
+    ${result}=   Run Process    python    -c    print 'nothing to remove',
+    Result should equal    ${result}    stdout=nothing to remove
+    ${result}=   Run Process    python    -c    print 'one is removed\\n',
+    Result should equal    ${result}    stdout=one is removed
+ ${result}= Run Process python -c print 'only one is removed\\n\\n\\n',
+    Result should equal    ${result}    stdout=only one is removed\n\n

-Newline test using shell=True
-    ${result}=   Run Process    python -c "print 'hello'"   shell=True
-    Result should equal    ${result}    stdout=hello
+Internal newlines are preserved
+    ${result}=   Run Process    python -c "print '1\\n2\\n3'"   shell=True
+    Result should equal    ${result}    stdout=1\n2\n3

-Newline test using shell=False
-    ${result}=   Run Process    python  -c   print "hello"
-    Result should equal    ${result}    stdout=hello
+Newlines with custom stream
+ ${result}= Run Process python -c "print '1\\n2\\n3'" shell=True stdout=${STDOUT}
+    Result should equal    ${result}    stdout=1\n2\n3
+    [Teardown]   Safe Remove File    ${STDOUT}
=======================================
--- /src/robot/libraries/Process.py     Tue Jan 28 14:24:45 2014 UTC
+++ /src/robot/libraries/Process.py     Tue Jan 28 16:58:11 2014 UTC
@@ -16,6 +16,7 @@

 import os
 import subprocess
+import sys
 import time
 import signal as signal_module

@@ -25,6 +26,10 @@
 from robot.api import logger


+if os.sep == '/' and sys.platform.startswith('java'):
+    encode_to_system = lambda string: string
+
+
 class Process(object):
     """Robot Framework test library for running processes.

@@ -321,7 +326,7 @@
that can be used as a handle to active the started process if needed.
         """
         config = ProcessConfig(**configuration)
-        executable_command = self._cmd(arguments, command, config.shell)
+        executable_command = self._cmd(command, arguments, config.shell)
         logger.info('Starting process:\n%s' % executable_command)
         logger.debug('Process configuration:\n%s' % config)
         process = subprocess.Popen(executable_command,
@@ -337,8 +342,8 @@
                                                  config.stderr_stream)
         return self._processes.register(process, alias=config.alias)

-    def _cmd(self, args, command, use_shell):
-        command = [item for item in [command] + list(args)]
+    def _cmd(self, command, args, use_shell):
+ command = [encode_to_system(item) for item in [command] + list(args)]
         if not use_shell:
             return command
         if args:
@@ -719,7 +724,7 @@
     def _format_output(self, output):
         if output.endswith('\n'):
             output = output[:-1]
-        return decode_output(output)
+        return decode_output(output, force=True)

     def __str__(self):
         return '<result object with rc %d>' % self.rc
@@ -756,6 +761,9 @@
         return self._new_stream(stderr)

     def _construct_env(self, env, extra):
+        if env:
+            env = dict((encode_to_system(k), encode_to_system(v))
+                       for k, v in env.items())
         for key in extra:
             if not key.startswith('env:'):
raise RuntimeError("'%s' is not supported by this keyword." % key)

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to