a
    Ø
þde;  ã                   @   s^   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„ dejƒZ	e
dkrZe ¡  dS )	z$Facebook tests for yapf.reformatter.é    N)Úreformatter)Ústyle)Úyapf_test_helperc                   @   s¨   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'S )(ÚTestsForFacebookStylec                 C   s   t  t  ¡ ¡ d S )N)r   ZSetGlobalStyleZCreateFacebookStyle)Úcls© r   úl/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapftests/reformatter_facebook_test.pyÚ
setUpClass   s    z TestsForFacebookStyle.setUpClassc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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©ÚselfZunformatted_codeZexpected_formatted_codeÚllinesr   r   r   ÚtestNoNeedForLineBreaks   s    


z-TestsForFacebookStyle.testNoNeedForLineBreaksc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestDedentClosingBracket,   s    


z.TestsForFacebookStyle.testDedentClosingBracketc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   Ú,testBreakAfterOpeningBracketIfContentsTooBig<   s    


zBTestsForFacebookStyle.testBreakAfterOpeningBracketIfContentsTooBigc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   Ú$testDedentClosingBracketWithCommentsL   s    

	
z:TestsForFacebookStyle.testDedentClosingBracketWithCommentsc                 C   s*   t  d¡}t |¡}|  |t |¡¡ d S )NzÃ        from module import (
            internal_function as function,
            SOME_CONSTANT_NUMBER1,
            SOME_CONSTANT_NUMBER2,
            SOME_CONSTANT_NUMBER3,
        )
        r
   ©r   Úcoder   r   r   r   ÚtestDedentImportAsNamesa   s    

z-TestsForFacebookStyle.testDedentImportAsNamesc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestDedentTestListGexpm   s    


z,TestsForFacebookStyle.testDedentTestListGexpc                 C   sZ   t  d¡}t  d¡}t |¡}|  |t |¡¡ t  d¡}t |¡}|  |t |¡¡ 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   Z
pass0_codeZ
pass1_coder   Z
pass2_coder   r   r   ÚtestBrokenIdempotency“   s    




z+TestsForFacebookStyle.testBrokenIdempotencyc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestIfExprHangingIndent±   s    
	


z-TestsForFacebookStyle.testIfExprHangingIndentc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestSimpleDedentingÈ   s    


z)TestsForFacebookStyle.testSimpleDedentingc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestDedentingWithSubscriptsÖ   s    
	


z1TestsForFacebookStyle.testDedentingWithSubscriptsc                 C   s*   t  d¡}t |¡}|  |t |¡¡ d S )Nz½        class _():
            def _():
                cls.effect_clues = {
                    'effect': Clue((cls.effect_time, 'apache_host'), effect_line, 40)
                }
        r
   r   r   r   r   Ú testDedentingCallsWithInnerListsí   s    

z6TestsForFacebookStyle.testDedentingCallsWithInnerListsc                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestDedentingListComprehensionø   s    
&
$
z4TestsForFacebookStyle.testDedentingListComprehensionc                 C   s*   t  d¡}t |¡}|  |t |¡¡ d S )Nzú        class _():
            def _():
                effect_line = FrontInput(
                    effect_line_offset, line_content,
                    LineSource('localhost', xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
                )
        r
   r   r   r   r   ÚtestMustSplitDedentingF  s    

z,TestsForFacebookStyle.testMustSplitDedentingc                 C   s*   t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestDedentIfConditionalR  s    


z-TestsForFacebookStyle.testDedentIfConditionalc                 C   s*   t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestDedentSet`  s    

z#TestsForFacebookStyle.testDedentSetc                 C   sN   t  d¡}t |¡}t |¡}|  ||¡ t |¡}t |¡}|  ||¡ 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   Zreformatted_coder   r   r   ÚtestDedentingInnerScopep  s    
	



z-TestsForFacebookStyle.testDedentingInnerScopec                 C   s4   t  d¡}t  d¡}t |¡}|  |t |¡¡ 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   r   r   r   ÚtestCommentWithNewlinesInPrefix‚  s    


z5TestsForFacebookStyle.testCommentWithNewlinesInPrefixc                 C   s(   d}d}t  |¡}|  |t |¡¡ d S )Nz’if (isinstance(value  , (StopIteration  , StopAsyncIteration  )) and exc.__cause__ is value_asdfasdfasdfasdfsafsafsafdasfasdfs):
    return False
z–if (
    isinstance(value, (StopIteration, StopAsyncIteration)) and
    exc.__cause__ is value_asdfasdfasdfasdfsafsafsafdasfasdfs
):
    return False
)r   r   r   r   r   r   r   r   r   ÚtestIfStmtClosingBracketŸ  s    
z.TestsForFacebookStyle.testIfStmtClosingBracketN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr	   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r   r   r   r   r      s(   
&Nr   Ú__main__)Ú__doc__r   ZunittestZyapf.yapflibr   r   Z	yapftestsr   ZYAPFTestr   r'   Úmainr   r   r   r   Ú<module>   s      