|
1 | 1 | import unittest |
2 | 2 | from PythonBuddy.app import * |
3 | 3 |
|
4 | | -# Testing Flask Views |
5 | | -# class TestPylint(unittest.TestCase): |
6 | | -# |
7 | | -# def test_pylint(self): |
8 | | -# test_code_1 = "print(\"hello world\")" |
9 | | -# self.assertEqual(app.check_code(test_code_1), '{}') |
10 | | -# |
11 | | -# def test_isupper(self): |
12 | | -# self.assertTrue('FOO'.isupper()) |
13 | | -# self.assertFalse('Foo'.isupper()) |
14 | | -# |
15 | | -# def test_split(self): |
16 | | -# s = 'hello world' |
17 | | -# self.assertEqual(s.split(), ['hello', 'world']) |
18 | | -# # check that s.split fails when the separator is not a string |
19 | | -# with self.assertRaises(TypeError): |
20 | | -# s.split(2) |
21 | | - |
22 | | -# Testing individual functions |
23 | 4 | class TestProcessingFunctions(unittest.TestCase): |
| 5 | + # def test_evaluate_pylint(self): |
| 6 | + # test_code = "def foo(bar, baz):\n pass\nfoo(42)" |
| 7 | + # self.assertNotEqual(evaluate_pylint(test_code), {}) |
| 8 | + |
| 9 | + # def test_slow(self): |
| 10 | + # self.assertFalse(slow()) |
| 11 | + |
24 | 12 | def test_format_errors(self): |
25 | 13 | # self.assertEqual(format_errors(""), {}) |
| 14 | + 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" |
| 15 | + 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]) |
26 | 16 | self.assertEqual(format_errors("\n\n"), [None]) |
| 17 | + |
27 | 18 | def test_process_error(self): |
| 19 | + test_error = " \/tmp\/tmp9utinlsg:3: error (E1120, no-value-for-parameter, ) No value for argument 'baz' in function call\r\n" |
| 20 | + print(process_error(test_error)) |
| 21 | + 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'}) |
28 | 22 | self.assertEqual(process_error(None), None) |
29 | 23 | self.assertEqual(process_error(""), None) |
30 | 24 |
|
31 | | - |
32 | 25 | if __name__ == '__main__': |
33 | 26 | # print(process_error("s")) |
34 | 27 | unittest.main() |
0 commit comments