Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1604)

Unified Diff: native_client_sdk/src/tools/lib/tests/quote_test.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/tools/httpd.py ('k') | native_client_sdk/src/tools/nacl_config.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tools/lib/tests/quote_test.py
diff --git a/native_client_sdk/src/tools/lib/tests/quote_test.py b/native_client_sdk/src/tools/lib/tests/quote_test.py
index fe0e6c36059956dcf253367f0acc97882541c2f4..a14f186e4e0c2d6677a1e6167ef46557c85ded50 100755
--- a/native_client_sdk/src/tools/lib/tests/quote_test.py
+++ b/native_client_sdk/src/tools/lib/tests/quote_test.py
@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import optparse
+import argparse
import os
import sys
import unittest
@@ -92,53 +92,51 @@ class TestQuote(unittest.TestCase):
# Invoke this file directly for simple manual testing. For running
# the unittests, use the -t flag. Any flags to be passed to the
-# unittest module should be passed as after the optparse processing,
+# unittest module should be passed as after the argparse processing,
# e.g., "quote_test.py -t -- -v" to pass the -v flag to the unittest
# module.
-def main(argv):
+def main(args):
global verbose
- parser = optparse.OptionParser(
- usage='Usage: %prog [options] word...')
- parser.add_option('-s', '--special-chars', dest='special_chars', default=':',
- help='Special characters to quote (default is ":")')
- parser.add_option('-q', '--quote', dest='quote', default='\\',
- help='Quote or escape character (default is "\")')
- parser.add_option('-t', '--run-tests', dest='tests', action='store_true',
- help='Run built-in tests\n')
- parser.add_option('-u', '--unquote-input', dest='unquote_input',
- action='store_true', help='Unquote command line argument')
- parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
- help='Verbose test output')
- options, args = parser.parse_args(argv)
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-s', '--special-chars',
+ dest='special_chars', default=':',
+ help='Special characters to quote (default is ":")')
+ parser.add_argument('-q', '--quote', dest='quote', default='\\',
+ help='Quote or escape character (default is "\")')
+ parser.add_argument('-u', '--unquote-input', dest='unquote_input',
+ action='store_true', help='Unquote command line argument')
+ parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
+ help='Verbose test output')
+ parser.add_argument('words', nargs='*')
+ options = parser.parse_args(args)
if options.verbose:
verbose = True
- num_errors = 0
- if options.tests:
- sys.argv = [sys.argv[0]] + args
+ if not options.words:
unittest.main()
- else:
- for word in args:
- # NB: there are inputs x for which quote(unquote(x) != x, but
- # there should be no input x for which unquote(quote(x)) != x.
- if options.unquote_input:
- qq = quote.unquote(word, options.special_chars, options.quote)
- sys.stdout.write('unquote(%s) = %s\n'
- % (word, ''.join(qq)))
- # There is no expected output for unquote -- this is just for
- # manual testing, so it is okay that we do not (and cannot)
- # update num_errors here.
- else:
- q = quote.quote(word, options.special_chars, options.quote)
- qq = quote.unquote(q, options.special_chars, options.quote)
- sys.stdout.write('quote(%s) = %s, unquote(%s) = %s\n'
- % (word, q, q, ''.join(qq)))
- if word != ''.join(qq):
- num_errors += 1
- if num_errors > 0:
- sys.stderr.write('[ FAILED ] %d test failures\n' % num_errors)
+
+ num_errors = 0
+ for word in options.words:
+ # NB: there are inputs x for which quote(unquote(x) != x, but
+ # there should be no input x for which unquote(quote(x)) != x.
+ if options.unquote_input:
+ qq = quote.unquote(word, options.special_chars, options.quote)
+ sys.stdout.write('unquote(%s) = %s\n'
+ % (word, ''.join(qq)))
+ # There is no expected output for unquote -- this is just for
+ # manual testing, so it is okay that we do not (and cannot)
+ # update num_errors here.
+ else:
+ q = quote.quote(word, options.special_chars, options.quote)
+ qq = quote.unquote(q, options.special_chars, options.quote)
+ sys.stdout.write('quote(%s) = %s, unquote(%s) = %s\n'
+ % (word, q, q, ''.join(qq)))
+ if word != ''.join(qq):
+ num_errors += 1
+ if num_errors > 0:
+ sys.stderr.write('[ FAILED ] %d test failures\n' % num_errors)
return num_errors
if __name__ == '__main__':
« no previous file with comments | « native_client_sdk/src/tools/httpd.py ('k') | native_client_sdk/src/tools/nacl_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698