Esempio n. 1
0
def _get_sorted_vars(group_var_counts: Dict[Optional[str], Counter], track: Track) -> List[Tuple]:
    all_known_vars: Set[Tuple] = set()
    for counter in group_var_counts.values():
        for key in counter:
            all_known_vars.add(key)
    for variable in track.values():
        path: Tuple = tuple(variable.absolute_path)
        all_known_vars.add(path)
    sorted_vars: List[Tuple] = sorted(all_known_vars)
    return sorted_vars
Esempio n. 2
0
def _get_sorted_vars(group_var_counts: Dict[Optional[str], Dict[Tuple[str, ...], int]], track: Track) \
        -> List[Tuple[str, ...]]:
    all_known_vars: Set[Tuple[str, ...]] = set()
    for counter in group_var_counts.values():
        for key in counter:
            all_known_vars.add(key)
    for variable in track.values():
        # Exclude transient variable from the coverage report
        if not (variable.transient or variable.has_transient_ancestor):
            path: Tuple[str, ...] = tuple(variable.absolute_path)
            all_known_vars.add(path)
    sorted_vars: List[Tuple[str, ...]] = sorted(all_known_vars)
    return sorted_vars
Esempio n. 3
0
    def __init__(self, target: Track, failsafe: bool = False):
        logging.info('Initializing translator for track "%s".' % target.name)
        if failsafe:
            logging.warning(
                "Translation errors will be ignored! Use at your own risk!")

        assert target.source is not None
        self.source: Track = target.source

        # We need to group by variables by parent to be able to efficiently do
        # a recursion in the translate function
        # NB: `defaultdict(list)` means "Create a dictionary that automatically supplies missing values"--very nice
        logging.debug("Grouping variables by parents.")
        self.target_variables_by_parent: Dict[
            Optional[VariableId], List[Variable]] = defaultdict(list)
        for variable in target.values():  # type: Variable
            self.target_variables_by_parent[variable.parent].append(variable)

        # when failsafe is true exceptions are caught and ignored
        self.failsafe = failsafe
Esempio n. 4
0
    def __init__(self, target: Track, create_document_value_provider: "Callable[[Dict[str, Any]], DocumentValueProvider]", failsafe: bool = False):
        logging.info('Initializing translator for track "%s".' % target.name)
        if failsafe:
            logging.warning("Translation errors will be ignored! Use at your own risk!")

        assert target.source is not None
        self.source: Track = target.source
        self.create_document_value_provider = create_document_value_provider

        # We need to group by variables by parent to be able to efficiently do
        # a recursion in the translate function
        # NB: `defaultdict(list)` means "Create a dictionary that automatically supplies missing values"--very nice
        logging.debug("Grouping variables by parents.")
        self.target_variables_by_parent: Dict[Optional[VariableId], List[Variable]] = defaultdict(list)
        for variable in target.values():  # type: Variable
            self.target_variables_by_parent[variable.parent].append(variable)

        # Sort children by sort order.
        for parent_id, children in self.target_variables_by_parent.items():
            children.sort(key=lambda child: child.sort_order)

        # when failsafe is true exceptions are caught and ignored
        self.failsafe = failsafe