
    `N`e;                         d Z ddlZddlZddlmZ ddlmZ ddlmZ  G d dej                  Z	e
dk    r ej                     dS dS )	z$Facebook tests for yapf.reformatter.    N)reformatter)style)yapf_test_helperc                       e Zd Ze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S )TestsForFacebookStylec                 P    t          j        t          j                               d S )N)r   SetGlobalStyleCreateFacebookStyle)clss    Clib/python3.11/site-packages/yapftests/reformatter_facebook_test.py
setUpClassz TestsForFacebookStyle.setUpClass   s"    	24455555    c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nza        def overly_long_function_name(
          just_one_arg, **kwargs):
          pass
        zX        def overly_long_function_name(just_one_arg, **kwargs):
            pass
        textwrapdedentr   ParseAndUnwrapassertCodeEqualr   Reformatselfunformatted_codeexpected_formatted_codeuwliness       r   testNoNeedForLineBreaksz-TestsForFacebookStyle.testNoNeedForLineBreaks   sm     (  
 'o /   -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        def overly_long_function_name(
          first_argument_on_the_same_line,
          second_argument_makes_the_line_too_long):
          pass
        z        def overly_long_function_name(
            first_argument_on_the_same_line, second_argument_makes_the_line_too_long
        ):
            pass
        r   r   s       r   testDedentClosingBracketz.TestsForFacebookStyle.testDedentClosingBracket,   sm     (   'o /   -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        def overly_long_function_name(a, b, c, d, e, f, g, h, i, j, k, l, m,
          n, o, p, q, r, s, t, u, v, w, x, y, z):
          pass
        z        def overly_long_function_name(
            a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
        ):
            pass
        r   r   s       r   ,testBreakAfterOpeningBracketIfContentsTooBigzBTestsForFacebookStyle.testBreakAfterOpeningBracketIfContentsTooBig<   sm     (  
 'o /   -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Na          def overly_long_function_name(
          # comment about the first argument
          first_argument_with_a_very_long_name_or_so,
          # comment about the second argument
          second_argument_makes_the_line_too_long):
          pass
        a          def overly_long_function_name(
            # comment about the first argument
            first_argument_with_a_very_long_name_or_so,
            # comment about the second argument
            second_argument_makes_the_line_too_long
        ):
            pass
        r   r   s       r   $testDedentClosingBracketWithCommentsz:TestsForFacebookStyle.testDedentClosingBracketWithCommentsL   sm     (   'o /   -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        from module import (
            internal_function as function,
            SOME_CONSTANT_NUMBER1,
            SOME_CONSTANT_NUMBER2,
            SOME_CONSTANT_NUMBER3,
        )
        r   r   coder   s      r   testDedentImportAsNamesz-TestsForFacebookStyle.testDedentImportAsNamesa   Q    ?   D -d33G{3G<<=====r   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )NaH          try:
            pass
        except (
            IOError, OSError, LookupError, RuntimeError, OverflowError
        ) as exception:
            pass

        try:
            pass
        except (
            IOError, OSError, LookupError, RuntimeError, OverflowError,
        ) as exception:
            pass
        ax          try:
            pass
        except (
            IOError, OSError, LookupError, RuntimeError, OverflowError
        ) as exception:
            pass

        try:
            pass
        except (
            IOError,
            OSError,
            LookupError,
            RuntimeError,
            OverflowError,
        ) as exception:
            pass
        r   r   s       r   testDedentTestListGexpz,TestsForFacebookStyle.testDedentTestListGexpm   sm     (   'o /  & -.>??G0+2Fw2O2OPPPPPr   c                 n   t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        try:
            pass
        except (IOError, OSError, LookupError, RuntimeError, OverflowError) as exception:
            pass
        z        try:
            pass
        except (
            IOError, OSError, LookupError, RuntimeError, OverflowError
        ) as exception:
            pass
        r   )r   
