OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 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 argparse |
| 7 import os |
| 8 import unittest |
| 9 |
| 10 from compile_modules import ModuleCompiler |
| 11 |
| 12 |
| 13 def rel_to_abs(rel_path): |
| 14 script_path = os.path.dirname(os.path.abspath(__file__)) |
| 15 return os.path.join(script_path, rel_path) |
| 16 |
| 17 |
| 18 module_file = os.path.join('tests', 'test.resources') |
| 19 |
| 20 |
| 21 class CodingConventionTest(unittest.TestCase): |
| 22 def __init__(self, *args, **kwargs): |
| 23 unittest.TestCase.__init__(self, *args, **kwargs) |
| 24 self.maxDiff = None |
| 25 |
| 26 def setUp(self): |
| 27 self.module_compiler = ModuleCompiler(verbose=opts.verbose, |
| 28 test_expected_output=True) |
| 29 |
| 30 def testCodingConvention(self): |
| 31 modules = self.module_compiler.get_modules(rel_to_abs(module_file)) |
| 32 |
| 33 for m in modules: |
| 34 assert len(m.sources) == 1 |
| 35 s = m.sources[0] |
| 36 output = self.module_compiler.compile_source(s, m).strip() |
| 37 expected_output = m.expected_output.strip().split('\n') |
| 38 for line in expected_output: |
| 39 self.assertTrue(line in output, |
| 40 msg='{}\n\nExpected line: \n{}\n\nOutput:\n{}\n'.format( |
| 41 m.name, line, output)) |
| 42 |
| 43 |
| 44 if __name__ == '__main__': |
| 45 parser = argparse.ArgumentParser() |
| 46 parser.add_argument("-v", "--verbose", action="store_true", |
| 47 help="Show more information as this script runs") |
| 48 opts = parser.parse_args() |
| 49 |
| 50 unittest.main() |
OLD | NEW |