2 new revisions:

Revision: a822de705908
Branch:   default
Author:   Pekka Klärck
Date:     Tue Jan 28 22:16:40 2014 UTC
Log:      Process: Separate suite for tests related to stdout/stderr.
http://code.google.com/p/robotframework/source/detail?r=a822de705908

Revision: 9f01ec56cd9c
Branch:   default
Author:   Pekka Klärck
Date:     Tue Jan 28 23:10:45 2014 UTC
Log: Process: Fixed failures reading custom streams with Jython on Windows...
http://code.google.com/p/robotframework/source/detail?r=9f01ec56cd9c

==============================================================================
Revision: a822de705908
Branch:   default
Author:   Pekka Klärck
Date:     Tue Jan 28 22:16:40 2014 UTC
Log:      Process: Separate suite for tests related to stdout/stderr.
http://code.google.com/p/robotframework/source/detail?r=a822de705908

Added:
 /atest/robot/standard_libraries/process/stdout_and_stderr.txt
 /atest/testdata/standard_libraries/process/stdout_and_stderr.txt
Modified:
 /atest/robot/standard_libraries/process/process_library.txt
 /atest/testdata/standard_libraries/process/newlines_and_encoding.txt
 /atest/testdata/standard_libraries/process/process_library.txt
 /atest/testdata/standard_libraries/process/resource.txt
 /src/robot/libraries/Process.py

=======================================
--- /dev/null
+++ /atest/robot/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 22:16:40 2014 UTC
@@ -0,0 +1,32 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} standard_libraries/process/stdout_and_stderr.txt
+Force Tags       regression    pybot    jybot
+Resource         process_resource.txt
+
+*** Test Cases ***
+Default stdout and stderr
+    Check Test Case    ${TESTNAME}
+
+Custom stdout
+    Check Test Case    ${TESTNAME}
+
+Custom stderr
+    Check Test Case    ${TESTNAME}
+
+Custom stdout and stderr
+    Check Test Case    ${TESTNAME}
+
+Custom stdout and stderr to same file
+    Check Test Case    ${TESTNAME}
+
+Redirecting stderr to stdout
+    Check Test Case    ${TESTNAME}
+
+Redirecting stderr to custom stdout
+    Check Test Case    ${TESTNAME}
+
+Custom streams are written under cwd when relative
+    Check Test Case    ${TESTNAME}
+
+Cwd does not affect absolute custom streams
+    Check Test Case    ${TESTNAME}
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 22:16:40 2014 UTC
@@ -0,0 +1,57 @@
+*** Settings ***
+Resource          resource.txt
+Test Teardown     Safe Remove File    ${STDOUT}    ${STDERR}
+
+*** Test Cases ***
+Default stdout and stderr
+    ${result} =    Run Stdout Stderr Process
+    Result Should Equal    ${result}    stdout    stderr
+
+Custom stdout
+    ${result} =    Run Stdout Stderr Process    stdout=${STDOUT}
+ Result Should Equal ${result} stdout stderr stdout_path=${STDOUT}
+
+Custom stderr
+    ${result} =    Run Stdout Stderr Process    stderr=${STDERR}
+ Result Should Equal ${result} stdout stderr stderr_path=${STDERR}
+
+Custom stdout and stderr
+ ${result} = Run Stdout Stderr Process stdout=${STDOUT} stderr=${STDERR} + Result Should Equal ${result} stdout stderr stdout_path=${STDOUT} stderr_path=${STDERR}
+
+Custom stdout and stderr to same file
+ ${result} = Run Stdout Stderr Process stdout=${STDOUT} stderr=${STDOUT}
+    Result Should Match    ${result}    std???std???    std???std???
+    ...    stdout_path=${STDOUT}    stderr_path=${STDOUT}
+
+Redirecting stderr to stdout
+    ${result} =    Run Stdout Stderr Process    stderr=STDOUT
+    Result Should Match    ${result}    std???std???
+
+Redirecting stderr to custom stdout
+ ${result} = Run Stdout Stderr Process stdout=${STDOUT} stderr=STDOUT
+    Result Should Match    ${result}    std???std???    std???std???
+    ...    stdout_path=${STDOUT}    stderr_path=${STDOUT}
+
+Custom streams are written under cwd when relative
+    [Setup]    Create Directory    ${CWD}
+ ${result} = Run Stdout Stderr Process cwd=${CWD} stdout=stdout.txt stderr=stderr.txt + Result Should Equal ${result} stdout stderr stdout_path=${CWD}/stdout.txt stderr_path=${CWD}/stderr.txt
+    [Teardown]    Safe Remove Directory    ${CWD}
+
+Cwd does not affect absolute custom streams
+    [Setup]    Create Directory    ${CWD}
+ ${result} = Run Stdout Stderr Process cwd=${CWD} stdout=${STDOUT} stderr=${STDERR} + Result Should Equal ${result} stdout stderr stdout_path=${STDOUT} stderr_path=${STDERR}
+    [Teardown]    Safe Remove Directory    ${CWD}
+
+*** Keywords ***
+Run Stdout Stderr Process
+    [Arguments]    ${stdout}=${NONE}    ${stderr}=${NONE}    ${cwd}=${NONE}
+    ${code} =    Catenate    SEPARATOR=;
+    ...    import sys
+    ...    sys.stdout.write('stdout')
+    ...    sys.stderr.write('stderr')
+    ${result} =    Run Process    python    -c    ${code}
+    ...    stdout=${stdout}    stderr=${stderr}    cwd=${cwd}
+    [Return]    ${result}
=======================================
--- /atest/robot/standard_libraries/process/process_library.txt Tue Jan 28 09:20:00 2014 UTC +++ /atest/robot/standard_libraries/process/process_library.txt Tue Jan 28 22:16:40 2014 UTC
@@ -1,4 +1,6 @@
 *** Settings ***