pass0_code
pass1_coder   
pass2_codes        r   testBrokenIdempotencyz+TestsForFacebookStyle.testBrokenIdempotency   s     "  J  "  J -j99G[%9'%B%BCCC "  J -j99G[%9'%B%BCCCCCr   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Na"          if True:
            if True:
                if True:
                    if not self.frobbies and (
                       self.foobars.counters['db.cheeses'] != 1 or
                       self.foobars.counters['db.marshmellow_skins'] != 1):
                        pass
        a9          if True:
            if True:
                if True:
                    if not self.frobbies and (
                        self.foobars.counters['db.cheeses'] != 1 or
                        self.foobars.counters['db.marshmellow_skins'] != 1
                    ):
                        pass
        r   r   s       r   testIfExprHangingIndentz-TestsForFacebookStyle.testIfExprHangingIndent   m     (   'o 	/ 	 	 -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nzu        if True:
            self.assertEqual(result.reason_not_added, "current preflight is still running")
        z        if True:
            self.assertEqual(
                result.reason_not_added, "current preflight is still running"
            )
        r   r   s       r   testSimpleDedentingz)TestsForFacebookStyle.testSimpleDedenting   sm     (   'o /   -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Na8          class Foo:
            class Bar:
                @classmethod
                def baz(cls, clues_list, effect, constraints, constraint_manager):
                    if clues_lists:
                       return cls.single_constraint_not(clues_lists, effect, constraints[0], constraint_manager)

        an          class Foo:
            class Bar:
                @classmethod
                def baz(cls, clues_list, effect, constraints, constraint_manager):
                    if clues_lists:
                        return cls.single_constraint_not(
                            clues_lists, effect, constraints[0], constraint_manager
                        )
        r   r   s       r   testDedentingWithSubscriptsz1TestsForFacebookStyle.testDedentingWithSubscripts   r0   r   c                     t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        class _():
            def _():
                cls.effect_clues = {
                    'effect': Clue((cls.effect_time, 'apache_host'), effect_line, 40)
                }
        r   r#   s      r    testDedentingCallsWithInnerListsz6TestsForFacebookStyle.testDedentingCallsWithInnerLists   sQ    ?   D -d33G{3G<<=====r   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Na          class Foo():
            def _pack_results_for_constraint_or():
                self.param_groups = dict(
                    (
                        key + 1, ParamGroup(groups[key], default_converter)
                    ) for key in six.moves.range(len(groups))
                )

                for combination in cls._clues_combinations(clues_lists):
                    if all(
                        cls._verify_constraint(combination, effect, constraint)
                        for constraint in constraints
                    ):
                        pass

                guessed_dict = dict(
                    (
                        key, guessed_pattern_matches[key]
                    ) for key in six.moves.range(len(guessed_pattern_matches))
                )

                content = "".join(
                    itertools.chain(
                        (first_line_fragment, ), lines_between, (last_line_fragment, )
                    )
                )

                rule = Rule(
                    [self.cause1, self.cause2, self.cause1, self.cause2], self.effect, constraints1,
                    Rule.LINKAGE_AND
                )

                assert sorted(log_type.files_to_parse) == [
                    ('localhost', os.path.join(path, 'node_1.log'), super_parser),
                    ('localhost', os.path.join(path, 'node_2.log'), super_parser)
                ]
        ae          class Foo():
            def _pack_results_for_constraint_or():
                self.param_groups = dict(
                    (key + 1, ParamGroup(groups[key], default_converter))
                    for key in six.moves.range(len(groups))
                )

                for combination in cls._clues_combinations(clues_lists):
                    if all(
                        cls._verify_constraint(combination, effect, constraint)
                        for constraint in constraints
                    ):
                        pass

                guessed_dict = dict(
                    (key, guessed_pattern_matches[key])
                    for key in six.moves.range(len(guessed_pattern_matches))
                )

                content = "".join(
                    itertools.chain(
                        (first_line_fragment, ), lines_between, (last_line_fragment, )
                    )
                )

                rule = Rule(
                    [self.cause1, self.cause2, self.cause1, self.cause2], self.effect,
                    constraints1, Rule.LINKAGE_AND
                )

                assert sorted(log_type.files_to_parse) == [
                    ('localhost', os.path.join(path, 'node_1.log'), super_parser),
                    ('localhost', os.path.join(path, 'node_2.log'), super_parser)
                ]
        r   r   s       r   testDedentingListComprehensionz4TestsForFacebookStyle.testDedentingListComprehension   so     %( % %L 'o #/ # #H -.>??G0+2Fw2O2OPPPPPr   c                     t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        class _():
            def _():
                effect_line = FrontInput(
                    effect_line_offset, line_content,
                    LineSource('localhost', xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
                )
        r   r#   s      r   testMustSplitDedentingz,TestsForFacebookStyle.testMustSplitDedentingF  r&   r   c                     t          j        d          }t          j        |          }|                     |t          j        |                     d S )Na;          class _():
            def _():
                if True:
                    if not self.frobbies and (
                        self.foobars.counters['db.cheeses'] != 1 or
                        self.foobars.counters['db.marshmellow_skins'] != 1
                    ):
                        pass
        r   r#   s      r   testDedentIfConditionalz-TestsForFacebookStyle.testDedentIfConditionalR  sQ    ? 	 	 	D -d33G{3G<<=====r   c                     t          j        d          }t          j        |          }|                     |t          j        |                     d S )NaL          class _():
            def _():
                assert set(self.constraint_links.get_links()) == set(
                    [
                        (2, 10, 100),
                        (2, 10, 200),
                        (2, 20, 100),
                        (2, 20, 200),
                    ]
                )
        r   r#   s      r   testDedentSetz#TestsForFacebookStyle.testDedentSet`  sQ    ?   D -d33G{3G<<=====r   c                 &   t          j        d          }t          j        |          }t	          j        |          }|                     ||           t          j        |          }t	          j        |          }|                     ||           d S )Na_          class Foo():
            @classmethod
            def _pack_results_for_constraint_or(cls, combination, constraints):
                return cls._create_investigation_result(
                    (clue for clue in combination if not clue == Verifier.UNMATCHED),
                    constraints, InvestigationResult.OR
                )
        )r   r   r   r   r   r   r   )r   r$   r   reformatted_codes       r   testDedentingInnerScopez-TestsForFacebookStyle.testDedentingInnerScopep  s    ?   D -d33G"+G44/000-.>??G"+G44/00000r   c                     t          j        d          }t          j        d          }t          j        |          }|                     |t          j        |                     d S )Nz        def foo():
            if 0:
                return False
                
                
            #a deadly comment
            elif 1:
                return True


        print(foo())
        z        def foo():
            if 0:
                return False
                
            #a deadly comment
            elif 1:
                return True


        print(foo())
        r   r   s       r   testCommentWithNewlinesInPrefixz5TestsForFacebookStyle.testCommentWithNewlinesInPrefix  sm     (   'o /   -.>??G0+2Fw2O2OPPPPPr   c                     d}d}t          j        |          }|                     |t          j        |                     d S )Nzif (isinstance(value  , (StopIteration  , StopAsyncIteration  )) and exc.__cause__ is value_asdfasdfasdfasdfsafsafsafdasfasdfs):
    return False
zif (
    isinstance(value, (StopIteration, StopAsyncIteration)) and
    exc.__cause__ is value_asdfasdfasdfasdfsafsafsafdasfasdfs
):
    return False
)r   r   r   r   r   r   s       r   testIfStmtClosingBracketz.TestsForFacebookStyle.testIfStmtClosingBracket  sM     -.>??G0+2Fw2O2OPPPPPr   N)__name__
__module____qualname__classmethodr   r   r   r   r!   r%   r(   r-   r/   r2   r4   r6   r8   r:   r<   r>   rA   rC   rE    r   r   r   r      sf       6 6 ;6Q Q QQ Q Q Q Q Q Q Q Q*
> 
> 
>$Q $Q $QLD D D<Q Q Q.Q Q QQ Q Q.	> 	> 	>LQ LQ LQ\
> 
> 
>> > >> > > 1 1 1$Q Q Q:Q Q Q Q Qr   r   __main__)__doc__r   unittestyapf.yapflibr   r   	yapftestsr   YAPFTestr   rF   mainrJ   r   r   <module>rR      s    + *   $ $ $ $ $ $       & & & & & &SQ SQ SQ SQ SQ,5 SQ SQ SQl z(-///// r   