2 new revisions:

Revision: 5ccb3dbfb9d2
Branch:   default
Author:   Mika Hänninen <mika.hanni...@gmail.com>
Date:     Mon Jun 10 05:47:50 2013
Log:      process lib: newlines and encoding
http://code.google.com/p/robotframework/source/detail?r=5ccb3dbfb9d2

Revision: 060c9b609059
Branch:   default
Author:   Mika Hänninen <mika.hanni...@gmail.com>
Date:     Mon Jun 10 05:47:56 2013
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=060c9b609059

==============================================================================
Revision: 5ccb3dbfb9d2
Branch:   default
Author:   Mika Hänninen <mika.hanni...@gmail.com>
Date:     Mon Jun 10 05:47:50 2013
Log:      process lib: newlines and encoding
http://code.google.com/p/robotframework/source/detail?r=5ccb3dbfb9d2

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

=======================================
--- /dev/null
+++ /atest/robot/standard_libraries/process/test_newlines_and_encoding.txt Mon Jun 10 05:47:50 2013
@@ -0,0 +1,31 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} standard_libraries/process/test_newlines_and_encoding.txt
+Force Tags       regression    pybot    jybot
+Test Setup       Check Preconditions
+Resource         atest_resource.txt
+
+*** Test Cases ***
+Non-ascii in the command using shell=True
+    Check Test Case    ${TESTNAME}
+
+Non-ascii in the command using shell=False
+    Check Test Case    ${TESTNAME}
+
+Non-ascii in the command with given stdout
+    Check Test Case    ${TESTNAME}
+
+Ascii characters in output with dir command
+    Check Test Case    ${TESTNAME}
+
+Non-ascii in the command arguments
+    Check Test Case    ${TESTNAME}
+
+Newline test using shell=True
+    Check Test Case    ${TESTNAME}
+
+Newline test using shell=False
+    Check Test Case    ${TESTNAME}
+
+*** Keywords ***
+Check Preconditions
+ Run Keyword If '${SUITE.metadata.get('info')}' == 'precondition_fail' Fail precondition fail -regression
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/process/test_newlines_and_encoding.txt Mon Jun 10 05:47:50 2013
@@ -0,0 +1,39 @@
+*** Settings ***
+Suite Setup       Check Preconditions
+Library           Process
+Resource          resource.txt
+
+*** Test Cases ***
+Non-ascii in the command using shell=True
+    ${result}=   Run Process    python -c 'print "ööåöåöå"'   shell=True
+    Result should equal    ${result}    stdout=ööåöåöå   exit_code=0
+
+Non-ascii in the command using shell=False
+    ${result}=   Run Process    python   -c     print "ööåöåöå"
+    Result should equal    ${result}    stdout=ööåöåöå   exit_code=0
+
+Non-ascii in the command with given stdout
+ ${result}= Run Process python -c print "ööåöåöå" shell=True stdout=myfile.txt
+    Result should equal    ${result}    stdout=ööåöåöå   exit_code=0
+
+Ascii characters in output with dir command
+    ${result}=   Run Process    dir   ${CURDIR}    shell=True
+    Log     ${result.stdout}
+
+Non-ascii in the command arguments
+ ${result}= Run Process python -c "import os; print os.getenv('varri', '-');" shell=True env:varri=Öoa
+    Should Be Equal        ${result.stdout.strip()}  Öoa
+
+Newline test using shell=True
+    ${result}=   Run Process    python -c 'print "hello"'   shell=True
+    Result should equal    ${result}    stdout=hello  exit_code=0
+
+Newline test using shell=False
+    ${result}=   Run Process    python  -c   print "hello"
+    Result should equal    ${result}    stdout=hello   exit_code=0
+
+*** Keywords ***
+Check Preconditions
+ ${is_ok}= Evaluate sys.version_info >= (2,6) and sys.platform != 'cli' sys + Run Keyword If not ${is_ok} Set Suite Metadata info precondition_fail
+    Run Keyword If  not ${is_ok}    Fail
=======================================
--- /src/robot/libraries/Process.py     Mon Jun 10 02:16:55 2013
+++ /src/robot/libraries/Process.py     Mon Jun 10 05:47:50 2013
@@ -19,7 +19,7 @@
 import subprocess
 import sys

