]> crepu.dev Git - config.git/blame_incremental - djavu-asus/elpa/elpy-20230803.1455/elpy/tests/test_yapf.py
Configuracion en desarrollo PC pega
[config.git] / djavu-asus / elpa / elpy-20230803.1455 / elpy / tests / test_yapf.py
... / ...
CommitLineData
1# coding: utf-8
2"""Tests for the elpy.yapf module"""
3
4import unittest
5import os
6
7from elpy import yapfutil
8from elpy.rpc import Fault
9from elpy.tests.support import BackendTestCase
10
11
12@unittest.skipIf(yapfutil.YAPF_NOT_SUPPORTED,
13 'yapf not supported for current python version')
14class YAPFTestCase(BackendTestCase):
15 def setUp(self):
16 if yapfutil.YAPF_NOT_SUPPORTED:
17 raise unittest.SkipTest
18
19 def test_fix_code_should_throw_error_for_invalid_code(self):
20 src = 'x = '
21 self.assertRaises(Fault, yapfutil.fix_code, src, os.getcwd())
22
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
30
31 def test_fix_code(self):
32 testdata = [
33 ('x= 123\n', 'x = 123\n'),
34 ('x=1; \ny=2 \n', 'x = 1\ny = 2\n'),
35 ]
36 for src, expected in testdata:
37 self._assert_format(src, expected)
38
39 def _assert_format(self, src, expected):
40 new_block = yapfutil.fix_code(src, os.getcwd())
41 self.assertEqual(new_block, expected)