| OLD | NEW |
| 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
| 9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
| 10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 self.assertEqual('--min-confidence=3 --output=emacs', | 59 self.assertEqual('--min-confidence=3 --output=emacs', |
| 60 self._printer.to_flag_string(options)) | 60 self._printer.to_flag_string(options)) |
| 61 | 61 |
| 62 | 62 |
| 63 class ArgumentParserTest(LoggingTestCase): | 63 class ArgumentParserTest(LoggingTestCase): |
| 64 | 64 |
| 65 """Test the ArgumentParser class.""" | 65 """Test the ArgumentParser class.""" |
| 66 | 66 |
| 67 class _MockStdErr(object): | 67 class _MockStdErr(object): |
| 68 | 68 |
| 69 def write(self, message): | 69 def write(self, _): |
| 70 # We do not want the usage string or style categories | 70 # We do not want the usage string or style categories |
| 71 # to print during unit tests, so print nothing. | 71 # to print during unit tests, so print nothing. |
| 72 return | 72 return |
| 73 | 73 |
| 74 def _parse(self, args): | 74 def _parse(self, args): |
| 75 """Call a test parser.parse().""" | 75 """Call a test parser.parse().""" |
| 76 parser = self._create_parser() | 76 parser = self._create_parser() |
| 77 return parser.parse(args) | 77 return parser.parse(args) |
| 78 | 78 |
| 79 def _create_defaults(self): | 79 def _create_defaults(self): |
| 80 """Return a DefaultCommandOptionValues instance for testing.""" | 80 """Return a DefaultCommandOptionValues instance for testing.""" |
| 81 base_filter_rules = ["-", "+whitespace"] | |
| 82 return DefaultCommandOptionValues(min_confidence=3, | 81 return DefaultCommandOptionValues(min_confidence=3, |
| 83 output_format="vs7") | 82 output_format="vs7") |
| 84 | 83 |
| 85 def _create_parser(self): | 84 def _create_parser(self): |
| 86 """Return an ArgumentParser instance for testing.""" | 85 """Return an ArgumentParser instance for testing.""" |
| 87 default_options = self._create_defaults() | 86 default_options = self._create_defaults() |
| 88 | 87 |
| 89 all_categories = ["build", "whitespace"] | 88 all_categories = ["build", "whitespace"] |
| 90 | 89 |
| 91 mock_stderr = self._MockStdErr() | 90 mock_stderr = self._MockStdErr() |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 self.assertIsNone(options.git_commit) | 147 self.assertIsNone(options.git_commit) |
| 149 self.assertFalse(options.diff_files) | 148 self.assertFalse(options.diff_files) |
| 150 self.assertFalse(options.is_verbose) | 149 self.assertFalse(options.is_verbose) |
| 151 self.assertEqual(options.min_confidence, 3) | 150 self.assertEqual(options.min_confidence, 3) |
| 152 self.assertEqual(options.output_format, 'vs7') | 151 self.assertEqual(options.output_format, 'vs7') |
| 153 | 152 |
| 154 def test_parse_explicit_arguments(self): | 153 def test_parse_explicit_arguments(self): |
| 155 parse = self._parse | 154 parse = self._parse |
| 156 | 155 |
| 157 # Pass non-default explicit values. | 156 # Pass non-default explicit values. |
| 158 (files, options) = parse(['--min-confidence=4']) | 157 _, options = parse(['--min-confidence=4']) |
| 159 self.assertEqual(options.min_confidence, 4) | 158 self.assertEqual(options.min_confidence, 4) |
| 160 (files, options) = parse(['--output=emacs']) | 159 _, options = parse(['--output=emacs']) |
| 161 self.assertEqual(options.output_format, 'emacs') | 160 self.assertEqual(options.output_format, 'emacs') |
| 162 (files, options) = parse(['-g', 'commit']) | 161 _, options = parse(['-g', 'commit']) |
| 163 self.assertEqual(options.git_commit, 'commit') | 162 self.assertEqual(options.git_commit, 'commit') |
| 164 (files, options) = parse(['--git-commit=commit']) | 163 _, options = parse(['--git-commit=commit']) |
| 165 self.assertEqual(options.git_commit, 'commit') | 164 self.assertEqual(options.git_commit, 'commit') |
| 166 (files, options) = parse(['--git-diff=commit']) | 165 _, options = parse(['--git-diff=commit']) |
| 167 self.assertEqual(options.git_commit, 'commit') | 166 self.assertEqual(options.git_commit, 'commit') |
| 168 (files, options) = parse(['--verbose']) | 167 _, options = parse(['--verbose']) |
| 169 self.assertTrue(options.is_verbose) | 168 self.assertTrue(options.is_verbose) |
| 170 (files, options) = parse(['--diff-files', 'file.txt']) | 169 _, options = parse(['--diff-files', 'file.txt']) |
| 171 self.assertTrue(options.diff_files) | 170 self.assertTrue(options.diff_files) |
| 172 | 171 |
| 173 # Pass user_rules. | 172 # Pass user_rules. |
| 174 (files, options) = parse(['--filter=+build,-whitespace']) | 173 _, options = parse(['--filter=+build,-whitespace']) |
| 175 self.assertEqual(options.filter_rules, | 174 self.assertEqual(options.filter_rules, |
| 176 ["+build", "-whitespace"]) | 175 ["+build", "-whitespace"]) |
| 177 | 176 |
| 178 # Pass spurious white space in user rules. | 177 # Pass spurious white space in user rules. |
| 179 (files, options) = parse(['--filter=+build, -whitespace']) | 178 _, options = parse(['--filter=+build, -whitespace']) |
| 180 self.assertEqual(options.filter_rules, | 179 self.assertEqual(options.filter_rules, |
| 181 ["+build", "-whitespace"]) | 180 ["+build", "-whitespace"]) |
| 182 | 181 |
| 183 def test_parse_files(self): | 182 def test_parse_files(self): |
| 184 parse = self._parse | 183 parse = self._parse |
| 185 | 184 |
| 186 (files, options) = parse(['foo.cpp']) | 185 files, _ = parse(['foo.cpp']) |
| 187 self.assertEqual(files, ['foo.cpp']) | 186 self.assertEqual(files, ['foo.cpp']) |
| 188 | 187 |
| 189 # Pass multiple files. | 188 # Pass multiple files. |
| 190 (files, options) = parse(['--output=emacs', 'foo.cpp', 'bar.cpp']) | 189 files, _ = parse(['--output=emacs', 'foo.cpp', 'bar.cpp']) |
| 191 self.assertEqual(files, ['foo.cpp', 'bar.cpp']) | 190 self.assertEqual(files, ['foo.cpp', 'bar.cpp']) |
| 192 | 191 |
| 193 | 192 |
| 194 class CommandOptionValuesTest(unittest.TestCase): | 193 class CommandOptionValuesTest(unittest.TestCase): |
| 195 | 194 |
| 196 """Tests CommandOptionValues class.""" | 195 """Tests CommandOptionValues class.""" |
| 197 | 196 |
| 198 def test_init(self): | 197 def test_init(self): |
| 199 """Test __init__ constructor.""" | 198 """Test __init__ constructor.""" |
| 200 # Check default parameters. | 199 # Check default parameters. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 self.assertFalse(options.__eq__(ProcessorOptions(is_verbose=True))) | 247 self.assertFalse(options.__eq__(ProcessorOptions(is_verbose=True))) |
| 249 self.assertFalse(options.__eq__(ProcessorOptions(min_confidence=2))) | 248 self.assertFalse(options.__eq__(ProcessorOptions(min_confidence=2))) |
| 250 self.assertFalse(options.__eq__(ProcessorOptions(output_format="vs7"))) | 249 self.assertFalse(options.__eq__(ProcessorOptions(output_format="vs7"))) |
| 251 | 250 |
| 252 def test_ne(self): | 251 def test_ne(self): |
| 253 """Test __ne__ inequality function.""" | 252 """Test __ne__ inequality function.""" |
| 254 # By default, __ne__ always returns true on different objects. | 253 # By default, __ne__ always returns true on different objects. |
| 255 # Thus, just check the distinguishing case to verify that the | 254 # Thus, just check the distinguishing case to verify that the |
| 256 # code defines __ne__. | 255 # code defines __ne__. |
| 257 self.assertFalse(ProcessorOptions().__ne__(ProcessorOptions())) | 256 self.assertFalse(ProcessorOptions().__ne__(ProcessorOptions())) |
| OLD | NEW |