OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2017 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 js_checker | |
7 import json | |
8 import os | |
9 import sys | |
10 import unittest | |
11 import tempfile | |
12 | |
13 | |
14 _HERE_PATH = os.path.dirname(__file__) | |
15 sys.path.append( | |
16 os.path.join(os.path.dirname(_HERE_PATH), '..', '..')) | |
Dan Beam
2017/05/31 01:40:31
why do we need the dirname() around _HERE_PATH aga
dpapad
2017/05/31 02:49:58
Removed.
| |
17 | |
18 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile | |
19 | |
20 | |
21 class JsCheckerEsLintTest(unittest.TestCase): | |
22 def tearDown(self): | |
23 os.remove(self._tmp_file) | |
24 | |
25 def testGetElementByIdCheck(self): | |
26 with tempfile.NamedTemporaryFile( | |
27 suffix='.js', dir=_HERE_PATH, delete=False) as f: | |
Dan Beam
2017/05/31 01:40:31
arguable nit for prettiness:
tmp_args = {suffix='
dpapad
2017/05/31 02:49:58
Done.
| |
28 self._tmp_file = f.name | |
29 print self._tmp_file | |
Dan Beam
2017/05/31 01:40:31
remove print
dpapad
2017/05/31 02:49:58
Done.
| |
30 f.write('var a = document.getElementById(\'foo\');') | |
31 | |
32 input_api = MockInputApi() | |
33 input_api.files = [MockFile(os.path.abspath(self._tmp_file), '')] | |
34 input_api.presubmitLocalPath = _HERE_PATH | |
35 | |
36 checker = js_checker.JSChecker(input_api, MockOutputApi()) | |
37 results_json = checker.RunEsLintChecks( | |
38 input_api.AffectedFiles(), format='json') | |
39 self.assertEqual(1, len(results_json)) | |
40 | |
41 results = json.loads(results_json[0].message) | |
42 self.assertEqual(1, len(results)) | |
43 | |
44 self.assertEqual(1, len(results[0].get('messages'))) | |
45 message = results[0].get('messages')[0] | |
46 self.assertEqual('no-restricted-properties', message.get('ruleId')) | |
47 self.assertEqual(1, message.get('line')) | |
48 | |
49 | |
50 if __name__ == '__main__': | |
51 unittest.main() | |
OLD | NEW |