From ea6530e7df95852270a3210bcc5cc5b6a4a7961c Mon Sep 17 00:00:00 2001 From: Evandro Flores Date: Tue, 29 Jul 2014 18:40:51 -0300 Subject: [PATCH 1/2] correcting tests and adding more verbose assertions --- code_quality_tools/tests/fixtures/pep8.py | 2 +- .../tests/test_code_quality_tools.py | 30 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/code_quality_tools/tests/fixtures/pep8.py b/code_quality_tools/tests/fixtures/pep8.py index 19c3622..0ba4d8c 100644 --- a/code_quality_tools/tests/fixtures/pep8.py +++ b/code_quality_tools/tests/fixtures/pep8.py @@ -1,4 +1,4 @@ - + def myFunction(): return 1 + 1 diff --git a/code_quality_tools/tests/test_code_quality_tools.py b/code_quality_tools/tests/test_code_quality_tools.py index aed263e..60c0fcd 100644 --- a/code_quality_tools/tests/test_code_quality_tools.py +++ b/code_quality_tools/tests/test_code_quality_tools.py @@ -37,8 +37,12 @@ def test_get_total_of_lines_per_language(self): def test_get_pep8_errors(self): path_fixture = self.path_fixtures + 'pep8.py' errors = self.check.get_pep8_errors(path_fixture) + #print errors self.assertEqual(errors['total_errors'], 3) self.assertEqual(len(errors['list_errors']), 3) + self.assertTrue(path_fixture + ":1:1: W293 blank line contains whitespace" in errors['list_errors']) + self.assertTrue(path_fixture + ":5:1: E302 expected 2 blank lines, found 1" in errors['list_errors']) + self.assertTrue(path_fixture + ":6:17: W292 no newline at end of file" in errors['list_errors']) self.assertEqual(errors['percentage_errors'], 50.0) def test_get_pep8_errors_with_extra_options(self): @@ -47,9 +51,12 @@ def test_get_pep8_errors_with_extra_options(self): path_fixture, options=['--ignore=E302'] ) - self.assertEqual(errors['total_errors'], 1) - self.assertEqual(len(errors['list_errors']), 1) - self.assertEqual(errors['percentage_errors'], 16.67) + self.assertEqual(errors['total_errors'], 2) + self.assertEqual(len(errors['list_errors']), 2) + self.assertTrue(path_fixture + ":1:1: W293 blank line contains whitespace" in errors['list_errors']) + self.assertFalse(path_fixture + ":5:1: E302 expected 2 blank lines, found 1" in errors['list_errors']) + self.assertTrue(path_fixture + ":6:17: W292 no newline at end of file" in errors['list_errors']) + self.assertEqual(errors['percentage_errors'], 33.33) def test_get_pep8_errors_saving_in_output_file(self): output_file = self.out_files['pep8'] @@ -62,6 +69,8 @@ def test_get_pyflakes_errors(self): errors = self.check.get_pyflakes_errors(path_fixture) self.assertEqual(errors['total_errors'], 2) self.assertEqual(len(errors['list_errors']), 2) + self.assertTrue(path_fixture + ":1: 're' imported but unused" in errors['list_errors']) + self.assertTrue(path_fixture + ":2: 'sys' imported but unused" in errors['list_errors']) self.assertEqual(errors['percentage_errors'], 28.57) def test_get_pyflakes_errors_saving_in_output_file(self): @@ -75,6 +84,8 @@ def test_get_jshint_errors(self): errors = self.check.get_jshint_errors(path_fixture) self.assertEqual(errors['total_errors'], 2) self.assertEqual(len(errors['list_errors']), 2) + self.assertTrue(path_fixture + ": line 1, col 11, Missing semicolon." in errors['list_errors']) + self.assertTrue(path_fixture + ": line 2, col 11, Missing semicolon." in errors['list_errors']) self.assertEqual(errors['percentage_errors'], 33.33) def test_get_jshint_errors_saving_in_output_file(self): @@ -91,6 +102,10 @@ def test_get_jshint_errors_with_extra_options(self): ) self.assertEqual(errors['total_errors'], 4) self.assertEqual(len(errors['list_errors']), 4) + self.assertTrue(path_fixture + "jshint.js: line 1, col 11, Missing semicolon." in errors['list_errors']) + self.assertTrue(path_fixture + "jshint.js: line 2, col 11, Missing semicolon." in errors['list_errors']) + self.assertTrue(path_fixture + "jshint_with_extension.jss: line 1, col 11, Missing semicolon." in errors['list_errors']) + self.assertTrue(path_fixture + "jshint_with_extension.jss: line 2, col 11, Missing semicolon." in errors['list_errors']) self.assertEqual(errors['percentage_errors'], 66.67) def test_get_csslint_errors(self): @@ -98,11 +113,17 @@ def test_get_csslint_errors(self): errors = self.check.get_csslint_errors(path_fixture) self.assertEqual(errors['total_errors'], 6) self.assertEqual(len(errors['list_errors']), 6) + self.assertTrue(path_fixture + ": line 1, col 1, Warning - Don't use IDs in selectors." in errors['list_errors']) + self.assertTrue(path_fixture + ": line 2, col 20, Warning - Values of 0 shouldn't have units specified." in errors['list_errors']) + self.assertTrue(path_fixture + ": line 3, col 25, Warning - Values of 0 shouldn't have units specified." in errors['list_errors']) + self.assertTrue(path_fixture + ": line 3, col 5, Warning - Standard property 'border-radius' should come after vendor-prefixed property '-moz-border-radius'." in errors['list_errors']) + self.assertTrue(path_fixture + ": line 4, col 28, Warning - Values of 0 shouldn't have units specified." in errors['list_errors']) + self.assertTrue(path_fixture + ": line 4, col 5, Warning - Standard property 'border-radius' should come after vendor-prefixed property '-webkit-border-radius'." in errors['list_errors']) self.assertEqual(errors['percentage_errors'], 120.0) def test_get_csslint_errors_saving_in_output_file(self): output_file = self.out_files['csslint'] - path_fixture = self.path_fixtures + 'csslint.py' + path_fixture = self.path_fixtures + 'csslint.css' self.check.get_csslint_errors(path_fixture, output_file) self.assertTrue(isfile(output_file)) @@ -114,6 +135,7 @@ def test_get_csslint_errors_with_extra_options(self): ) self.assertEqual(errors['total_errors'], 1) self.assertEqual(len(errors['list_errors']), 1) + self.assertTrue(path_fixture + ": line 1, col 1, Error - Don't use IDs in selectors." in errors['list_errors']) self.assertEqual(errors['percentage_errors'], 20.0) def test_get_clonedigger_errors(self): From 7d62f9d507070fb93b1eb484ab31fff7b5644229 Mon Sep 17 00:00:00 2001 From: Evandro Flores Date: Tue, 29 Jul 2014 18:41:52 -0300 Subject: [PATCH 2/2] correcting tests and adding more verbose assertions --- code_quality_tools/tests/test_code_quality_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/code_quality_tools/tests/test_code_quality_tools.py b/code_quality_tools/tests/test_code_quality_tools.py index 60c0fcd..ae9bf82 100644 --- a/code_quality_tools/tests/test_code_quality_tools.py +++ b/code_quality_tools/tests/test_code_quality_tools.py @@ -37,7 +37,6 @@ def test_get_total_of_lines_per_language(self): def test_get_pep8_errors(self): path_fixture = self.path_fixtures + 'pep8.py' errors = self.check.get_pep8_errors(path_fixture) - #print errors self.assertEqual(errors['total_errors'], 3) self.assertEqual(len(errors['list_errors']), 3) self.assertTrue(path_fixture + ":1:1: W293 blank line contains whitespace" in errors['list_errors'])