
    ?d8                         d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	  ej                  ej                  d       G d d	e	j                               Zed
k(  r ej                          yy)z$Python 3 tests for yapf.reformatter.    N)	py3compat)reformatter)style)yapf_test_helperzRequires Python 3c                       e Zd ZdZed        Zd Zd Zd Z e	j                  ej                  d      d        Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"y)TestsForPython3Codez3Test a few constructs that are new Python 3 syntax.c                 R    t        j                  t        j                                y )N)r   SetGlobalStyleCreatePEP8Style)clss    D/usr/lib/python3/dist-packages/yapftests/reformatter_python3_test.py
setUpClasszTestsForPython3Code.setUpClass   s    	..01    c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nz        def x(aaaaaaaaaaaaaaa:int,bbbbbbbbbbbbbbbb:str,ccccccccccccccc:dict,eeeeeeeeeeeeee:set={1, 2, 3})->bool:
          pass
        z        def x(aaaaaaaaaaaaaaa: int,
              bbbbbbbbbbbbbbbb: str,
              ccccccccccccccc: dict,
              eeeeeeeeeeeeee: set = {1, 2, 3}) -> bool:
            pass
        textwrapdedentr   ParseAndUnwrapassertCodeEqualr   Reformatselfunformatted_codeexpected_formatted_codelliness       r   testTypedNamesz"TestsForPython3Code.testTypedNames#   s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nz}        def func(arg=long_function_call_that_pushes_the_line_over_eighty_characters()) -> ReturnType:
          pass
        z        def func(arg=long_function_call_that_pushes_the_line_over_eighty_characters()
                 ) -> ReturnType:
            pass
        r   r   s       r   testTypedNameWithLongNamedArgz1TestsForPython3Code.testTypedNameWithLongNamedArg2   s[     (  'oo / 
 ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nz9        def foo(a, *, kw):
          return a+kw
        z=        def foo(a, *, kw):
            return a + kw
        r   r   s       r   testKeywordOnlyArgSpecifierz/TestsForPython3Code.testKeywordOnlyArgSpecifier?   [     (  'oo /  ,,-=>F0+2F2Fv2NOr   zRequires Python 3.6c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nzd    { ** x }
    {   **{}   }
    { **{   **x },  **x }
    {'a': 1,   **kw , 'b':3,  **kw2   }
    zN    {**x}
    {**{}}
    {**{**x}, **x}
    {'a': 1, **kw, 'b': 3, **kw2}
    r   r   s       r   testPEP448ParameterExpansionz0TestsForPython3Code.testPEP448ParameterExpansionK   s[     ( 	 'oo / 	 ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )NzI        def foo(a: list, b: "bar") -> dict:
          return a+b
        zM        def foo(a: list, b: "bar") -> dict:
            return a + b
        r   r   s       r   testAnnotationsz#TestsForPython3Code.testAnnotations\   r!   r   c                     d}d}t        j                  |      }| j                  |t        j                  |             y )Nz!methods.exec( sys.modules[name])
z methods.exec(sys.modules[name])
r   r   r   r   r   r   s       r   testExecAsNonKeywordz(TestsForPython3Code.testExecAsNonKeywordh   s;    ;A,,-=>F0+2F2Fv2NOr   c                     t         j                  d   dk  ry t        j                  d      }t	        j
                  |      }| j                  |t        j                  |d             y )N      a@          import asyncio
        import time


        @print_args
        async def slow_operation():
            await asyncio.sleep(1)
            # print("Slow operation {} complete".format(n))


        async def main():
            start = time.time()
            if (await get_html()):
                pass
        F)verify	sysversion_infor   r   r   r   r   r   r   r   coder   s      r   testAsyncFunctionsz&TestsForPython3Code.testAsyncFunctionsn   sZ    
Q??  D  ,,T2F{33F5IJr   c                    t        j                  d      }t        j                  d      }	 t        j                  t        j                  d             t        j                  |      }| j                  |t        j                  |             t        j                  t        j                                y # t        j                  t        j                                w xY w)Nz        a**b
        z        a ** b
        z:{based_on_style: pep8, SPACES_AROUND_POWER_OPERATOR: True}r   r   r   r
   CreateStyleFromConfigr   r   r   r   r   r   r   s       r   testNoSpacesAroundPowerOperatorz3TestsForPython3Code.testNoSpacesAroundPowerOperator   s     (  'oo / 	4

%
%JLM  ../?@f
2&//79 50023e50023   A"B6 6)Cc                    t        j                  d      }t        j                  d      }	 t        j                  t        j                  d             t        j                  |      }| j                  |t        j                  |             t        j                  t        j                                y # t        j                  t        j                                w xY w)Nz        f(a=5)
        z        f(a = 5)
        zC{based_on_style: pep8, SPACES_AROUND_DEFAULT_OR_NAMED_ASSIGN: True}r4   r   s       r   $testSpacesAroundDefaultOrNamedAssignz8TestsForPython3Code.testSpacesAroundDefaultOrNamedAssign   s     (  'oo / 
4

%
%=>?
  ../?@f
2&//79 50023e50023r7   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nzh        def foo(x: int=42):
            pass


        def foo2(x: 'int' =42):
            pass
        zk        def foo(x: int = 42):
            pass


        def foo2(x: 'int' = 42):
            pass
        r   r   s       r   testTypeHintz TestsForPython3Code.testTypeHint   s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nz        a=b@c
        z        a = b @ c
        r   r   s       r   testMatrixMultiplicationz,TestsForPython3Code.testMatrixMultiplication   s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                 |    d}t        j                  |      }| j                  |t        j                  |             y )NzNone.__ne__()
