Changeset 2817


Ignore:
Timestamp:
04/28/12 08:23:02 (2 years ago)
Author:
wehart
Message:

Adding tests to validate that subprocess output is captured, and that it can be tee'd
to two streams.

Referencing sys.stdout to get encoding info, since sys.stdout might be
overwritten.

Location:
pyutilib.subprocess/trunk/pyutilib/subprocess
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • pyutilib.subprocess/trunk/pyutilib/subprocess/processmngr.py

    r2816 r2817  
    117117    while True: 
    118118        data = os.read(stream, 80) 
    119         if sys.stdout.encoding is None: 
     119        if sys.__stdout__.encoding is None: 
    120120            data = data.decode('utf-8') 
    121121        else: 
    122             data = data.decode(sys.stdout.encoding) 
     122            data = data.decode(sys.__stdout__.encoding) 
    123123        if data: 
    124124            ostr1.write(data) 
    125             #ostr2.write(data) 
     125            ostr2.write(data) 
    126126            ostr1.flush() 
    127             #ostr2.flush() 
     127            ostr2.flush() 
    128128        else: 
    129129            break 
     
    286286        if sys.version_info >= (3,0): 
    287287            import io 
    288             if sys.stdout.encoding is None: 
     288            if sys.__stdout__.encoding is None: 
    289289                encoding = 'utf-8' 
    290290            else: 
  • pyutilib.subprocess/trunk/pyutilib/subprocess/tests/test_subprocess.py

    r2813 r2817  
    6868        os.remove(currdir+'valgrind.out') 
    6969         
     70    def test_outputfile(self): 
     71        pyutilib.subprocess.run([sys.executable, currdir+"tee_script.py"], outfile=currdir+'tee.out') 
     72        self.assertFileEqualsBaseline(currdir+'tee.out', currdir+'tee.txt') 
     73 
     74    def test_tee(self): 
     75        pyutilib.misc.setup_redirect(currdir+'tee.stream') 
     76        output = pyutilib.subprocess.run([sys.executable, currdir+"tee_script.py"], outfile=currdir+'tee.out', tee=True) 
     77        pyutilib.misc.reset_redirect() 
     78        self.assertFileEqualsBaseline(currdir+'tee.out', currdir+'tee.txt') 
     79 
    7080 
    7181if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.