Index: tools/json_schema_compiler/dart_generator_test.py |
diff --git a/tools/json_schema_compiler/dart_generator_test.py b/tools/json_schema_compiler/dart_generator_test.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..cf719fe099ea5b39bfd1e935b3eb2bfa7d6eeea9 |
--- /dev/null |
+++ b/tools/json_schema_compiler/dart_generator_test.py |
@@ -0,0 +1,87 @@ |
+#!/usr/bin/env python |
+# 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. |
+ |
+import os |
+import sys |
+import unittest |
+import glob |
+ |
+from dart_generator import DartGenerator |
+from compiler import generate_schema |
+ |
+# If --rebase is passed to this test, this is set to True, indicating the test |
+# output should be re-generated for each test (rather than running the tests |
+# themselves). |
+REBASE_MODE = False |
+ |
+class DartTest(unittest.TestCase): |
+ |
+ def _RunTest(self, test_filename, tests_dir='dart_test'): |
not at google - send to devlin
2013/02/20 03:02:33
this tests_dir thing is never used as a parameter
sashab
2013/02/20 03:26:19
Done.
|
+ '''Given the name of a test, runs compiler.py on the file: |
+ <test_dir>/test_filename.idl |
+ and compares it to the output in the file: |
+ <test_dir>/test_filename.dart |
+ |
+ The default |test_dir| location can be overwritten by passing in the new |
+ location. |
+ ''' |
+ file_rel = os.path.join(tests_dir, test_filename) |
+ |
+ output_dir = None |
+ if REBASE_MODE: |
+ output_dir = tests_dir |
+ output_code = generate_schema('dart', ['%s.idl' % file_rel], tests_dir, |
+ output_dir, None, None) |
+ |
+ if not REBASE_MODE: |
+ expected_output = open('%s.dart' % file_rel).read() |
not at google - send to devlin
2013/02/20 03:02:33
Should be closing files here, this function is run
sashab
2013/02/20 03:26:19
Done.
|
+ # Remove the first line of the output code (as it contains the filename). |
+ # Also remove all blank lines, ignoring them from the comparison. |
+ # Compare with lists instead of strings for clearer diffs (especially with |
+ # whitespace) when a test fails. |
+ self.assertListEqual([l for l in expected_output.split('\n') if l], |
+ [l for l in output_code.split('\n')[1:] if l]) |
+ |
+ def setUp(self): |
+ # Increase the maximum diff amount to see the full diff on a failed test. |
+ self.maxDiff = 2000 |
+ |
+ def testBasicEvent(self): |
+ self._RunTest('basic_event') |
+ |
+ def testBasicFunction(self): |
+ self._RunTest('basic_function') |
+ |
+ def testBasicType(self): |
+ self._RunTest('basic_type') |
+ |
+ def testComments(self): |
+ self._RunTest('comments') |
+ |
+ def testComplexType(self): |
+ self._RunTest('complex_type') |
+ |
+ def testEmptyNamespace(self): |
+ self._RunTest('empty_namespace') |
+ |
+ def testEmptyType(self): |
+ self._RunTest('empty_type') |
+ |
+ def testOpratableType(self): |
+ self._RunTest('operatable_type') |
+ |
+ def testTags(self): |
+ self._RunTest('tags') |
+ |
+if __name__ == '__main__': |
+ if '--rebase' in sys.argv: |
+ print ("About to run in rebase mode - all expected test output will be " |
+ "overwritten.") |
+ cont = raw_input("Are you sure you wish to continue? Y/[N] ") |
not at google - send to devlin
2013/02/20 03:02:33
I don't think a confirmation is necessary. It's an
sashab
2013/02/20 03:26:19
Done. Still printed a message to be clear.
|
+ if cont.lower() == 'y': |
+ print "Running in rebase mode." |
+ REBASE_MODE = True |
+ sys.argv.remove('--rebase') |
+ unittest.main() |