Skip to content

Commit

Permalink
Merge branch 'feature/unit_tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanchewy committed Oct 29, 2018
2 parents a78a3a4 + 5f880fb commit eca5b76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ python:
install: "pip install -r requirements.txt"
# command to run tests
script:
- echo "TODO"
- python -m tests.test_linter
33 changes: 13 additions & 20 deletions tests/test_linter.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit eca5b76

Please sign in to comment.