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

Side by Side Diff: tools/json_schema_compiler/dart_generator_test.py

Issue 12218151: Added unit tests for the Dart Chrome.* API wrappers. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added --rebase flag, and removed calls to shell Created 7 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import sys
8 import unittest
9 import glob
10
11 from dart_generator import DartGenerator
12 from compiler import generate_schema
13
14 # If --rebase is passed to this test, this is set to True, indicating the test
15 # output should be re-generated for each test (rather than running the tests
16 # themselves).
17 REBASE_MODE = False
18
19 class DartTest(unittest.TestCase):
20
21 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.
22 '''Given the name of a test, runs compiler.py on the file:
23 <test_dir>/test_filename.idl
24 and compares it to the output in the file:
25 <test_dir>/test_filename.dart
26
27 The default |test_dir| location can be overwritten by passing in the new
28 location.
29 '''
30 file_rel = os.path.join(tests_dir, test_filename)
31
32 output_dir = None
33 if REBASE_MODE:
34 output_dir = tests_dir
35 output_code = generate_schema('dart', ['%s.idl' % file_rel], tests_dir,
36 output_dir, None, None)
37
38 if not REBASE_MODE:
39 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.
40 # Remove the first line of the output code (as it contains the filename).
41 # Also remove all blank lines, ignoring them from the comparison.
42 # Compare with lists instead of strings for clearer diffs (especially with
43 # whitespace) when a test fails.
44 self.assertListEqual([l for l in expected_output.split('\n') if l],
45 [l for l in output_code.split('\n')[1:] if l])
46
47 def setUp(self):
48 # Increase the maximum diff amount to see the full diff on a failed test.
49 self.maxDiff = 2000
50
51 def testBasicEvent(self):
52 self._RunTest('basic_event')
53
54 def testBasicFunction(self):
55 self._RunTest('basic_function')
56
57 def testBasicType(self):
58 self._RunTest('basic_type')
59
60 def testComments(self):
61 self._RunTest('comments')
62
63 def testComplexType(self):
64 self._RunTest('complex_type')
65
66 def testEmptyNamespace(self):
67 self._RunTest('empty_namespace')
68
69 def testEmptyType(self):
70 self._RunTest('empty_type')
71
72 def testOpratableType(self):
73 self._RunTest('operatable_type')
74
75 def testTags(self):
76 self._RunTest('tags')
77
78 if __name__ == '__main__':
79 if '--rebase' in sys.argv:
80 print ("About to run in rebase mode - all expected test output will be "
81 "overwritten.")
82 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.
83 if cont.lower() == 'y':
84 print "Running in rebase mode."
85 REBASE_MODE = True
86 sys.argv.remove('--rebase')
87 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698