| OLD | NEW |
| 1 # Copyright (C) 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2012 Google Inc. All rights reserved. |
| 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 are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 def path_to_generic_test_expectations_file(self): | 65 def path_to_generic_test_expectations_file(self): |
| 66 return '' | 66 return '' |
| 67 | 67 |
| 68 class FakeFactory(object): | 68 class FakeFactory(object): |
| 69 def __init__(self, host, ports): | 69 def __init__(self, host, ports): |
| 70 self.host = host | 70 self.host = host |
| 71 self.ports = {} | 71 self.ports = {} |
| 72 for port in ports: | 72 for port in ports: |
| 73 self.ports[port.name] = port | 73 self.ports[port.name] = port |
| 74 | 74 |
| 75 def get(self, port_name, *args, **kwargs): # pylint: disable=W0613,E0202 | 75 def get(self, port_name='a', *args, **kwargs): # pylint: disable=W0613,E020
2 |
| 76 return self.ports[port_name] | 76 return self.ports[port_name] |
| 77 | 77 |
| 78 def all_port_names(self, platform=None): # pylint: disable=W0613,E0202 | 78 def all_port_names(self, platform=None): # pylint: disable=W0613,E0202 |
| 79 return sorted(self.ports.keys()) | 79 return sorted(self.ports.keys()) |
| 80 | 80 |
| 81 | 81 |
| 82 class LintTest(unittest.TestCase): | 82 class LintTest(unittest.TestCase): |
| 83 def test_all_configurations(self): | 83 def test_all_configurations(self): |
| 84 host = MockHost() | 84 host = MockHost() |
| 85 host.ports_parsed = [] | 85 host.ports_parsed = [] |
| 86 host.port_factory = FakeFactory(host, (FakePort(host, 'a', 'path-to-a'), | 86 host.port_factory = FakeFactory(host, (FakePort(host, 'a', 'path-to-a'), |
| 87 FakePort(host, 'b', 'path-to-b'), | 87 FakePort(host, 'b', 'path-to-b'), |
| 88 FakePort(host, 'b-win', 'path-to-
b'))) | 88 FakePort(host, 'b-win', 'path-to-
b'))) |
| 89 | 89 |
| 90 logging_stream = StringIO.StringIO() | 90 logging_stream = StringIO.StringIO() |
| 91 options = optparse.Values({'platform': None}) | 91 options = optparse.Values({'platform': None}) |
| 92 res = lint_test_expectations.lint(host, options, logging_stream) | 92 logger, handler = lint_test_expectations.set_up_logging(logging_stream) |
| 93 try: |
| 94 res = lint_test_expectations.lint(host, options) |
| 95 finally: |
| 96 lint_test_expectations.tear_down_logging(logger, handler) |
| 93 self.assertEqual(res, 0) | 97 self.assertEqual(res, 0) |
| 94 self.assertEqual(host.ports_parsed, ['a', 'b', 'b-win']) | 98 self.assertEqual(host.ports_parsed, ['a', 'b', 'b-win']) |
| 95 | 99 |
| 96 def test_lint_test_files(self): | 100 def test_lint_test_files(self): |
| 97 logging_stream = StringIO.StringIO() | 101 logging_stream = StringIO.StringIO() |
| 98 options = optparse.Values({'platform': 'test-mac-leopard'}) | 102 options = optparse.Values({'platform': 'test-mac-leopard'}) |
| 99 host = MockHost() | 103 host = MockHost() |
| 100 | 104 |
| 101 # pylint appears to complain incorrectly about the method overrides pyli
nt: disable=E0202,C0322 | 105 # pylint appears to complain incorrectly about the method overrides pyli
nt: disable=E0202,C0322 |
| 102 # FIXME: incorrect complaints about spacing pylint: disable=C0322 | 106 # FIXME: incorrect complaints about spacing pylint: disable=C0322 |
| 103 host.port_factory.all_port_names = lambda platform=None: [platform] | 107 host.port_factory.all_port_names = lambda platform=None: [platform] |
| 104 | 108 |
| 105 res = lint_test_expectations.lint(host, options, logging_stream) | 109 logger, handler = lint_test_expectations.set_up_logging(logging_stream) |
| 110 try: |
| 111 res = lint_test_expectations.lint(host, options) |
| 112 self.assertEqual(res, 0) |
| 113 finally: |
| 114 lint_test_expectations.tear_down_logging(logger, handler) |
| 106 | 115 |
| 107 self.assertEqual(res, 0) | |
| 108 self.assertIn('Lint succeeded', logging_stream.getvalue()) | |
| 109 | 116 |
| 110 def test_lint_test_files__errors(self): | 117 def test_lint_test_files__errors(self): |
| 111 options = optparse.Values({'platform': 'test', 'debug_rwt_logging': Fals
e}) | 118 options = optparse.Values({'platform': 'test', 'debug_rwt_logging': Fals
e}) |
| 112 host = MockHost() | 119 host = MockHost() |
| 113 | 120 |
| 114 # FIXME: incorrect complaints about spacing pylint: disable=C0322 | 121 # FIXME: incorrect complaints about spacing pylint: disable=C0322 |
| 115 port = host.port_factory.get(options.platform, options=options) | 122 port = host.port_factory.get(options.platform, options=options) |
| 116 port.expectations_dict = lambda: {'foo': '-- syntax error1', 'bar': '--
syntax error2'} | 123 port.expectations_dict = lambda: {'foo': '-- syntax error1', 'bar': '--
syntax error2'} |
| 117 | 124 |
| 118 host.port_factory.get = lambda platform, options=None: port | 125 host.port_factory.get = lambda platform, options=None: port |
| 119 host.port_factory.all_port_names = lambda platform=None: [port.name()] | 126 host.port_factory.all_port_names = lambda platform=None: [port.name()] |
| 120 | 127 |
| 121 logging_stream = StringIO.StringIO() | 128 logging_stream = StringIO.StringIO() |
| 129 logger, handler = lint_test_expectations.set_up_logging(logging_stream) |
| 130 try: |
| 131 res = lint_test_expectations.lint(host, options) |
| 132 finally: |
| 133 lint_test_expectations.tear_down_logging(logger, handler) |
| 122 | 134 |
| 123 res = lint_test_expectations.lint(host, options, logging_stream) | 135 self.assertTrue(res) |
| 124 | |
| 125 self.assertEqual(res, -1) | |
| 126 self.assertIn('Lint failed', logging_stream.getvalue()) | |
| 127 self.assertIn('foo:1', logging_stream.getvalue()) | 136 self.assertIn('foo:1', logging_stream.getvalue()) |
| 128 self.assertIn('bar:1', logging_stream.getvalue()) | 137 self.assertIn('bar:1', logging_stream.getvalue()) |
| 129 | 138 |
| 130 | 139 |
| 140 class CheckVirtualSuiteTest(unittest.TestCase): |
| 141 def test_check_virtual_test_suites(self): |
| 142 host = MockHost() |
| 143 options = optparse.Values({'platform': 'test', 'debug_rwt_logging': Fals
e}) |
| 144 orig_get = host.port_factory.get |
| 145 host.port_factory.get = lambda options: orig_get('test', options=options
) |
| 146 |
| 147 logging_stream = StringIO.StringIO() |
| 148 logger, handler = lint_test_expectations.set_up_logging(logging_stream) |
| 149 try: |
| 150 res = lint_test_expectations.check_virtual_test_suites(host, options
) |
| 151 self.assertTrue(res) |
| 152 |
| 153 host.filesystem.exists = lambda path: True |
| 154 res = lint_test_expectations.check_virtual_test_suites(host, options
) |
| 155 self.assertFalse(res) |
| 156 finally: |
| 157 lint_test_expectations.tear_down_logging(logger, handler) |
| 158 |
| 159 |
| 131 class MainTest(unittest.TestCase): | 160 class MainTest(unittest.TestCase): |
| 161 # unused args pylint: disable=W0613 |
| 162 |
| 163 def setUp(self): |
| 164 self.orig_lint_fn = lint_test_expectations.lint |
| 165 self.orig_check_fn = lint_test_expectations.check_virtual_test_suites |
| 166 lint_test_expectations.check_virtual_test_suites = lambda host, options:
False |
| 167 |
| 168 self.stdout = StringIO.StringIO() |
| 169 self.stderr = StringIO.StringIO() |
| 170 |
| 171 def tearDown(self): |
| 172 lint_test_expectations.lint = self.orig_lint_fn |
| 173 lint_test_expectations.check_virtual_test_suites = self.orig_check_fn |
| 174 |
| 132 def test_success(self): | 175 def test_success(self): |
| 133 orig_lint_fn = lint_test_expectations.lint | 176 lint_test_expectations.lint = lambda host, options: False |
| 177 res = lint_test_expectations.main(['--platform', 'test'], self.stdout, s
elf.stderr) |
| 178 self.assertTrue('Lint succeeded' in self.stderr.getvalue()) |
| 179 self.assertEqual(res, 0) |
| 134 | 180 |
| 135 # unused args pylint: disable=W0613 | 181 def test_failure(self): |
| 136 def interrupting_lint(host, options, logging_stream): | 182 lint_test_expectations.lint = lambda host, options: True |
| 183 res = lint_test_expectations.main(['--platform', 'test'], self.stdout, s
elf.stderr) |
| 184 self.assertTrue('Lint failed' in self.stderr.getvalue()) |
| 185 self.assertEqual(res, 1) |
| 186 |
| 187 def test_interrupt(self): |
| 188 def interrupting_lint(host, options): |
| 137 raise KeyboardInterrupt | 189 raise KeyboardInterrupt |
| 138 | 190 |
| 139 def successful_lint(host, options, logging_stream): | 191 lint_test_expectations.lint = interrupting_lint |
| 140 return 0 | 192 res = lint_test_expectations.main([], self.stdout, self.stderr) |
| 193 self.assertEqual(res, lint_test_expectations.INTERRUPTED_EXIT_STATUS) |
| 141 | 194 |
| 142 def exception_raising_lint(host, options, logging_stream): | 195 def test_exception(self): |
| 196 def exception_raising_lint(host, options): |
| 143 assert False | 197 assert False |
| 144 | 198 lint_test_expectations.lint = exception_raising_lint |
| 145 stdout = StringIO.StringIO() | 199 res = lint_test_expectations.main([], self.stdout, self.stderr) |
| 146 stderr = StringIO.StringIO() | 200 self.assertEqual(res, lint_test_expectations.EXCEPTIONAL_EXIT_STATUS) |
| 147 try: | |
| 148 lint_test_expectations.lint = interrupting_lint | |
| 149 res = lint_test_expectations.main([], stdout, stderr) | |
| 150 self.assertEqual(res, lint_test_expectations.INTERRUPTED_EXIT_STATUS
) | |
| 151 | |
| 152 lint_test_expectations.lint = successful_lint | |
| 153 res = lint_test_expectations.main(['--platform', 'test'], stdout, st
derr) | |
| 154 self.assertEqual(res, 0) | |
| 155 | |
| 156 lint_test_expectations.lint = exception_raising_lint | |
| 157 res = lint_test_expectations.main([], stdout, stderr) | |
| 158 self.assertEqual(res, lint_test_expectations.EXCEPTIONAL_EXIT_STATUS
) | |
| 159 finally: | |
| 160 lint_test_expectations.lint = orig_lint_fn | |
| OLD | NEW |