+Documentation This suite should be split. Please don't add more tests but +... create a new suite and move related tests from here to it too. Suite Setup Run Tests ${EMPTY} standard_libraries/process/process_library.txt
 Force Tags       regression    pybot    jybot
 Resource         process_resource.txt
@@ -21,12 +23,6 @@

 Change Current Working Directory
     Check Test Case    ${TESTNAME}
-
-Setting Stdout
-    Check Test Case    ${TESTNAME}
-
-Setting Stderr
-    Check Test Case    ${TESTNAME}

 Without Env Configuration the Environment Should Be As It Was
     Check Test Case    ${TESTNAME}
@@ -60,15 +56,3 @@

 Process alias
     Check Test Case    ${TESTNAME}
-
-Redirecting Stderr to Stdout
-    Check Test Case    ${TESTNAME}
-
-Redirecting Stderr to Stdout with filename
-    Check Test Case    ${TESTNAME}
-
-Current working directory should be used with stdout and stderr
-    Check Test Case    ${TESTNAME}
-
-Current working directory should not be used with stdout and stderr when absolute path in use
-    Check Test Case    ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/process/newlines_and_encoding.txt Tue Jan 28 16:58:11 2014 UTC +++ /atest/testdata/standard_libraries/process/newlines_and_encoding.txt Tue Jan 28 22:16:40 2014 UTC
@@ -1,9 +1,6 @@
 *** Settings ***
 Resource          resource.txt

-*** Variables ***
-${STDOUT}         %{TEMPDIR}/process-stdout.txt
-
 *** Test Cases ***
 Non-ASCII command and output
     ${result}=   Run Process    echo hyvä   shell=True
@@ -11,7 +8,7 @@

 Non-ASCII command and output with custom stream
     ${result}=   Run Process    echo hyvä   shell=True    stdout=${STDOUT}
