def test_quality(self): """ Test basic scenarios, including special characters that would appear in JavaScript and mixed quotation marks """ # Patch the output of `jshint` return_string = '\n' + dedent(""" ../test_file.js: line 3, col 9, Missing "use strict" statement. ../test_file.js: line 10, col 17, '$hi' is defined but never used. """).strip() + '\n' self.subproc_mock.communicate.return_value = ( (return_string.encode('utf-8'), b'')) self._mock_communicate.return_value = self.subproc_mock # Parse the report quality = JsHintQualityReporter('jshint', []) # Expect that the name is set self.assertEqual(quality.name(), 'jshint') # Measured_lines is undefined for # a quality reporter since all lines are measured self.assertEqual(quality.measured_lines('../blah.js'), None) # Expect that we get the right violations expected_violations = [ Violation(3, 'Missing "use strict" statement.'), Violation(10, "'$hi' is defined but never used."), ] self.assertEqual(expected_violations, quality.violations('../test_file.js'))
def test_quality_error(self): # Override the subprocess return code to a failure self.subproc_mock.returncode = 1 # Patch the output of `jshint` self.subproc_mock.communicate.return_value = (b"", 'whoops Ƕئ'.encode('utf-8')) self._mock_communicate.return_value = self.subproc_mock # Parse the report quality = JsHintQualityReporter('jshint', []) # Expect that the name is set self.assertEqual(quality.name(), 'jshint') with self.assertRaises(QualityReporterError) as ex: quality.violations('file1.js') self.assertEqual(six.text_type(ex.exception), 'whoops Ƕئ')