Пример #1
0
    def test_symbol_object_gives_correct_source_for_annotated_symbol(
            self, symbol, arg_specs, annotated_symbol):
        normalized_symbol = NormalizedSymbol(symbol, None, None)
        module_qualname = get_module_qualname(symbol, project_root_path)

        module_annotated_data_items = {
            create_data_item_id(module_qualname, normalized_symbol.qualname):
            arg_specs[normalized_symbol.qualname]
        }

        queue = collections.deque()
        annotated_symbol_object = symbol_collector.convert_to_symbol_object(
            project_root_path, NormalizedSymbol(symbol, None, None),
            is_non_annotated_symbol_of_interest)
        queue.appendleft(annotated_symbol_object)
        while queue:
            current = queue.pop()
            for nested_symbol in current.nested_symbols:
                queue.appendleft(nested_symbol)
                data_item_id = create_data_item_id(module_qualname,
                                                   nested_symbol.qualname)
                module_annotated_data_items[data_item_id] = arg_specs[
                    nested_symbol.qualname]

        symbol_object = symbol_collector.convert_to_symbol_object(
            project_root_path, NormalizedSymbol(symbol, None, None),
            is_non_annotated_symbol_of_interest)
        symbol_object.module = module_qualname
        symbol_object.qualname = normalized_symbol.qualname

        annotated_source = symbol_object.get_annotated_source(
            module_annotated_data_items)

        assert annotated_source == pavo_cristatus_get_source(annotated_symbol)
Пример #2
0
def symbols_object_generator(symbol_object):
    base64_data = base64.b64encode(pickle.dumps(DummyPickled()))
    data_item_data = str(base64_data, "utf-8")
    yield create_data_item_id(
        get_module_qualname_from_source(symbol_object.normalized_symbol.source,
                                        project_root_path),
        symbol_object.qualname), data_item_data
    for nested_symbol in symbol_object.nested_symbols:
        base64_data = base64.b64encode(pickle.dumps(DummyPickled()))
        data_item_data = str(base64_data, "utf-8")
        yield create_data_item_id(
            get_module_qualname_from_source(
                nested_symbol.normalized_symbol.source, project_root_path),
            symbol_object.qualname), data_item_data
Пример #3
0
def test_symbol_signature_restorer_interaction(monkeypatch, symbol, arg_specs,
                                               annotated_symbol):
    monkeypatch.setattr(utilities, pavo_cristatus_open.__name__,
                        safe_open_hook)

    normalized_symbol = NormalizedSymbol(symbol, None, None)

    module_qualname = get_module_qualname_from_source(normalized_symbol.source,
                                                      project_root_path)

    module_annotated_data_items = {
        create_data_item_id(module_qualname, normalized_symbol.qualname):
        arg_specs[normalized_symbol.qualname]
    }

    queue = collections.deque()
    symbol_object = symbol_collector.convert_to_symbol_object(
        project_root_path, normalized_symbol,
        is_non_annotated_symbol_of_interest)
    queue.appendleft(symbol_object)
    while queue:
        current = queue.pop()
        for nested_symbol in current.nested_symbols:
            queue.appendleft(nested_symbol)
            data_item_id = create_data_item_id(module_qualname,
                                               nested_symbol.qualname)
            module_annotated_data_items[data_item_id] = arg_specs[
                nested_symbol.qualname]

    python_file = get_python_file_from_symbol_object(symbol_object)
    module_symbols = ModuleSymbols(
        inspect.getmodule(symbol_object.normalized_symbol), python_file,
        symbol_object.normalized_symbol.qualname, {symbol_object})
    write_verifier.reset(
        module_symbols.get_annotated_source(module_annotated_data_items))

    # Due to file_write_verifier's structure, there can only be one ModuleSymbols per test
    result = interact({module_symbols: module_annotated_data_items})
    assert result.status == PavoCristatusStatus.SUCCESS and result.result
    write_verifier.verify()
