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

Unified Diff: build/copy_test_data.py

Issue 10790008: Adds a way to specify test data files for unittests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updates. Created 8 years, 5 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 | « build/copy_test_data.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/copy_test_data.py
diff --git a/build/copy_test_data.py b/build/copy_test_data.py
new file mode 100755
index 0000000000000000000000000000000000000000..feb12e5cf4410656d1384fa00754fbfe8f89ad3b
--- /dev/null
+++ b/build/copy_test_data.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
pkl (ping after 24h if needed) 2012/07/16 17:15:34 google3 python files do *not* require shebang line
+# Copyright (c) 2012 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.
+
+"""Copies test data files into an iOS app bundle."""
+
+import optparse
+import os
+import shutil
+import sys
+
+class WrongNumberOfArgumentsException(Exception):
+ pass
+
+def ExpandFilesForPath(path):
+ output = []
+ # Files get returned without modification.
+ if not os.path.isdir(path):
+ output.append(path)
+ return output
+
+ # Directories get recursively expanded.
+ contents = os.listdir(path)
+ for item in contents:
+ full_path = os.path.join(path, item)
+ output.extend(ExpandFilesForPath(full_path))
+ return output
+
+def CalcInputs(inputs):
+ # Inputs is a list of possibly-space-separated strings. Break apart the list
pkl (ping after 24h if needed) 2012/07/16 17:15:34 Use triple-" for function doc strings.
+ # and tokenize the string.
+ output = []
+ for input in inputs:
+ tokens = input.split()
+ for token in tokens:
+ output.extend(ExpandFilesForPath(token))
+ return output
+
+def CopyFiles(relative_filenames, output_basedir):
+ for file in relative_filenames:
+ relative_dirname = os.path.dirname(file)
pkl (ping after 24h if needed) 2012/07/16 17:15:34 indent 2
+ output_dir = os.path.join(output_basedir, relative_dirname)
+ if not os.path.exists(output_dir):
+ os.makedirs(output_dir)
+ output_filename = os.path.join(output_basedir, file)
+ shutil.copy(file, output_filename)
+
+def DoMain(argv):
+ parser = optparse.OptionParser()
+ usage = 'Usage: %prog -o <output_dir> [--inputs] [--outputs] <input_files>'
+ parser.set_usage(usage)
+ parser.add_option('-o', dest='output_dir')
+ parser.add_option('--inputs', action='store_true', dest='list_inputs')
+ parser.add_option('--outputs', action='store_true', dest='list_outputs')
+ options, arglist = parser.parse_args(argv)
+
+ if len(arglist) == 0:
+ raise WrongNumberOfArgumentsException("<input_files> required.")
pkl (ping after 24h if needed) 2012/07/16 17:15:34 single quote strings.
+
+ files_to_copy = CalcInputs(arglist)
+ if options.list_inputs:
+ return '\n'.join(files_to_copy)
+
+ if not options.output_dir:
+ raise WrongNumberOfArgumentsException("-o required.")
+
+ if options.list_outputs:
+ outputs = [os.path.join(options.output_dir, x) for x in files_to_copy]
+ return '\n'.join(outputs)
+
+ CopyFiles(files_to_copy, options.output_dir)
+ return 0
+
+def main(argv):
+ try:
+ result = DoMain(argv[1:])
+ except WrongNumberOfArguments, e:
+ print >>sys.stderr, e
+ return 1
+ print result
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « build/copy_test_data.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698