-from robot.utils import ConnectionCache, encode_to_system
+from robot.utils import ConnectionCache, encode_to_system, decode_output, decode_from_system
 from robot.version import get_version
 from robot.api import logger

@@ -306,20 +306,20 @@
                                    stdin=subprocess.PIPE,
                                    shell=config.shell,
                                    cwd=config.cwd,
-                                   env=config.env)
+                                   env=config.env,
+                                   universal_newlines=True)
         self._results[process] = ExecutionResult(process,
                                                  config.stdout_stream,
                                                  config.stderr_stream)
return self._started_processes.register(process, alias=config.alias)

     def _cmd(self, args, command, use_shell):
-        # TODO: Why is command not encoded? Remember also elif below.
-        cmd = [command] + [encode_to_system(i) for i in args]
-        if use_shell and args:
-            cmd = subprocess.list2cmdline(cmd)
-        elif use_shell:
-            cmd = command
-        return cmd
+ command = [encode_to_system(item) for item in [command] + list(args)]
+        if not use_shell:
+            return command
+        if args:
+            return subprocess.list2cmdline(command)
+        return command[0]

     # TODO: process_is_running vs is_process_running
     def process_is_running(self, handle=None):
@@ -490,9 +490,9 @@

     def _construct_stdout(self):
         if not self.stdout_path:
-            return self._process.stdout.read()
+            return decode_from_system(self._process.stdout.read())
         with open(self.stdout_path, 'r') as f:
-            return f.read()
+            return decode_from_system(f.read())

     @property
     def stderr(self):

==============================================================================
Revision: 060c9b609059
Branch:   default
Author:   Mika Hänninen <mika.hanni...@gmail.com>
Date:     Mon Jun 10 05:47:56 2013
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=060c9b609059

Modified:
 /src/robot/libraries/Process.py

=======================================
--- /src/robot/libraries/Process.py     Mon Jun 10 05:39:20 2013
+++ /src/robot/libraries/Process.py     Mon Jun 10 05:47:56 2013
@@ -19,7 +19,7 @@
 import subprocess
 import sys

-from robot.utils import ConnectionCache, encode_to_system
+from robot.utils import ConnectionCache, encode_to_system, decode_output, decode_from_system
 from robot.version import get_version
 from robot.api import logger

@@ -306,20 +306,20 @@
                                    stdin=subprocess.PIPE,
                                    shell=config.shell,
                                    cwd=config.cwd,
-                                   env=config.env)
+                                   env=config.env,
+                                   universal_newlines=True)
         self._results[process] = ExecutionResult(process,
                                                  config.stdout_stream,
                                                  config.stderr_stream)
return self._started_processes.register(process, alias=config.alias)

     def _cmd(self, args, command, use_shell):
-        # TODO: Why is command not encoded? Remember also elif below.
-        cmd = [command] + [encode_to_system(i) for i in args]
-        if use_shell and args:
-            cmd = subprocess.list2cmdline(cmd)
-        elif use_shell:
-            cmd = command
-        return cmd
+ command = [encode_to_system(item) for item in [command] + list(args)]
+        if not use_shell:
+            return command
+        if args:
+            return subprocess.list2cmdline(command)
+        return command[0]

     # TODO: process_is_running vs is_process_running
     def process_is_running(self, handle=None):
@@ -490,9 +490,9 @@

     def _construct_stdout(self):
         if not self.stdout_path:
-            return self._process.stdout.read()
+            return decode_from_system(self._process.stdout.read())
         with open(self.stdout_path, 'r') as f:
-            return f.read()
+            return decode_from_system(f.read())

     @property
     def stderr(self):

--

--- 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