-    Result should equal    ${result}    stdout=hyvä
+ Result should equal ${result} stdout=hyvä stdout_path=${STDOUT}
     [Teardown]   Safe Remove File    ${STDOUT}

 Non-ASCII in environment variables
@@ -34,5 +31,5 @@

 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
+ Result should equal ${result} stdout=1\n2\n3 stdout_path=${STDOUT}
     [Teardown]   Safe Remove File    ${STDOUT}
=======================================
--- /atest/testdata/standard_libraries/process/process_library.txt Mon Nov 18 08:12:43 2013 UTC +++ /atest/testdata/standard_libraries/process/process_library.txt Tue Jan 28 22:16:40 2014 UTC
@@ -38,20 +38,6 @@
${result}= Run Process python -c import os; print os.path.abspath(os.curdir); cwd=. ${result2}= Run Process python -c import os; print os.path.abspath(os.curdir); cwd=..
     Should Not Be Equal    ${result.stdout}    ${result2.stdout}
-
-Setting Stdout
- ${result}= Run Process python -c "print 'hello'" shell=True stdout=%{TEMPDIR}/myfile_1.txt
-    ${output}=    Get File    %{TEMPDIR}/myfile_1.txt
-    Should Not Be Empty    ${output}
-    Should Match  ${output}   ${result.stdout}*
-    [Teardown]    Safe Remove File    %{TEMPDIR}/myfile_1.txt
-
-Setting Stderr
- ${result}= Run Process python -c "1/0" shell=True stderr=%{TEMPDIR}/myfile.txt
-    ${output}=    Get File    %{TEMPDIR}/myfile.txt
-    Should Not Be Empty    ${output}
-    Should Match   ${output}   ${result.stderr}*
-    [Teardown]    Safe Remove File    %{TEMPDIR}/myfile.txt

 Without Env Configuration the Environment Should Be As It Was
     Set Environment Variable  normalvar  normal
@@ -117,51 +103,6 @@
     ${pid_by_handle}=    Get process id    ${handle}
     ${pid_by_alias}=    Get process id    hello
     Should Be Equal    ${pid_by_handle}    ${pid_by_alias}
-
-Redirecting Stderr to Stdout
- ${result}= Run Process python -c print 'hello';1/0 stderr=STDOUT
-    Should Match    ${result.stdout}    *hello*
-    Should Match    ${result.stdout}    *ZeroDivisionError*
-    Should Be Equal    ${result.stderr}    ${EMPTY}
-    Should Be Equal    ${result.stdout_path}    ${NONE}
-    Should Be Equal    ${result.stderr_path}    ${NONE}
-
-Redirecting Stderr to Stdout with filename
-    ${path}=    Normalize Path    %{TEMPDIR}/filename.txt
- ${result}= Run Process python -c print 'hello';1/0 stdout=${path} stderr=${path}
-    Should Match    ${result.stdout}    *hello*
-    Should Match    ${result.stdout}    *ZeroDivisionError*
-    Should Match    ${result.stderr}    *hello*
-    Should Match    ${result.stderr}    *ZeroDivisionError*
-    Should Be Equal    ${result.stdout_path}    ${path}
-    Should Be Equal    ${result.stderr_path}    ${path}
-    [Teardown]    Safe Remove File    ${path}
-
-Current working directory should be used with stdout and stderr
-    Create Directory    %{TEMPDIR}/hc
- ${result}= Run Process python -c print 'moon kuu';1/0 cwd=%{TEMPDIR}/hc stdout=myout.txt
-    ...    stderr=myerr.txt
-    ${output}=    Get File    %{TEMPDIR}/hc/myout.txt
-    ${output2}=    Get File    %{TEMPDIR}/hc/myerr.txt
-    Should Match    ${output}    *moon kuu*
-    Should Match    ${output2}    *ZeroDivisionError*
-    [Teardown]    Safe Remove Directory    %{TEMPDIR}/hc
-
-Current working directory should not be used with stdout and stderr when absolute path in use
-    Create Directory    %{TEMPDIR}/hc
-    ${stdout_path}=    Normalize Path    %{TEMPDIR}/stdout.txt
- ${result}= Run Process python -c print 'moon kuu';1/0 cwd=%{TEMPDIR}/hc stdout=${stdout_path}
-    ...    stderr=stderr.txt
-    ${stderr_path}=    Normalize Path    %{TEMPDIR}/hc/stderr.txt
-    ${stdout}=    Get File    ${stdout_path}
-    ${stderr}=    Get File    ${stderr_path}
-    Should Match    ${stdout}    *moon kuu*
-    Should Match    ${stderr}    *ZeroDivisionError*
-    Should Be Equal    ${result.stdout_path}    ${stdout_path}
-    Should Be Equal    ${result.stderr_path}    ${stderr_path}
-    [Teardown]   Run Keywords
-    ...    Safe Remove Directory   %{TEMPDIR}/hc    AND
-    ...    Safe Remove File    ${stdout_path}

 *** Keywords ***
 Restart Suite Process If Needed
