コード例 #1
0
 def test_max_seconds(self):
     if sys.platform.startswith('win'):
         cmd = 'ping -w 5000 -n 1 1.0.0.0 > NUL'
     else:
         cmd = 'sleep 5000'
     code, out, err = run(cmd, maxSeconds=2, stopOnError=False)
     self.assertEquals(code, -2)
コード例 #2
0
 def test_max_seconds(self):
     if sys.platform.startswith('win'):
         cmd = 'ping -w 5000 -n 1 1.0.0.0 > NUL'
     else:
         cmd = 'sleep 5000'
     code, out, err = run(cmd, maxSeconds=2, stopOnError=False)
     self.assertEquals(code, -2)
コード例 #3
0
    def test_max_seconds_output(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world && ping -w 4000 -n 1 1.0.0.0 > NUL'
        else:
            cmd = '%s -n "Hello world"; sleep 5000' % ECHO
        code, out, err = run(cmd, maxSeconds=2, stopOnError=False)

        if sys.platform.startswith('win'):
            out = out.rstrip()

        self.assertEquals(code, -2)
        self.assertEquals(out, 'Hello world')
コード例 #4
0
    def test_stderr(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world >&2'
        else:
            cmd = '%s -n "Hello world" > /dev/stderr' % ECHO
        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            err = err.rstrip()

        self.assertEquals(code, 0)
        self.assertEquals(out, '')
        self.assertEquals(err, 'Hello world')
コード例 #5
0
    def test_stderr(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world >&2'
        else:
            cmd = '%s -n "Hello world" > /dev/stderr' % ECHO
        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            err = err.rstrip()

        self.assertEquals(code, 0)
        self.assertEquals(out, '')
        self.assertEquals(err, 'Hello world')
コード例 #6
0
    def test_max_seconds_output(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world && ping -w 4000 -n 1 1.0.0.0 > NUL'
        else:
            cmd = '%s -n "Hello world"; sleep 5000' % ECHO
        code, out, err = run(cmd, maxSeconds=2,
                stopOnError=False)

        if sys.platform.startswith('win'):
            out = out.rstrip()

        self.assertEquals(code, -2)
        self.assertEquals(out, 'Hello world')
コード例 #7
0
    def test_stdout(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world'
        else:
            cmd = '%s -n "Hello world"' % ECHO
        code, out, err = run(cmd)
        self.assertEquals(code, 0)

        if sys.platform.startswith('win'):
            out = out.rstrip()

        self.assertEquals(out, 'Hello world')
        self.assertEquals(err, '')
コード例 #8
0
    def test_stdout(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world'
        else:
            cmd = '%s -n "Hello world"' % ECHO
        code, out, err = run(cmd)
        self.assertEquals(code, 0)

        if sys.platform.startswith('win'):
            out = out.rstrip()

        self.assertEquals(out, 'Hello world')
        self.assertEquals(err, '')
コード例 #9
0
    def test_simple(self):
        if sys.platform.startswith('win'):
            cmd = 'echo.'
        else:
            cmd = '%s -n' % ECHO
        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            #'echo' on win32 outputs at least a newline
            out = out.rstrip()

        self.assertEquals(code, 0)
        self.assertEquals(out, '')
        self.assertEquals(err, '')
コード例 #10
0
    def test_stdout_multiline(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world&& echo Beautiful world'
        else:
            cmd = r'%s -e "Hello world\nBeautiful world"' % ECHO

        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            out = out.replace('\r\n', '\n')

        self.assertEquals(code, 0)
        self.assertEquals(out, 'Hello world\nBeautiful world\n')
        self.assertEquals(err, '')
コード例 #11
0
    def _run_exit_test(self, *args, **kwargs):
        l = list()

        def exit(code):
            l.append(code)

        oldexit = sys.exit
        sys.exit = exit

        code, out, err = run(*args, **kwargs)

        sys.exit = oldexit

        return l[0]
コード例 #12
0
    def _run_exit_test(self, *args, **kwargs):
        l = list()

        def exit(code):
            l.append(code)

        oldexit = sys.exit
        sys.exit = exit

        code, out, err = run(*args, **kwargs)

        sys.exit = oldexit

        return l[0]
コード例 #13
0
    def test_simple(self):
        if sys.platform.startswith('win'):
            cmd = 'echo.'
        else:
            cmd = '%s -n' % ECHO
        code, out, err = run(cmd)

        if  sys.platform.startswith('win'):
            #'echo' on win32 outputs at least a newline
            out = out.rstrip()

        self.assertEquals(code, 0)
        self.assertEquals(out, '')
        self.assertEquals(err, '')
コード例 #14
0
    def test_stdout_multiline(self):
        if sys.platform.startswith('win'):
            cmd = 'echo Hello world&& echo Beautiful world'
        else:
            cmd = r'%s -e "Hello world\nBeautiful world"' % ECHO

        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            out = out.replace('\r\n', '\n')

        self.assertEquals(code, 0)
        self.assertEquals(out, 'Hello world\nBeautiful world\n')
        self.assertEquals(err, '')
コード例 #15
0
    def _execute_test(self, user=None, group=None):
        code, out, _ = run('id', stopOnError=False, user=user, group=group)

        self.assertEquals(code, 0)

        def get_name(s):
            return s.split('(')[1].rstrip(')')

        if user:
            name = get_name(out.split()[0])
            self.assertEquals(name, self.USER)

        if group:
            name = get_name(out.split()[1])
            self.assertEquals(name, self.GROUP)
コード例 #16
0
    def _execute_test(self, user=None, group=None):
        code, out, _ = run('id', stopOnError=False, user=user, group=group)

        self.assertEquals(code, 0)

        def get_name(s):
            return s.split('(')[1].rstrip(')')

        if user:
            name = get_name(out.split()[0])
            self.assertEquals(name, self.USER)

        if group:
            name = get_name(out.split()[1])
            self.assertEquals(name, self.GROUP)
コード例 #17
0
    def test_stdout_stderr(self):
        if sys.platform.startswith('win'):
            cmd = 'echo out && echo err >&2'
        else:
            cmd = '%(echo)s -n "out";' \
                  '%(echo)s -n "err" > /dev/stderr' % \
                  {'echo': ECHO}

        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            out = out.rstrip()
            err = err.rstrip()

        self.assertEquals(code, 0)
        self.assertEquals(out, 'out')
        self.assertEquals(err, 'err')
コード例 #18
0
    def test_stdout_stderr(self):
        if sys.platform.startswith('win'):
            cmd = 'echo out && echo err >&2'
        else:
            cmd = '%(echo)s -n "out";' \
                  '%(echo)s -n "err" > /dev/stderr' % \
                  {'echo': ECHO}

        code, out, err = run(cmd)

        if sys.platform.startswith('win'):
            out = out.rstrip()
            err = err.rstrip()

        self.assertEquals(code, 0)
        self.assertEquals(out, 'out')
        self.assertEquals(err, 'err')
コード例 #19
0
 def test_long_running(self):
     if sys.platform.startswith('win'):
         run('ping -w 2000 -n 1 1.0.0.0 > NUL', stopOnError=False)
     else:
         run('sleep 2')
コード例 #20
0
 def test_run(self):
     cmd = 'yes | head -n2'
     output = run(cmd)
     self.assertEquals(output, (0, 'y\ny\n', ''))
コード例 #21
0
 def test_exitcode(self):
     code, out, err = run('exit 123', stopOnError=False)
     self.assertEquals(code, 123)
     self.assertEquals(out, '')
     self.assertEquals(err, '')
コード例 #22
0
 def test_run_python_execute_command(self):
     for run_ in xrange(20):
         cmd = '%s -uc "from pylabs.InitBase import q; q.system.process.execute(\'echo %d\', useShell=True)"' \
             % (sys.executable, run_)
         run(cmd)
コード例 #23
0
 def test_run(self):
     cmd = 'yes | head -n2'
     output = run(cmd)
     self.assertEquals(output, (0, 'y\ny\n', ''))
コード例 #24
0
 def test_long_running(self):
     if sys.platform.startswith('win'):
         run('ping -w 2000 -n 1 1.0.0.0 > NUL', stopOnError=False)
     else:
         run('sleep 2')
コード例 #25
0
 def test_run_python_execute_command(self):
     for run_ in xrange(20):
         cmd = '%s -uc "from pylabs.InitBase import q; q.system.process.execute(\'echo %d\', useShell=True)"' \
             % (sys.executable, run_)
         run(cmd)
コード例 #26
0
 def test_exitcode(self):
     code, out, err = run('exit 123', stopOnError=False)
     self.assertEquals(code, 123)
     self.assertEquals(out, '')
     self.assertEquals(err, '')