Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
975 B

5 years ago
  1. # coding: utf-8
  2. """Tests for the elpy.yapf module"""
  3. import unittest
  4. import os
  5. from elpy import yapfutil
  6. from elpy.rpc import Fault
  7. from elpy.tests.support import BackendTestCase
  8. @unittest.skipIf(yapfutil.YAPF_NOT_SUPPORTED,
  9. 'yapf not supported for current python version')
  10. class YAPFTestCase(BackendTestCase):
  11. def setUp(self):
  12. if yapfutil.YAPF_NOT_SUPPORTED:
  13. raise unittest.SkipTest
  14. def test_fix_code_should_throw_error_for_invalid_code(self):
  15. src = 'x = '
  16. self.assertRaises(Fault, yapfutil.fix_code, src, os.getcwd())
  17. def test_fix_code(self):
  18. testdata = [
  19. ('x= 123\n', 'x = 123\n'),
  20. ('x=1; \ny=2 \n', 'x = 1\ny = 2\n'),
  21. ]
  22. for src, expected in testdata:
  23. self._assert_format(src, expected)
  24. def _assert_format(self, src, expected):
  25. new_block = yapfutil.fix_code(src, os.getcwd())
  26. self.assertEqual(new_block, expected)