コード例 #1
0
    def test_correctly_placed_symbol(self,
                                     mypy_nodes: MypyNodeFactory) -> None:
        hand, gen = mypy_nodes.get_method()
        gen_map = mypy_nodes.get_generated_stubs_map()

        result = lookup_symbol(gen_map, hand)
        assert result == LookupResult(symbol=gen, containing_class=gen.info)
コード例 #2
0
    def test_type_infos_with_different_names_mismatch(
            self, mypy_nodes: MypyNodeFactory) -> None:
        a_cls, _ = mypy_nodes.get_class()
        antoher_cls, _ = mypy_nodes.get_another_class()
        result = compare_symbols(a_cls, antoher_cls)

        assert result.match_result is MatchResult.MISMATCH
コード例 #3
0
    def test_mislocated_symbol_with_cls_not_found(
            self, mypy_nodes: MypyNodeFactory) -> None:
        mislocated_handwritten = mypy_nodes.get_mislocated_method_handwritten()
        gen_map = copy(mypy_nodes.get_generated_stubs_map())

        del gen_map[mislocated_handwritten.info.fullname]
        result = lookup_symbol(gen_map, mislocated_handwritten)
        assert result == LookupResult(symbol=None, containing_class=None)
コード例 #4
0
    def test_str_and_int_dont_match(self, mypy_nodes: MypyNodeFactory) -> None:
        int_var = mypy_nodes.get_int_var()
        str_var = mypy_nodes.get_str_var()

        result_a = compare_symbols(int_var, str_var)
        result_b = compare_symbols(str_var, int_var)

        assert result_a.match_result is MatchResult.MISMATCH
        assert result_b.match_result is MatchResult.MISMATCH
コード例 #5
0
    def test_bool_more_specific_than_int(self,
                                         mypy_nodes: MypyNodeFactory) -> None:
        int_var = mypy_nodes.get_int_var()
        bool_var = mypy_nodes.get_bool_var()

        result_a = compare_symbols(int_var, bool_var)
        result_b = compare_symbols(bool_var, int_var)

        assert result_a.match_result is MatchResult.MISMATCH
        assert result_b.match_result is MatchResult.MATCH
コード例 #6
0
    def test_mislocated_symbol(self, mypy_nodes: MypyNodeFactory) -> None:
        mislocated_handwritten = mypy_nodes.get_mislocated_method_handwritten()
        gen_map = mypy_nodes.get_generated_stubs_map()
        mislocated_actual_location = (
            mypy_nodes.get_mislocated_method_actual_location_generated())

        result = lookup_symbol(gen_map, mislocated_handwritten)
        assert result == LookupResult(
            symbol=mislocated_actual_location,
            containing_class=mislocated_actual_location.info,
        )
コード例 #7
0
    def test_mislocated_symbol_without_cls(
            self, mypy_nodes: MypyNodeFactory) -> None:
        mislocated_handwritten = mypy_nodes.get_mislocated_method_handwritten()
        gen_map = mypy_nodes.get_generated_stubs_map()

        original_func_info = mislocated_handwritten.info
        mislocated_handwritten.info = FUNC_NO_INFO

        result = lookup_symbol(gen_map, mislocated_handwritten)
        assert result == LookupResult(symbol=None, containing_class=None)

        mislocated_handwritten.info = original_func_info
コード例 #8
0
 def test_overload_mismatch_if_any_handwritten_stub_has_additional_optional_args(
         self, mypy_nodes: MypyNodeFactory) -> None:
     (
         overloaded_def,
         overloaded_reference,
     ) = mypy_nodes.get_overloaded_additional_optional_args_node()
     result = compare_symbols(overloaded_def, overloaded_reference)
     assert result.match_result is MatchResult.MISMATCH
コード例 #9
0
 def test_decorated_mismatches_if_handwritten_stub_has_additional_optional_args(
         self, mypy_nodes: MypyNodeFactory) -> None:
     (
         decorated,
         decorated_reference,
     ) = mypy_nodes.get_decorated_with_additional_optional_args()
     result = compare_symbols(decorated, decorated_reference)
     assert result.match_result is MatchResult.MISMATCH