=======================================
--- /atest/testdata/standard_libraries/process/resource.txt Tue Jan 28 09:20:00 2014 UTC +++ /atest/testdata/standard_libraries/process/resource.txt Tue Jan 28 22:16:40 2014 UTC
@@ -2,6 +2,11 @@
 Library           Process
 Library           OperatingSystem

+*** Variables ***
+${STDOUT}         %{TEMPDIR}/process-stdout-file.txt
+${STDERR}         %{TEMPDIR}/process-stderr-file.txt
+${CWD}            %{TEMPDIR}/process-cwd
+
 *** Keywords ***
 Some process
     [Arguments]    ${alias}=${null}
@@ -18,15 +23,23 @@

 Result should equal
     [Arguments]    ${result}    ${stdout}=    ${stderr}=    ${rc}=0
-    Should Be Equal    ${result.stdout}    ${stdout}
-    Should Be Equal    ${result.stderr}    ${stderr}
-    Should Be Equal As Integers    ${result.rc}    ${rc}
+    ...    ${stdout_path}=    ${stderr_path}=
+    Should Be Equal    ${result.stdout}    ${stdout}    stdout:
+    Should Be Equal    ${result.stderr}    ${stderr}    stderr
+ Result should match ${result} * * ${rc} ${stdout_path} ${stderr_path}

 Result should match
     [Arguments]    ${result}    ${stdout}=    ${stderr}=    ${rc}=0
-    Should Match    ${result.stdout}    ${stdout}
-    Should Match    ${result.stderr}    ${stderr}
-    Should Be Equal As Integers    ${result.rc}    ${rc}
+    ...    ${stdout_path}=    ${stderr_path}=
+    Should Match    ${result.stdout}    ${stdout}    stdout
+    Should Match    ${result.stderr}    ${stderr}    stderr
+    Should Be Equal As Integers    ${result.rc}    ${rc}    rc
+    ${stdout_path} =    Run Keyword If    "${stdout_path}"
+    ...    Normalize Path    ${stdout_path}
+    ${stderr_path} =    Run Keyword If    "${stderr_path}"
+    ...    Normalize Path    ${stderr_path}
+ Should Be Equal ${result.stdout_path} ${stdout_path} stdout_path + Should Be Equal ${result.stderr_path} ${stderr_path} stderr_path

 Start Python Process
[Arguments] ${command} ${alias}=${NONE} ${stdout}=${NONE} ${stderr}=${NONE}
@@ -43,8 +56,8 @@
 Safe Remove File
     [Documentation]    Ignore errors caused by process being locked.
     ...                That happens at least with IronPython.
-    [Arguments]    ${path}
-    Run Keyword And Ignore Error    Remove File    ${path}
+    [Arguments]    @{paths}
+    Run Keyword And Ignore Error    Remove Files    @{paths}

 Safe Remove Directory
     [Arguments]    ${path}