r'   r0   s      r   testNoneKeywordz#TestsForPython3Code.testNoneKeyword   s6    D ,,T2F{33F;<r   c                     t         j                  d   dk  ry t        j                  d      }t        j                  d      }t	        j
                  |      }| j                  |t        j                  |             y )Nr*   r+   z        import asyncio

        # Comment
        async def bar():
            pass

        async def foo():
            pass
        z        import asyncio


        # Comment
        async def bar():
            pass


        async def foo():
            pass
        r-   r   s       r   testAsyncWithPrecedingCommentz1TestsForPython3Code.testAsyncWithPrecedingComment   sq    
Q 	( 	 'oo /  ,,-=>F0+2F2Fv2NOr   c                     t         j                  d   dk  ry t        j                  d      }t	        j
                  |      }| j                  |t        j                  |             y )Nr*   r+   zX        async def outer():

            async def inner():
                pass
        r-   r0   s      r   testAsyncFunctionsNestedz,TestsForPython3Code.testAsyncFunctionsNested   sX    
Q??  D ,,T2F{33F;<r   c                     t         j                  d   dk  ry t        j                  d      }t        j                  d      }t	        j
                  |      }| j                  |t        j                  |             y )Nr*   r+   z        def _ReduceAbstractContainers(
            self, *args: Optional[automation_converter.PyiCollectionAbc]) -> List[
                automation_converter.PyiCollectionAbc]:
            pass
        z        def _ReduceAbstractContainers(
            self, *args: Optional[automation_converter.PyiCollectionAbc]
        ) -> List[automation_converter.PyiCollectionAbc]:
            pass
        r-   r   s       r   testKeepTypesIntactz'TestsForPython3Code.testKeepTypesIntact   q    
Q (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     t         j                  d   dk  ry t        j                  d      }t        j                  d      }t	        j
                  |      }| j                  |t        j                  |             y )Nr*   r+   z        async def start_websocket():
            async with session.ws_connect(
                r"ws://a_really_long_long_long_long_long_long_url") as ws:
                pass
        z        async def start_websocket():
            async with session.ws_connect(
                    r"ws://a_really_long_long_long_long_long_long_url") as ws:
                pass
        r-   r   s       r   testContinuationIndentWithAsyncz3TestsForPython3Code.testContinuationIndentWithAsync
  rF   r   c                    t         j                  d   dk  ry d}d}	 t        j                  t        j                  d             t        j                  |      }| j                  |t        j                  |             t        j                  t        j                                y # t        j                  t        j                                w xY w)Nr*   r+   a  async def open_file(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None):
    pass

async def run_sync_in_worker_thread(sync_fn, *args, cancellable=False, limiter=None):
    pass

def open_file(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None):
    pass

def run_sync_in_worker_thread(sync_fn, *args, cancellable=False, limiter=None):
    pass
a  async def open_file(
    file,
    mode='r',
    buffering=-1,
    encoding=None,
    errors=None,
    newline=None,
    closefd=True,
    opener=None
):
    pass


async def run_sync_in_worker_thread(
    sync_fn, *args, cancellable=False, limiter=None
):
    pass


def open_file(
    file,
    mode='r',
    buffering=-1,
    encoding=None,
    errors=None,
    newline=None,
    closefd=True,
    opener=None
):
    pass


def run_sync_in_worker_thread(sync_fn, *args, cancellable=False, limiter=None):
    pass
z{based_on_style: pep8, dedent_closing_brackets: true, coalesce_brackets: false, space_between_ending_comma_and_closing_bracket: false, split_arguments_when_comma_terminated: true, split_before_first_argument: true})r.   r/   r   r
   r5   r   r   r   r   r   r   r   s       r   testSplittingArgumentsz*TestsForPython3Code.testSplittingArguments  s    
