diff --git a/.travis.yml b/.travis.yml index ddb4a564..e4c4534d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ python: install: "pip install -r requirements.txt" # command to run tests script: - - echo "TODO" + - python -m tests.test_linter diff --git a/tests/test_linter.py b/tests/test_linter.py index 929632a1..93ea3c2f 100644 --- a/tests/test_linter.py +++ b/tests/test_linter.py @@ -1,34 +1,27 @@ import unittest from PythonBuddy.app import * -# Testing Flask Views -# class TestPylint(unittest.TestCase): -# -# def test_pylint(self): -# test_code_1 = "print(\"hello world\")" -# self.assertEqual(app.check_code(test_code_1), '{}') -# -# def test_isupper(self): -# self.assertTrue('FOO'.isupper()) -# self.assertFalse('Foo'.isupper()) -# -# def test_split(self): -# s = 'hello world' -# self.assertEqual(s.split(), ['hello', 'world']) -# # check that s.split fails when the separator is not a string -# with self.assertRaises(TypeError): -# s.split(2) - -# Testing individual functions class TestProcessingFunctions(unittest.TestCase): + # def test_evaluate_pylint(self): + # test_code = "def foo(bar, baz):\n pass\nfoo(42)" + # self.assertNotEqual(evaluate_pylint(test_code), {}) + + # def test_slow(self): + # self.assertFalse(slow()) + def test_format_errors(self): # self.assertEqual(format_errors(""), {}) + test_errors="************* Module tmp9utinlsg\r\n \/tmp\/tmp9utinlsg:1: warning (W0613, unused-argument, foo) Unused argument 'bar'\r\n \/tmp\/tmp9utinlsg:1: warning (W0613, unused-argument, foo) Unused argument 'baz'\r\n \/tmp\/tmp9utinlsg:3: error (E1120, no-value-for-parameter, ) No value for argument 'baz' in function call\r\n \r\n ----------------------------------------------------------------------\r\n Your code has been rated at -13.33\/10 (previous run: -13.33\/10, +0.00)\r\n \r\n \r\n" + self.assertEqual(format_errors(test_errors), [{'code': 'W0613', 'error': 'unused-argument', 'message': 'Unused argument', 'line': '1', 'error_info': ' \r Occurs when a function or method argument is not used.\r'}, {'code': 'W0613', 'error': 'unused-argument', 'message': 'Unused argument', 'line': '1', 'error_info': ' \r Occurs when a function or method argument is not used.\r'}, {'code': 'E1120', 'error': 'no-value-for-parameter', 'message': "No value for argument 'baz' in function", 'line': '3', 'error_info': ' \r Occurs when a function call passes too few arguments.\r'}, None, None, None, None, None]) self.assertEqual(format_errors("\n\n"), [None]) + def test_process_error(self): + test_error = " \/tmp\/tmp9utinlsg:3: error (E1120, no-value-for-parameter, ) No value for argument 'baz' in function call\r\n" + print(process_error(test_error)) + self.assertEqual(process_error(test_error), {'code': 'E1120', 'error': 'no-value-for-parameter', 'message': "No value for argument 'baz' in function", 'line': '3', 'error_info': ' \r Occurs when a function call passes too few arguments.\r'}) self.assertEqual(process_error(None), None) self.assertEqual(process_error(""), None) - if __name__ == '__main__': # print(process_error("s")) unittest.main()