File: subprocess2_test_script.py

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (60 lines) | stat: -rw-r--r-- 1,775 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# Copyright (c) 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Script used to test subprocess2."""

import optparse
import os
import sys
import time

if sys.platform == 'win32':
    # Annoying, make sure the output is not translated on Windows.
    # pylint: disable=no-member,import-error
    import msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)

parser = optparse.OptionParser()
parser.add_option('--fail',
                  dest='return_value',
                  action='store_const',
                  default=0,
                  const=64)
parser.add_option('--crlf',
                  action='store_const',
                  const='\r\n',
                  dest='eol',
                  default='\n')
parser.add_option('--cr', action='store_const', const='\r', dest='eol')
parser.add_option('--stdout', action='store_true')
parser.add_option('--stderr', action='store_true')
parser.add_option('--read', action='store_true')
options, args = parser.parse_args()
if args:
    parser.error('Internal error')


def do(string):
    if options.stdout:
        sys.stdout.buffer.write(string.upper().encode('utf-8'))
        sys.stdout.buffer.write(options.eol.encode('utf-8'))
    if options.stderr:
        sys.stderr.buffer.write(string.lower().encode('utf-8'))
        sys.stderr.buffer.write(options.eol.encode('utf-8'))
        sys.stderr.flush()


do('A')
do('BB')
do('CCC')
if options.read:
    assert options.return_value == 0
    try:
        while sys.stdin.read(1):
            options.return_value += 1
    except OSError:
        pass

sys.exit(options.return_value)