コード例 #10
0
 def test_args_with_no_annotation_matches_if_argc_matches(
         self, mypy_nodes: MypyNodeFactory) -> None:
     (
         func_def,
         func_def_reference,
     ) = mypy_nodes.get_function_with_args_but_no_annotation()
     result = compare_symbols(func_def, func_def_reference)
     assert result.match_result is MatchResult.MATCH
コード例 #11
0
 def test_generated_has_no_parameters_and_return_type(
         self, mypy_nodes: MypyNodeFactory) -> None:
     (
         func_def,
         func_def_reference,
     ) = mypy_nodes.get_no_parameters_and_return_type_node()
     result = compare_symbols(func_def, func_def_reference)
     assert result.match_result is MatchResult.MISMATCH
コード例 #12
0
 def test_decorated_function_matches(self,
                                     mypy_nodes: MypyNodeFactory) -> None:
     decorated, decorated_reference = mypy_nodes.get_decorated_function()
     result = compare_symbols(decorated, decorated_reference)
     assert result.match_result is MatchResult.MATCH
コード例 #13
0
 def test_compare_overridden_classmethod(
         self, mypy_nodes: MypyNodeFactory) -> None:
     override, override_meth = mypy_nodes.get_overridden_classmethod()
     result = compare_symbols(override, override_meth)
     assert result.match_result is MatchResult.MATCH
コード例 #14
0
 def test_argument_names_wrong_does_mismatch(
         self, mypy_nodes: MypyNodeFactory) -> None:
     meth, meth_ref = mypy_nodes.get_argument_names_wrong()
     result = compare_symbols(meth, meth_ref)
     assert result.match_result is MatchResult.MISMATCH
コード例 #15
0
 def test_return_type_less_specific_does_match(
         self, mypy_nodes: MypyNodeFactory) -> None:
     meth, meth_ref = mypy_nodes.get_return_type_less_specific()
     result = compare_symbols(meth, meth_ref)
     assert result.match_result is MatchResult.MATCH
コード例 #16
0
    def test_type_infos_with_same_name_match(
            self, mypy_nodes: MypyNodeFactory) -> None:
        cls, cls_reference = mypy_nodes.get_class()
        result = compare_symbols(cls, cls_reference)

        assert result.match_result is MatchResult.MATCH
コード例 #17
0
 def test_generated_has_no_parameters(self,
                                      mypy_nodes: MypyNodeFactory) -> None:
     func_def, func_def_reference = mypy_nodes.get_mismatch_with_zero_parameters(
     )
     result = compare_symbols(func_def, func_def_reference)
     assert result.match_result is MatchResult.MISMATCH
コード例 #18
0
 def test_compare_classmethod(self, mypy_nodes: MypyNodeFactory) -> None:
     meth, meth_ref = mypy_nodes.get_classmethod()
     result = compare_symbols(meth, meth_ref)
     assert result.match_result is MatchResult.MATCH
コード例 #19
0
 def test_return_type_wrong(self, mypy_nodes: MypyNodeFactory) -> None:
     meth, meth_ref = mypy_nodes.get_return_type_wrong()
     result = compare_symbols(meth, meth_ref)
     assert result.match_result is MatchResult.MISMATCH
コード例 #20
0
 def test_mismatching_with_additional_kwarg_star2(
         self, mypy_nodes: MypyNodeFactory) -> None:
     func, func_ref = mypy_nodes.get_mismatching_with_additional_kwarg_star2(
     )
     result = compare_symbols(func, func_ref)
     assert_mismatch(result)
コード例 #21
0
 def test_func_def_mismatches_when_handwritten_stub_has_additional_args(
         self, mypy_nodes: MypyNodeFactory) -> None:
     func_def, func_def_reference = mypy_nodes.get_additional_args_node()
     result = compare_symbols(func_def, func_def_reference)
     assert result.match_result is MatchResult.MISMATCH
コード例 #22
0
 def test_matching_functions(self, mypy_nodes: MypyNodeFactory) -> None:
     func_def, func_ref = mypy_nodes.get_matching_func_node()
     result = compare_symbols(func_def, func_ref)
     assert_match(result)