Skip to content

Commit 828aaaa

Browse files
avivkelleraduh95
authored andcommitted
test: switch from deprecated optparse to argparse
PR-URL: #58224 Reviewed-By: Luigi Pinca <[email protected]>
1 parent 342b5a0 commit 828aaaa

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

tools/test.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from __future__ import print_function
3232
from typing import Dict
3333
import logging
34-
import optparse
34+
import argparse
3535
import os
3636
import re
3737
import signal
@@ -1369,84 +1369,84 @@ def ReadConfigurationInto(path, sections, defs):
13691369

13701370

13711371
def BuildOptions():
1372-
result = optparse.OptionParser()
1373-
result.add_option("-m", "--mode", help="The test modes in which to run (comma-separated)",
1372+
result = argparse.ArgumentParser()
1373+
result.add_argument("-m", "--mode", help="The test modes in which to run (comma-separated)",
13741374
default='release')
1375-
result.add_option("-v", "--verbose", help="Verbose output",
1375+
result.add_argument("-v", "--verbose", help="Verbose output",
13761376
default=False, action="store_true")
1377-
result.add_option('--logfile', dest='logfile',
1377+
result.add_argument('--logfile', dest='logfile',
13781378
help='write test output to file. NOTE: this only applies the tap progress indicator')
1379-
result.add_option("-p", "--progress",
1379+
result.add_argument("-p", "--progress",
13801380
help="The style of progress indicator (%s)" % ", ".join(PROGRESS_INDICATORS.keys()),
13811381
choices=list(PROGRESS_INDICATORS.keys()), default="mono")
1382-
result.add_option("--report", help="Print a summary of the tests to be run",
1382+
result.add_argument("--report", help="Print a summary of the tests to be run",
13831383
default=False, action="store_true")
1384-
result.add_option("-s", "--suite", help="A test suite",
1384+
result.add_argument("-s", "--suite", help="A test suite",
13851385
default=[], action="append")
1386-
result.add_option("-t", "--timeout", help="Timeout in seconds",
1387-
default=120, type="int")
1388-
result.add_option("--arch", help='The architecture to run tests for',
1386+
result.add_argument("-t", "--timeout", help="Timeout in seconds",
1387+
default=120, type=int)
1388+
result.add_argument("--arch", help='The architecture to run tests for',
13891389
default='none')
1390-
result.add_option("--snapshot", help="Run the tests with snapshot turned on",
1390+
result.add_argument("--snapshot", help="Run the tests with snapshot turned on",
13911391
default=False, action="store_true")
1392-
result.add_option("--special-command", default=None)
1393-
result.add_option("--node-args", dest="node_args", help="Args to pass through to Node",
1392+
result.add_argument("--special-command", default=None)
1393+
result.add_argument("--node-args", dest="node_args", help="Args to pass through to Node",
13941394
default=[], action="append")
1395-
result.add_option("--expect-fail", dest="expect_fail",
1395+
result.add_argument("--expect-fail", dest="expect_fail",
13961396
help="Expect test cases to fail", default=False, action="store_true")
1397-
result.add_option("--valgrind", help="Run tests through valgrind",
1397+
result.add_argument("--valgrind", help="Run tests through valgrind",
13981398
default=False, action="store_true")
1399-
result.add_option("--worker", help="Run parallel tests inside a worker context",
1399+
result.add_argument("--worker", help="Run parallel tests inside a worker context",
14001400
default=False, action="store_true")
1401-
result.add_option("--check-deopts", help="Check tests for permanent deoptimizations",
1401+
result.add_argument("--check-deopts", help="Check tests for permanent deoptimizations",
14021402
default=False, action="store_true")
1403-
result.add_option("--cat", help="Print the source of the tests",
1403+
result.add_argument("--cat", help="Print the source of the tests",
14041404
default=False, action="store_true")
1405-
result.add_option("--flaky-tests",
1405+
result.add_argument("--flaky-tests",
14061406
help="Regard tests marked as flaky (run|skip|dontcare|keep_retrying)",
14071407
default="run")
1408-
result.add_option("--measure-flakiness",
1408+
result.add_argument("--measure-flakiness",
14091409
help="When a test fails, re-run it x number of times",
1410-
default=0, type="int")
1411-
result.add_option("--skip-tests",
1410+
default=0, type=int)
1411+
result.add_argument("--skip-tests",
14121412
help="Tests that should not be executed (comma-separated)",
14131413
default="")
1414-
result.add_option("--warn-unused", help="Report unused rules",
1414+
result.add_argument("--warn-unused", help="Report unused rules",
14151415
default=False, action="store_true")
1416-
result.add_option("-j", help="The number of parallel tasks to run, 0=use number of cores",
1417-
default=0, type="int")
1418-
result.add_option("-J", help="For legacy compatibility, has no effect",
1416+
result.add_argument("-j", help="The number of parallel tasks to run, 0=use number of cores",
1417+
default=0, type=int)
1418+
result.add_argument("-J", help="For legacy compatibility, has no effect",
14191419
default=False, action="store_true")
1420-
result.add_option("--time", help="Print timing information after running",
1420+
result.add_argument("--time", help="Print timing information after running",
14211421
default=False, action="store_true")
1422-
result.add_option("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests",
1422+
result.add_argument("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests",
14231423
dest="suppress_dialogs", default=True, action="store_true")
1424-
result.add_option("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests",
1424+
result.add_argument("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests",
14251425
dest="suppress_dialogs", action="store_false")
1426-
result.add_option("--shell", help="Path to node executable", default=None)
1427-
result.add_option("--store-unexpected-output",
1426+
result.add_argument("--shell", help="Path to node executable", default=None)
1427+
result.add_argument("--store-unexpected-output",
14281428
help="Store the temporary JS files from tests that fails",
14291429
dest="store_unexpected_output", default=True, action="store_true")
1430-
result.add_option("--no-store-unexpected-output",
1430+
result.add_argument("--no-store-unexpected-output",
14311431
help="Deletes the temporary JS files from tests that fails",
14321432
dest="store_unexpected_output", action="store_false")
1433-
result.add_option("-r", "--run",
1433+
result.add_argument("-r", "--run",
14341434
help="Divide the tests in m groups (interleaved) and run tests from group n (--run=n,m with n < m)",
14351435
default="")
1436-
result.add_option('--temp-dir',
1436+
result.add_argument('--temp-dir',
14371437
help='Optional path to change directory used for tests', default=False)
1438-
result.add_option('--test-root',
1438+
result.add_argument('--test-root',
14391439
help='Optional path to change test directory', dest='test_root', default=None)
1440-
result.add_option('--repeat',
1440+
result.add_argument('--repeat',
14411441
help='Number of times to repeat given tests',
1442-
default=1, type="int")
1443-
result.add_option('--abort-on-timeout',
1442+
default=1, type=int)
1443+
result.add_argument('--abort-on-timeout',
14441444
help='Send SIGABRT instead of SIGTERM to kill processes that time out',
14451445
default=False, action="store_true", dest="abort_on_timeout")
1446-
result.add_option("--type",
1446+
result.add_argument("--type",
14471447
help="Type of build (simple, fips, coverage)",
14481448
default=None)
1449-
result.add_option("--error-reporter",
1449+
result.add_argument("--error-reporter",
14501450
help="use error reporter",
14511451
default=True, action="store_true")
14521452
return result
@@ -1625,7 +1625,7 @@ def get_pointer_compression_state(vm, context):
16251625

16261626
def Main():
16271627
parser = BuildOptions()
1628-
(options, args) = parser.parse_args()
1628+
(options, args) = parser.parse_known_args()
16291629
if not ProcessOptions(options):
16301630
parser.print_help()
16311631
return 1

0 commit comments

Comments
 (0)