Skip to content

Commit 029440b

Browse files
avivkellertargos
authored andcommitted
test: switch from deprecated optparse to argparse
PR-URL: #58224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8df4dee commit 029440b

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
@@ -1378,84 +1378,84 @@ def ReadConfigurationInto(path, sections, defs):
13781378

13791379

13801380
def BuildOptions():
1381-
result = optparse.OptionParser()
1382-
result.add_option("-m", "--mode", help="The test modes in which to run (comma-separated)",
1381+
result = argparse.ArgumentParser()
1382+
result.add_argument("-m", "--mode", help="The test modes in which to run (comma-separated)",
13831383
default='release')
1384-
result.add_option("-v", "--verbose", help="Verbose output",
1384+
result.add_argument("-v", "--verbose", help="Verbose output",
13851385
default=False, action="store_true")
1386-
result.add_option('--logfile', dest='logfile',
1386+
result.add_argument('--logfile', dest='logfile',
13871387
help='write test output to file. NOTE: this only applies the tap progress indicator')
1388-
result.add_option("-p", "--progress",
1388+
result.add_argument("-p", "--progress",
13891389
help="The style of progress indicator (%s)" % ", ".join(PROGRESS_INDICATORS.keys()),
13901390
choices=list(PROGRESS_INDICATORS.keys()), default="mono")
1391-
result.add_option("--report", help="Print a summary of the tests to be run",
1391+
result.add_argument("--report", help="Print a summary of the tests to be run",
13921392
default=False, action="store_true")
1393-
result.add_option("-s", "--suite", help="A test suite",
1393+
result.add_argument("-s", "--suite", help="A test suite",
13941394
default=[], action="append")
1395-
result.add_option("-t", "--timeout", help="Timeout in seconds",
1396-
default=120, type="int")
1397-
result.add_option("--arch", help='The architecture to run tests for',
1395+
result.add_argument("-t", "--timeout", help="Timeout in seconds",
1396+
default=120, type=int)
1397+
result.add_argument("--arch", help='The architecture to run tests for',
13981398
default='none')
1399-
result.add_option("--snapshot", help="Run the tests with snapshot turned on",
1399+
result.add_argument("--snapshot", help="Run the tests with snapshot turned on",
14001400
default=False, action="store_true")
1401-
result.add_option("--special-command", default=None)
1402-
result.add_option("--node-args", dest="node_args", help="Args to pass through to Node",
1401+
result.add_argument("--special-command", default=None)
1402+
result.add_argument("--node-args", dest="node_args", help="Args to pass through to Node",
14031403
default=[], action="append")
1404-
result.add_option("--expect-fail", dest="expect_fail",
1404+
result.add_argument("--expect-fail", dest="expect_fail",
14051405
help="Expect test cases to fail", default=False, action="store_true")
1406-
result.add_option("--valgrind", help="Run tests through valgrind",
1406+
result.add_argument("--valgrind", help="Run tests through valgrind",
14071407
default=False, action="store_true")
1408-
result.add_option("--worker", help="Run parallel tests inside a worker context",
1408+
result.add_argument("--worker", help="Run parallel tests inside a worker context",
14091409
default=False, action="store_true")
1410-
result.add_option("--check-deopts", help="Check tests for permanent deoptimizations",
1410+
result.add_argument("--check-deopts", help="Check tests for permanent deoptimizations",
14111411
default=False, action="store_true")
1412-
result.add_option("--cat", help="Print the source of the tests",
1412+
result.add_argument("--cat", help="Print the source of the tests",
14131413
default=False, action="store_true")
1414-
result.add_option("--flaky-tests",
1414+
result.add_argument("--flaky-tests",
14151415
help="Regard tests marked as flaky (run|skip|dontcare|keep_retrying)",
14161416
default="run")
1417-
result.add_option("--measure-flakiness",
1417+
result.add_argument("--measure-flakiness",
14181418
help="When a test fails, re-run it x number of times",
1419-
default=0, type="int")
1420-
result.add_option("--skip-tests",
1419+
default=0, type=int)
1420+
result.add_argument("--skip-tests",
14211421
help="Tests that should not be executed (comma-separated)",
14221422
default="")
1423-
result.add_option("--warn-unused", help="Report unused rules",
1423+
result.add_argument("--warn-unused", help="Report unused rules",
14241424
default=False, action="store_true")
1425-
result.add_option("-j", help="The number of parallel tasks to run, 0=use number of cores",
1426-
default=0, type="int")
1427-
result.add_option("-J", help="For legacy compatibility, has no effect",
1425+
result.add_argument("-j", help="The number of parallel tasks to run, 0=use number of cores",
1426+
default=0, type=int)
1427+
result.add_argument("-J", help="For legacy compatibility, has no effect",
14281428
default=False, action="store_true")
1429-
result.add_option("--time", help="Print timing information after running",
1429+
result.add_argument("--time", help="Print timing information after running",
14301430
default=False, action="store_true")
1431-
result.add_option("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests",
1431+
result.add_argument("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests",
14321432
dest="suppress_dialogs", default=True, action="store_true")
1433-
result.add_option("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests",
1433+
result.add_argument("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests",
14341434
dest="suppress_dialogs", action="store_false")
1435-
result.add_option("--shell", help="Path to node executable", default=None)
1436-
result.add_option("--store-unexpected-output",
1435+
result.add_argument("--shell", help="Path to node executable", default=None)
1436+
result.add_argument("--store-unexpected-output",
14371437
help="Store the temporary JS files from tests that fails",
14381438
dest="store_unexpected_output", default=True, action="store_true")
1439-
result.add_option("--no-store-unexpected-output",
1439+
result.add_argument("--no-store-unexpected-output",
14401440
help="Deletes the temporary JS files from tests that fails",
14411441
dest="store_unexpected_output", action="store_false")
1442-
result.add_option("-r", "--run",
1442+
result.add_argument("-r", "--run",
14431443
help="Divide the tests in m groups (interleaved) and run tests from group n (--run=n,m with n < m)",
14441444
default="")
1445-
result.add_option('--temp-dir',
1445+
result.add_argument('--temp-dir',
14461446
help='Optional path to change directory used for tests', default=False)
1447-
result.add_option('--test-root',
1447+
result.add_argument('--test-root',
14481448
help='Optional path to change test directory', dest='test_root', default=None)
1449-
result.add_option('--repeat',
1449+
result.add_argument('--repeat',
14501450
help='Number of times to repeat given tests',
1451-
default=1, type="int")
1452-
result.add_option('--abort-on-timeout',
1451+
default=1, type=int)
1452+
result.add_argument('--abort-on-timeout',
14531453
help='Send SIGABRT instead of SIGTERM to kill processes that time out',
14541454
default=False, action="store_true", dest="abort_on_timeout")
1455-
result.add_option("--type",
1455+
result.add_argument("--type",
14561456
help="Type of build (simple, fips, coverage)",
14571457
default=None)
1458-
result.add_option("--error-reporter",
1458+
result.add_argument("--error-reporter",
14591459
help="use error reporter",
14601460
default=True, action="store_true")
14611461
return result
@@ -1634,7 +1634,7 @@ def get_pointer_compression_state(vm, context):
16341634

16351635
def Main():
16361636
parser = BuildOptions()
1637-
(options, args) = parser.parse_args()
1637+
(options, args) = parser.parse_known_args()
16381638
if not ProcessOptions(options):
16391639
parser.print_help()
16401640
return 1

0 commit comments

Comments
 (0)