Exemplo n.º 1
0
    def argument_lists(self, request) -> ARG_FIXTURE_TYPE:  # noqa: ANN001
        """
        Build a pair of lists of arguments to compare and return as a (truth, parsed) tuple.

        `argument_test_cases` is a dictionary of the TestCase named tuples that provide the source
        code to be parsed and a list of Argument objects to be used as truth values

        A list of parsed Argument objects is taken from the class-level source parser

        The function name is also returned in order to provide a more verbose message for a failed
        assertion

        Note: For testing purposes, Argument lineno and col_offset are ignored so these are set to
        dummy values in the truth dictionary
        """
        test_case_name, test_case = request.param

        # Since positional-only args are part of these test cases, short-circuit for Python < 3.8 if
        # the `py38_only` boolean flag is set in the test case
        if test_case.py38_only and sys.version_info < (3, 8):
            pytest.skip("Test case expected to fail for Python < 3.8")

        truth_arguments = test_case.args

        tree, lines = parse_source(test_case.src)
        visitor = FunctionVisitor(lines)
        visitor.visit(tree)
        parsed_arguments = visitor.function_definitions[0].args

        return truth_arguments, parsed_arguments, test_case_name
Exemplo n.º 2
0
    def functions(self, request) -> FUNC_FIXTURE_TYPE:  # noqa: ANN001
        """
        Build a pair of Function objects to compare and return as a (truth, parsed) tuple.

        `parser_object_attributes.parsed_functions` is a dictionary of the Functions that should be
        parsed out of the testing source code:
          * Keys are the function name, as str
          * Values are the Function object that should be parsed from the source
        """
        test_case_name, test_case = request.param

        truth_functions = test_case.func

        tree, lines = parse_source(test_case.src)
        visitor = FunctionVisitor(lines)
        visitor.visit(tree)
        parsed_functions = visitor.function_definitions

        return truth_functions, parsed_functions, test_case_name
    def argument_lists(self, request) -> ARG_FIXTURE_TYPE:  # noqa: ANN001
        """
        Build a pair of lists of arguments to compare and return as a (truth, parsed) tuple.

        `parser_test_cases` is a dictionary of ParserTestCase named tuples, which provide the
        following:
            * `src` - Source code for the test case to be parsed
            * `args` - A list of Argument objects to be used as the truth values
            * `should_yield_ANN301` - Boolean flag indicating whether the source should yield ANN301

        A list of parsed Argument objects is taken from the class-level source parser

        The function name is also returned in order to provide a more verbose message for a failed
        assertion
        """
        test_case_name, test_case = request.param

        tree, lines = parse_source(test_case.src)
        visitor = FunctionVisitor(lines)
        visitor.visit(tree)
        parsed_arguments = visitor.function_definitions[0].args

        return test_case.args, parsed_arguments, test_case_name