
    ?de;                         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                          yy)	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y)TestsForFacebookStylec                 R    t        j                  t        j                                y )N)r   SetGlobalStyleCreateFacebookStyle)clss    E/usr/lib/python3/dist-packages/yapftests/reformatter_facebook_test.py
setUpClassz TestsForFacebookStyle.setUpClass   s    	2245    c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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lliness       r   testNoNeedForLineBreaksz-TestsForFacebookStyle.testNoNeedForLineBreaks   s[     ( 
 'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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,   s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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<   s[     ( 
 'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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   s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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   B    ??  D ,,T2F{33F;<r   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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   s[     (  'oo / & ,,-=>F0+2F2Fv2NOr   c                 j   t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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 ,,Z8F[%9%9&%AB " J ,,Z8F[%9%9&%ABr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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   [     (  'oo 	/ 	 ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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   s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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                  |      }| j	                  |t        j                  |             y )Nz        class _():
            def _():
                cls.effect_clues = {
                    'effect': Clue((cls.effect_time, 'apache_host'), effect_line, 40)
                }
        r   r#   s      r    testDedentingCallsWithInnerListsz6TestsForFacebookStyle.testDedentingCallsWithInnerLists   sB    ??  D ,,T2F{33F;<r   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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   s]     %( %L 'oo #/ #H ,,-=>F0+2F2Fv2NOr   c                     t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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                  |      }| j	                  |t        j                  |             y )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  sB    ?? 	 	D ,,T2F{33F;<r   c                     t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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`  sB    ??  D ,,T2F{33F;<r   c                    t        j                  d      }t        j                  |      }t	        j
                  |      }| j                  ||       t        j                  |      }t	        j
                  |      }| j                  ||       y )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 ,,T2F"++F3/0,,-=>F"++F3/0r   c                     t        j                  d      }t        j                  d      }t        j                  |      }| j	                  |t        j                  |             y )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  s[     (  'oo /  ,,-=>F0+2F2Fv2NOr   c                     d}d}t        j                  |      }| j                  |t        j                  |             y )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  sA     ,,-=>F0+2F2Fv2NOr   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      s}    6 6PP P P*
=$PLC<P.PP.	=LP\
=== 1$P:Pr   r   __main__)__doc__r   unittestyapf.yapflibr   r   	yapftestsr   YAPFTestr   rF   mainrJ   r   r   <module>rR      sK    +   $  &SP,55 SPl z(--/ r   