=======================================
--- /src/robot/libraries/Process.py     Tue Jan 28 16:58:11 2014 UTC
+++ /src/robot/libraries/Process.py     Tue Jan 28 22:16:40 2014 UTC
@@ -736,7 +736,7 @@
                  alias=None, env=None, **rest):
         self.cwd = self._get_cwd(cwd)
         self.stdout_stream = self._new_stream(stdout)
-        self.stderr_stream = self._get_stderr(stderr, stdout)
+ self.stderr_stream = self._get_stderr(stderr, stdout, self.stdout_stream)
         self.shell = is_true(shell)
         self.alias = alias
         self.env = self._construct_env(env, rest)
@@ -752,12 +752,11 @@
             return open(os.path.join(self.cwd, name), 'w')
         return subprocess.PIPE

-    def _get_stderr(self, stderr, stdout):
-        if stderr:
-            if stderr == 'STDOUT' or stderr == stdout:
-                if self.stdout_stream == subprocess.PIPE:
-                    return subprocess.STDOUT
-                return self.stdout_stream
+    def _get_stderr(self, stderr, stdout, stdout_stream):
+        if stderr and stderr in ['STDOUT', stdout]:
+            if stdout_stream != subprocess.PIPE:
+                return stdout_stream
+            return subprocess.STDOUT
         return self._new_stream(stderr)

     def _construct_env(self, env, extra):

==============================================================================
Revision: 9f01ec56cd9c
Branch:   default
Author:   Pekka Klärck
Date:     Tue Jan 28 23:10:45 2014 UTC
Log: Process: Fixed failures reading custom streams with Jython on Windows

Flush and close custom streams before opening them for reading.

Update issue 1640
Status: Done
Fixed with tests both for writing a lot of output and for writing many times in a for loop. The former test actually was there already, but it used to be disabled with Jython.
http://code.google.com/p/robotframework/source/detail?r=9f01ec56cd9c

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

=======================================
--- /atest/robot/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 22:16:40 2014 UTC +++ /atest/robot/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 23:10:45 2014 UTC
@@ -30,3 +30,12 @@

 Cwd does not affect absolute custom streams
     Check Test Case    ${TESTNAME}
+
+Lot of output to custom stream
+    Check Test Case    ${TESTNAME}
+
+Run multiple times
+    Check Test Case    ${TESTNAME}
+
+Run multiple times using custom streams
+    Check Test Case    ${TESTNAME}
=======================================
--- /atest/robot/standard_libraries/process/terminate_and_pid.txt Tue Jan 28 09:20:00 2014 UTC +++ /atest/robot/standard_libraries/process/terminate_and_pid.txt Tue Jan 28 23:10:45 2014 UTC
@@ -42,6 +42,3 @@

 Getting PIDs in different ways should give same result
     Check Test Case    ${TESTNAME}
-
-Lot of output
-    Check Test Case    ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 22:16:40 2014 UTC +++ /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 23:10:45 2014 UTC
@@ -44,14 +44,39 @@
${result} = Run Stdout Stderr Process cwd=${CWD} stdout=${STDOUT} stderr=${STDERR} Result Should Equal ${result} stdout stderr stdout_path=${STDOUT} stderr_path=${STDERR}
     [Teardown]    Safe Remove Directory    ${CWD}
+
+Lot of output to custom stream
+    [Tags]    performance
+ ${result}= Run Process python -c "for i in xrange(100000):\tprint 'a'*99" shell=True stdout=${STDOUT}
+    Length Should Be    ${result.stdout}    9999999
+    File Should Not Be Empty    ${STDOUT}
+
+Run multiple times
+    [Tags]    performance
+    :FOR    ${i}    IN RANGE    42
+    \   Run And Test Once    ${i}
+
+Run multiple times using custom streams
+    [Tags]    performance
+    :FOR    ${i}    IN RANGE    42
+    \   Run And Test Once    ${i}    ${STDOUT}    ${STDERR}
+

 *** Keywords ***
 Run Stdout Stderr Process
     [Arguments]    ${stdout}=${NONE}    ${stderr}=${NONE}    ${cwd}=${NONE}
