def test_lint_with_json_output(self): """ Tests the top-level linting with JSON summary format. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': False, 'verbose': False, 'rule_totals': True, 'summary_format': 'json', 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() assert re.search( 'test\\.py.*{}'.format(self.ruleset.python_wrap_html.rule_id), output) is not None # Find something that looks like pretty-printed JSON json_match = re.search(r'\n\{.*\n\}', output, re.DOTALL) assert json_match is not None data = json.loads(json_match.group()) # Check for rule counts (including zero-instance ones) and total assert 1 == data['rules']['javascript-concat-html'] assert 0 == data['rules']['python-concat-html'] assert 5 == data['total']
def test_lint_with_list_files(self): """ Tests the top-level linting with list files option. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': True, 'verbose': False, 'rule_totals': False, 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() # Assert file with rule is not output. self.assertIsNone( re.search( r'test\.py.*{}'.format(self.ruleset.python_wrap_html.rule_id), output)) # Assert file is output. self.assertIsNotNone(re.search(r'test\.py', output)) # Assert no totals. self.assertIsNone( re.search( r'{}:\s*{} violations'.format( self.ruleset.python_parse_error.rule_id, 0), output)) self.assertIsNone(re.search(r'{} violations total'.format(7), output))
def test_lint_with_verbose(self): """ Tests the top-level linting with verbose option. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': False, 'verbose': True, 'rule_totals': False, 'summary_format': 'eslint', 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() lines_with_rule = 0 lines_without_rule = 0 # Output with verbose setting only. for underscore_match in re.finditer(r'test\.underscore:.*\n', output): if re.search(self.ruleset.underscore_not_escaped.rule_id, underscore_match.group()) is not None: lines_with_rule += 1 else: lines_without_rule += 1 assert lines_with_rule >= 1 assert lines_without_rule >= 1 # Assert no rule totals. assert re.search( '{}:\\s*{} violations'.format( self.ruleset.python_parse_error.rule_id, 0), output) is None # Assert final total assert re.search('{} violations total'.format(5), output) is not None
def test_lint_with_rule_totals(self): """ Tests the top-level linting with rule totals option. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': False, 'verbose': False, 'rule_totals': True, 'summary_format': 'eslint', 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() assert re.search( 'test\\.py.*{}'.format(self.ruleset.python_wrap_html.rule_id), output) is not None # Assert totals output. assert re.search( '{}:\\s*{} violations'.format( self.ruleset.python_parse_error.rule_id, 0), output) is not None assert re.search( '{}:\\s*{} violations'.format( self.ruleset.python_wrap_html.rule_id, 1), output) is not None assert re.search('{} violations total'.format(5), output) is not None
def test_lint_with_verbose(self): """ Tests the top-level linting with verbose option. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': False, 'verbose': True, 'rule_totals': False, 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() lines_with_rule = 0 lines_without_rule = 0 # Output with verbose setting only. for underscore_match in re.finditer('test\.underscore:.*\n', output): if re.search(self.ruleset.underscore_not_escaped.rule_id, underscore_match.group()) is not None: lines_with_rule += 1 else: lines_without_rule += 1 self.assertGreaterEqual(lines_with_rule, 1) self.assertGreaterEqual(lines_without_rule, 1) # Assert no rule totals. self.assertIsNone(re.search('{}:\s*{} violations'.format(self.ruleset.python_parse_error.rule_id, 0), output)) # Assert final total self.assertIsNotNone(re.search('{} violations total'.format(7), output))
def test_lint_with_list_files(self): """ Tests the top-level linting with list files option. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': True, 'verbose': False, 'rule_totals': False, 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() # Assert file with rule is not output. self.assertIsNone(re.search('test\.py.*{}'.format(self.ruleset.python_wrap_html.rule_id), output)) # Assert file is output. self.assertIsNotNone(re.search('test\.py', output)) # Assert no totals. self.assertIsNone(re.search('{}:\s*{} violations'.format(self.ruleset.python_parse_error.rule_id, 0), output)) self.assertIsNone(re.search('{} violations total'.format(7), output))
def test_lint_defaults(self): """ Tests the top-level linting with default options. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': False, 'verbose': False, 'rule_totals': False, 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() # Assert violation details are displayed. self.assertIsNotNone( re.search( r'test\.html.*{}'.format( self.ruleset.mako_missing_default.rule_id), output)) self.assertIsNotNone( re.search( r'test\.js.*{}'.format( self.ruleset.javascript_concat_html.rule_id), output)) self.assertIsNotNone( re.search( r'test\.js.*{}'.format( self.ruleset.underscore_not_escaped.rule_id), output)) lines_with_rule = 0 lines_without_rule = 0 # Output with verbose setting only. for underscore_match in re.finditer(r'test\.underscore:.*\n', output): if re.search(self.ruleset.underscore_not_escaped.rule_id, underscore_match.group()) is not None: lines_with_rule += 1 else: lines_without_rule += 1 self.assertGreaterEqual(lines_with_rule, 1) self.assertEqual(lines_without_rule, 0) self.assertIsNone( re.search( r'test\.py.*{}'.format( self.ruleset.python_parse_error.rule_id), output)) self.assertIsNotNone( re.search( r'test\.py.*{}'.format(self.ruleset.python_wrap_html.rule_id), output)) # Assert no rule totals. self.assertIsNone( re.search( r'{}:\s*{} violations'.format( self.ruleset.python_parse_error.rule_id, 0), output)) # Assert final total self.assertIsNotNone( re.search(r'{} violations total'.format(5), output))
def test_lint_with_verbose(self): """ Tests the top-level linting with verbose option. """ out = StringIO() summary_results = SummaryResults() _lint( 'scripts/xsslint/tests/templates', template_linters=self._build_linters(), options={ 'list_files': False, 'verbose': True, 'rule_totals': False, 'skip_dirs': () }, summary_results=summary_results, out=out, ) output = out.getvalue() lines_with_rule = 0 lines_without_rule = 0 # Output with verbose setting only. for underscore_match in re.finditer('test\.underscore:.*\n', output): if re.search(Rules.underscore_not_escaped.rule_id, underscore_match.group()) is not None: lines_with_rule += 1 else: lines_without_rule += 1 self.assertGreaterEqual(lines_with_rule, 1) self.assertGreaterEqual(lines_without_rule, 1) # Assert no rule totals. self.assertIsNone( re.search( '{}:\s*{} violations'.format(Rules.python_parse_error.rule_id, 0), output)) # Assert final total self.assertIsNotNone(re.search('{} violations total'.format(7), output))
def test_lint_defaults(self): """ Tests the top-level linting with default options. """ _lint( 'scripts/xsslint/tests/templates', template_linters=self.template_linters, options={ 'list_files': False, 'verbose': False, 'rule_totals': False, 'skip_dirs': () }, summary_results=self.summary_results, out=self.out, ) output = self.out.getvalue() # Assert violation details are displayed. self.assertIsNotNone(re.search('test\.html.*{}'.format(self.ruleset.mako_missing_default.rule_id), output)) self.assertIsNotNone(re.search('test\.js.*{}'.format(self.ruleset.javascript_concat_html.rule_id), output)) self.assertIsNotNone(re.search('test\.js.*{}'.format(self.ruleset.underscore_not_escaped.rule_id), output)) lines_with_rule = 0 lines_without_rule = 0 # Output with verbose setting only. for underscore_match in re.finditer('test\.underscore:.*\n', output): if re.search(self.ruleset.underscore_not_escaped.rule_id, underscore_match.group()) is not None: lines_with_rule += 1 else: lines_without_rule += 1 self.assertGreaterEqual(lines_with_rule, 1) self.assertEquals(lines_without_rule, 0) self.assertIsNone(re.search('test\.py.*{}'.format(self.ruleset.python_parse_error.rule_id), output)) self.assertIsNotNone(re.search('test\.py.*{}'.format(self.ruleset.python_wrap_html.rule_id), output)) # Assert no rule totals. self.assertIsNone(re.search('{}:\s*{} violations'.format(self.ruleset.python_parse_error.rule_id, 0), output)) # Assert final total self.assertIsNotNone(re.search('{} violations total'.format(7), output))
def test_lint_with_rule_totals(self): """ Tests the top-level linting with rule totals option. """ out = StringIO() summary_results = SummaryResults() _lint( 'scripts/xsslint/tests/templates', template_linters=self._build_linters(), options={ 'list_files': False, 'verbose': False, 'rule_totals': True, 'skip_dirs': () }, summary_results=summary_results, out=out, ) output = out.getvalue() self.assertIsNotNone( re.search('test\.py.*{}'.format(Rules.python_wrap_html.rule_id), output)) # Assert totals output. self.assertIsNotNone( re.search( '{}:\s*{} violations'.format(Rules.python_parse_error.rule_id, 0), output)) self.assertIsNotNone( re.search( '{}:\s*{} violations'.format(Rules.python_wrap_html.rule_id, 1), output)) self.assertIsNotNone(re.search('{} violations total'.format(7), output))