Пример #4
0
    def test_symbol_object_gives_correct_source_for_non_annotated_symbol(
            self, symbols):
        non_annotated_symbol, annotated_symbol = symbols
        non_annotated_normalized_symbol = NormalizedSymbol(
            non_annotated_symbol, None, None)
        annotated_normalized_symbol = NormalizedSymbol(annotated_symbol, None,
                                                       None)
        module_qualname = get_module_qualname(non_annotated_symbol,
                                              project_root_path)
        module_annotated_data_items = {
            create_data_item_id(module_qualname, non_annotated_normalized_symbol.qualname):
            inspect.getfullargspec(annotated_normalized_symbol.symbol)
        }

        queue = collections.deque()
        queue.appendleft(annotated_normalized_symbol)
        while queue:
            current = queue.pop()
            for nested_symbol in symbol_collector.convert_to_symbol_object(
                    project_root_path, current,
                    is_annotated_symbol_of_interest).nested_symbols:
                queue.appendleft(nested_symbol.normalized_symbol)
                module_annotated_data_items[create_data_item_id(
                    module_qualname,
                    nested_symbol.qualname)] = inspect.getfullargspec(
                        nested_symbol.normalized_symbol.symbol)

        symbol_object = symbol_collector.convert_to_symbol_object(
            project_root_path, non_annotated_normalized_symbol,
            is_non_annotated_symbol_of_interest)
        annotated_source = symbol_object.get_annotated_source(
            module_annotated_data_items)
        expected_source_lines = pavo_cristatus_split(
            pavo_cristatus_get_source(annotated_symbol))
        annotated_source_lines = pavo_cristatus_split(annotated_source)

        assert len(annotated_source_lines) == len(expected_source_lines)
        assert self.get_count_of_mismatched_lines(expected_source_lines,
                                                  annotated_source_lines) == 0
def test_annotated_symbol_presenter_interaction(monkeypatch, symbol, arg_specs,
                                                annotated_symbol):
    monkeypatch.setattr(console_presenter, pavo_cristatus_print.__name__,
                        print_hook)

    module_qualname = get_module_qualname(symbol, project_root_path)
    module_annotated_data_items = {
        create_data_item_id(module_qualname, symbol.__qualname__):
        arg_specs[symbol.__qualname__]
    }
    queue = collections.deque()
    normalized_symbol = NormalizedSymbol(symbol, None, None)
    symbol_object = symbol_collector.convert_to_symbol_object(
        project_root_path, normalized_symbol,
        is_non_annotated_symbol_of_interest)
    queue.appendleft(symbol_object)
    while queue:
        current = queue.pop()
        for nested_symbol in current.nested_symbols:
            queue.appendleft(nested_symbol)
            data_item_id = create_data_item_id(module_qualname,
                                               nested_symbol.qualname)
            module_annotated_data_items[data_item_id] = arg_specs[
                nested_symbol.qualname]

    python_file = get_python_file_from_symbol_object(symbol_object)
    module = sys.modules[symbol_object.normalized_symbol.module]
    module_symbols = ModuleSymbols(module, python_file, module_qualname,
                                   {symbol_object})

    write_verifier.reset(
        module_symbols.get_annotated_source(module_annotated_data_items))

    result = interact({module_symbols: module_annotated_data_items},
                      present_annotated_symbols)
    assert result.status == PavoCristatusStatus.SUCCESS
    write_verifier.verify()
Пример #6
0
def read_data_item(module_symbols, symbol, repository, accumulator):
    """
    retrieve data item from repository
    :param module_symbols: module_symbols that we use to retrieve data item
    :param symbol: symbol that we use to retrieve data item
    :param repository: a repository object where we retrieve a data item from
    :param accumulator: accumulates the read data items
    :return: bool
    """
    data_item_id = create_data_item_id(module_symbols.qualname, symbol.qualname)
    data_item = repository.read_data_item(data_item_id)
    if not data_item:
        # TODO: look into this
        #logger.error("could not successfully operate on data item. data id: {0}".format(data_item_id))
        #return False
        return True
    data_item_data = base64.b64decode(data_item.data)
    accumulator[module_symbols][data_item.id] = pickle.loads(data_item_data)
    return True