+    ...    ${stdout_content}=stdout    ${stderr_content}=stderr
     ${code} =    Catenate    SEPARATOR=;
     ...    import sys
-    ...    sys.stdout.write('stdout')
-    ...    sys.stderr.write('stderr')
+    ...    sys.stdout.write('${stdout_content}')
+    ...    sys.stderr.write('${stderr_content}')
     ${result} =    Run Process    python    -c    ${code}
     ...    stdout=${stdout}    stderr=${stderr}    cwd=${cwd}
     [Return]    ${result}
+
+Run And Test Once
+    [Arguments]    ${content}    ${stdout}=${NONE}    ${stderr}=${NONE}
+ ${result} = Run Stdout Stderr Process stdout=${stdout} stderr=${stderr}
+    ...    stdout_content=out-${content}    stderr_content=err-${content}
+    Should Be Equal   ${result.stdout}    out-${content}
+    Should Be Equal   ${result.stderr}    err-${content}
=======================================
--- /atest/testdata/standard_libraries/process/terminate_and_pid.txt Tue Jan 28 09:20:00 2014 UTC +++ /atest/testdata/standard_libraries/process/terminate_and_pid.txt Tue Jan 28 23:10:45 2014 UTC
@@ -98,10 +98,3 @@
     ${pid3}=      Get Process Id   ${handle}
     Should Be Equal As Integers   ${pid1}   ${pid2}
     Should Be Equal As Integers   ${pid1}   ${pid3}
-
-Lot of output
-    [Tags]    performance
-    ${stdout}=    Normalize Path    %{TEMPDIR}/stdout.txt
- ${handle}= Run Process python -c "for i in range(350000): \tprint 'a'*400" shell=True stdout=${stdout} stderr=STDOUT
-    File Should Not Be Empty    ${stdout}
-    [Teardown]    Safe Remove File    ${stdout}
=======================================
--- /src/robot/libraries/Process.py     Tue Jan 28 22:16:40 2014 UTC
+++ /src/robot/libraries/Process.py     Tue Jan 28 23:10:45 2014 UTC
@@ -687,6 +687,8 @@

     def __init__(self, process, stdout, stderr, rc=None):
         self._process = process
+        self._stdout_stream = stdout
+        self._stderr_stream = stderr
         self.stdout_path = self._get_path(stdout)
         self.stderr_path = self._get_path(stderr)
         self.rc = rc
@@ -694,13 +696,15 @@
         self._stderr = None

     def _get_path(self, stream):
-        if stream in (subprocess.PIPE, subprocess.STDOUT):
-            return None
-        return stream.name
+        return stream.name if self._is_custom_stream(stream) else None
+
+    def _is_custom_stream(self, stream):
+        return stream not in (subprocess.PIPE, subprocess.STDOUT)

     @property
     def stdout(self):
         if self._stdout is None:
+            self._close_stream(self._stdout_stream)
             self._stdout = self._read_stream(self.stdout_path,
                                              self._process.stdout)
         return self._stdout
@@ -708,10 +712,16 @@
     @property
     def stderr(self):
         if self._stderr is None:
+            self._close_stream(self._stderr_stream)
             self._stderr = self._read_stream(self.stderr_path,
                                              self._process.stderr)
         return self._stderr

+    def _close_stream(self, stream):
+        if self._is_custom_stream(stream) and not stream.closed:
+            stream.flush()
+            stream.close()
+
     def _read_stream(self, stream_path, stream):
         if stream_path:
             stream = open(stream_path, 'r')

--

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