示例#1
0
 def test_args(self,d):
     path = d.write('test.py','\n'.join((
             "import sys",
             "print sys.argv",
             )),path=True)
     compare(("[%r, 'x=1', '--y=2', 'a', 'b']\n" % path,0),
             both(sys.executable+' '+path+' x=1 --y=2 a b'))
示例#2
0
 def test_popen_params(self):
     m = Mock()
     m.Popen.return_value = m.Popeni
     m.Popeni.communicate.return_value=('','')
     with Replacer() as r:
         r.replace('execute.Popen',m.Popen)
         both('something')
     compare(m.method_calls,[
             ('Popen',
              ('something',),
              {'cwd': None,
               'shell': True,
               'stderr': STDOUT,
               'stdout': PIPE,
               'universal_newlines': True}),
             ('Popeni.communicate', (), {})
             ])
示例#3
0
 def test_out_and_err(self,d):
     # without the flushes, the order comes out wrong
     path = d.write('test.py','\n'.join((
             "import sys",
             "sys.stdout.write('stdout\\n')",
             "sys.stdout.flush()",
             "sys.stderr.write('stderr\\n')",
             "sys.stderr.flush()",
             "sys.stdout.write('stdout2\\n')",
             "sys.stdout.flush()",
             )),path=True)
     compare(('stdout\nstderr\nstdout2\n',0),
             both(sys.executable+' '+path))
示例#4
0
    def test_working_directory(self,d):
        dir = d.makedir('a_dir',path=True)
        path = d.write('test.py','\n'.join((
                "import os",
                "print os.getcwd()",
                )),path=True)

        # tempdirs on Mac OS X give a different path
        # after you've os.chdir's into them!
        cur = os.getcwd()
        try:
            os.chdir(dir)
            expected = os.getcwd()+'\n',0
        finally:
            os.chdir(cur)
            
        compare(expected,
                both(sys.executable+' '+path,cwd=dir))