Q#J4

%
%345  ../?@f
2&//79 50023e50023s   A"B' ')Cc                     t         j                  d   dk  ry d}d}t        j                  |      }| j	                  |t        j                  |             y )Nr*   r+   zclass Foo:
    def foo(self):
        foofoofoofoofoofoofoofoo('foofoofoofoofoo', {

            'foo': 'foo',

            **foofoofoo
        })
zclass Foo:

    def foo(self):
        foofoofoofoofoofoofoofoo('foofoofoofoofoo', {
            'foo': 'foo',
            **foofoofoo
        })
r.   r/   r   r   r   r   r   r   s       r   testDictUnpackingz%TestsForPython3Code.testDictUnpackingb  sW    
Q	 ,,-=>F0+2F2Fv2NOr   c                     t         j                  d   dk  ry d}t        j                  |      }| j	                  |t        j                  |             y )Nr*      z,# yapf: disable
(f'''
  ''')
# yapf: enable
rL   r0   s      r   testMultilineFormatStringz-TestsForPython3Code.testMultilineFormatString{  sL    
QD ,,T2F{33F;<r   c                     t         j                  d   dk  ry d}t        j                  |      }| j	                  |t        j                  |             y )Nr*   rO   z[def dirichlet(x12345678901234567890123456789012345678901234567890=...) -> None:
    return
rL   r0   s      r   testEllipsesz TestsForPython3Code.testEllipses  sL    
QD
 ,,T2F{33F;<r   c                 |    d}t        j                  |      }| j                  |t        j                  |             y )Nzdef _GenerateStatsEntries(
    process_id: Text,
    timestamp: Optional[ffffffff.FFFFFFFFFFF] = None
) -> Sequence[ssssssssssss.SSSSSSSSSSSSSSS]:
    pass
r'   r0   s      r   testFunctionTypedReturnNextLinez3TestsForPython3Code.testFunctionTypedReturnNextLine  s6    D ,,T2F{33F;<r   c                 |    d}t        j                  |      }| j                  |t        j                  |             y )Nzudef rrrrrrrrrrrrrrrrrrrrrr(
        ccccccccccccccccccccccc: Tuple[Text, Text]) -> List[Tuple[Text, Text]]:
    pass
r'   r0   s      r   testFunctionTypedReturnSameLinez3TestsForPython3Code.testFunctionTypedReturnSameLine  s6    D
 ,,T2F{33F;<r   c                     t         j                  d   dk  ry t        j                  d      }t	        j
                  |      }| j                  |t        j                  |             y )Nr*   r+   z    async def fn():
        async for message in websocket:
            for i in range(10):
                pass
            else:
                pass
        else:
            pass
    r-   r0   s      r   %testAsyncForElseNotIndentedInsideBodyz9TestsForPython3Code.testAsyncForElseNotIndentedInsideBody  sX    
Q?? 	 		D ,,T2F{33F;<r   c                     t         j                  d   dk  ry t        j                  d      }t	        j
                  |      }| j                  |t        j                  |             y )Nr*   r+   zd    async def fn():
        for i in range(10):
            pass
        else:
            pass
    r-   r0   s      r   &testForElseInAsyncNotMixedWithAsyncForz:TestsForPython3Code.testForElseInAsyncNotMixedWithAsyncFor  sX    
Q??  	D ,,T2F{33F;<r   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )Nz        def raw_message(  # pylint: disable=too-many-arguments
                    self, text, user_id=1000, chat_type='private', forward_date=None, forward_from=None):
                pass
        a          def raw_message(  # pylint: disable=too-many-arguments
                self,
                text,
                user_id=1000,
                chat_type='private',
                forward_date=None,
                forward_from=None):
            pass
        r   r   s       r   %testParameterListIndentationConflictsz9TestsForPython3Code.testParameterListIndentationConflicts  s[     ( 
 'oo 	/ 	 ,,-=>F0+2F2Fv2NOr   N)#__name__
__module____qualname____doc__classmethodr   r   r   r    unittest
skipUnlessr   PY36r#   r%   r(   r2   r6   r9   r;   r=   r?   rA   rC   rE   rH   rJ   rM   rP   rR   rT   rV   rX   rZ   r\    r   r   r   r      s    ;2 2PP
P 8y~~'<=P >P 
PPK,4&4(P(P=P8
=P$P$D4LP2=	=	=== =Pr   r   __main__)r`   r.   r   rb   yapf.yapflibr   r   r   	yapftestsr   rc   PY3YAPFTestr   r]   mainre   r   r   <module>rl      sv    + 
   " $  & Y]]$78yP*33 yP 9yPx z(--/ r   