]>
crepu.dev Git - config.git/blob - djavu-asus/elpa/elpy-20230803.1455/elpy/tests/test_yapf.py
2 """Tests for the elpy.yapf module"""
7 from elpy
import yapfutil
8 from elpy
.rpc
import Fault
9 from elpy
.tests
.support
import BackendTestCase
12 @unittest.skipIf(yapfutil
.YAPF_NOT_SUPPORTED
,
13 'yapf not supported for current python version')
14 class YAPFTestCase(BackendTestCase
):
16 if yapfutil
.YAPF_NOT_SUPPORTED
:
17 raise unittest
.SkipTest
19 def test_fix_code_should_throw_error_for_invalid_code(self
):
21 self
.assertRaises(Fault
, yapfutil
.fix_code
, src
, os
.getcwd())
23 def test_fix_code_should_throw_error_without_yapf_installed(self
):
24 yapf
= yapfutil
.yapf_api
25 yapfutil
.yapf_api
= None
26 src
= 'x= 123\n', 'x = 123\n'
27 with self
.assertRaises(Fault
):
28 yapfutil
.fix_code(src
, os
.getcwd())
29 yapfutil
.yapf_api
= yapf
31 def test_fix_code(self
):
33 ('x= 123\n', 'x = 123\n'),
34 ('x=1; \ny=2 \n', 'x = 1\ny = 2\n'),
36 for src
, expected
in testdata
:
37 self
._assert
_format
(src
, expected
)
39 def _assert_format(self
, src
, expected
):
40 new_block
= yapfutil
.fix_code(src
, os
.getcwd())
41 self
.assertEqual(new_block
, expected
)