Commit 192e8a67 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

subprocess2: Rewrite tests to be Python 3 compatible.

Also replace mox with mock and move the test script to a different file.

Bug: 984182
Change-Id: I9005a523c2abd82c38a7c61501c7cbfd4201a5b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1745412Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent b4fc338b
#!/usr/bin/env python
# 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.write(string.upper())
sys.stdout.write(options.eol)
if options.stderr:
sys.stderr.write(string.lower())
sys.stderr.write(options.eol)
do('A')
do('BB')
do('CCC')
if options.read:
assert options.return_value is 0
try:
while sys.stdin.read(1):
options.return_value += 1
except OSError:
pass
sys.exit(options.return_value)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment