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

Side by Side Diff: tools/web_dev_style/js_checker_eslint_test.py

Issue 2917473002: js_checker.py: Restore smoke tests for linting violations. (Closed)
Patch Set: Nits. Created 3 years, 6 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
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
12 sys.path.append(
13 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))
Dan Beam 2017/05/30 23:11:09 indent is weird (should only be 4 \s for continuat
dpapad 2017/05/31 01:30:06 Done.
14
15 from PRESUBMIT_test_mocks import (MockInputApi, MockOutputApi)
Dan Beam 2017/05/30 23:11:09 nit: do you need the parens around the module name
dpapad 2017/05/31 01:30:06 Done.
16
17 class JsCheckerEsLintTest(unittest.TestCase):
18 def setUp(self):
19 self._tmp_files = []
20
21
Dan Beam 2017/05/30 23:11:09 only \n (not \n\n) between these. \n\n is only fo
dpapad 2017/05/31 01:30:06 Done.
22 def tearDown(self):
23 for tmp_file in self._tmp_files:
24 os.remove(tmp_file)
Dan Beam 2017/05/30 23:11:09 arguable nit: map(os.remove, self._tmp_files)
dpapad 2017/05/31 01:30:06 Not needed anymore.
25
26
27 def _create_tmp_file(self, file_contents):
28 # Temp files need to be under src/ such that src/.eslintrc.js takes effect.
29 _HERE_PATH = os.path.dirname(__file__)
Dan Beam 2017/05/30 23:11:09 can we combine both __file__ references in a globa
dpapad 2017/05/31 01:30:06 Done.
30 with open(os.path.join(_HERE_PATH, 'tmp_eslint_test.js'), 'w') as f:
31 self._tmp_files.append(f.name)
Dan Beam 2017/05/30 23:12:27 why do we need an array still?
dpapad 2017/05/31 01:30:06 Removed the array.
32 f.write(file_contents)
33 return f
34
35
36 def testGetElementByIdCheck(self):
37 checker = js_checker.JSChecker(MockInputApi(), MockOutputApi())
38 tmp = self._create_tmp_file('var a = document.getElementById(\'foo\');')
39
40 resultsJson = checker.RunEsLintChecks([tmp.name], format='json')
Dan Beam 2017/05/30 23:11:09 results_json https://engdoc.corp.google.com/eng/d
dpapad 2017/05/31 01:30:06 Done.
41 self.assertEqual(1, len(resultsJson))
42
43 results = json.loads(resultsJson[0].message)
44 self.assertEqual(1, len(results))
45
46 self.assertEqual(1, len(results[0].get('messages')))
47 message = results[0].get('messages')[0]
48 self.assertEqual('no-restricted-properties', message.get('ruleId'))
49 self.assertEqual(1, message.get('line'))
50
51
52 if __name__ == '__main__':
53 unittest.main()
OLDNEW
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698