Ejemplo n.º 1
0
def test_hanging_indent(one_sentence):
    """Test that hanging indents work as expected"""
    width = len(one_sentence) // 2  # Should force fill to three lines
    filled_text = console.fill(one_sentence, width=width, hanging=4)
    num_lines = filled_text.count("\n") + 1
    assert filled_text.count("\n     ") == 0  # 5 spaces indent
    assert filled_text.count("\n    ") == num_lines - 1  # 4 spaces indent
Ejemplo n.º 2
0
def _get_paths() -> str:
    """Get file paths of used files

    Returns:
        Header file path lines
    """
    lines = "[file_paths]\n"
    key_width = 25
    fill_args = dict(width=120,
                     hanging=key_width + 3,
                     break_long_words=False,
                     break_on_hyphens=False)
    path_def = {
        "Broadcast orbit": "gnss_rinex_nav_.",
        "Precise orbit": "gnss_orbit_sp3",
        "Bias": "gnss_sinex_bias",
        "Precise clock": "gnss_rinex_clk",
    }

    for name, file_key in sorted(path_def.items()):
        if file_key == "gnss_rinex_clk":
            if config.tech.clock_product.str != "clk":
                continue
        path = ", ".join(str(p) for p in sorted(pipelines.paths(file_key)))
        lines += console.fill(f"{name:<{key_width}} = {path}", **fill_args)
        lines += "\n"

    lines += "\n\n"
    return lines
Ejemplo n.º 3
0
    def __getattr__(self, key):
        """Get a field from the dataset using the attribute-notation

        This method is called when a field is accessed using a dot, e.g. data.station. This is done by forwarding the
        call to __getitem__.

        Args:
            key:   String, the name of the field.

        Returns:
            Field data. The datatype will depend on the table type.
        """
        try:
            return self.__getitem__(key)
        except KeyError:
            error_msg = "'{}' object has no attribute '{}'".format(
                type(self).__name__, key)
            completions = [f for f in self.fields if f.startswith(key)]
            completion_msg = console.fill(
                ".\nMaybe one of these: " + ", ".join(completions),
                hanging=20,
                replace_whitespace=False,
                break_on_hyphens=False,
            )
            raise AttributeError(
                error_msg + (completion_msg if completions else "")) from None
Ejemplo n.º 4
0
    def entry_as_str(self,
                     width: Optional[builtins.int] = None,
                     key_width: builtins.int = 30,
                     metadata: builtins.bool = True) -> builtins.str:
        """The configuration entry represented as a string

        This is simililar to what is shown by `str(entry)` (and implemented by `__str__`), but has more flexibility.

        Args:
            width:      Width of text for wrapping. Default is width of console.
            key_width:  Width of the key column. Default is 30 characters.
            metadata:   Include metadata like type and help text.

        Returns:
            String representation of the configuration entry.
        """
        lines = list()
        width = console.columns() if width is None else width
        fill_args = dict(width=width,
                         hanging=key_width + 3,
                         break_long_words=False,
                         break_on_hyphens=False)

        # The entry itself
        lines.append(
            console.fill(f"{self._key:<{key_width}} = {self._value}",
                         **fill_args))

        # Metadata, including help text and type hints
        if metadata and self.meta:
            for meta_key, meta_value in self.meta.items():
                if meta_value is None:
                    lines.append(
                        console.fill(f"{self._key}:{meta_key}", **fill_args))
                else:
                    lines.append(
                        console.fill(
                            f"{f'{self._key}:{meta_key}':<{key_width}} = {meta_value}",
                            **fill_args))
            lines.append("")

        return "\n".join(lines)
Ejemplo n.º 5
0
    def __str__(self):
        """A string describing the table

        The string describes the table, including listing the table name, datatype and all the fields. This string is
        mainly meant to be read by humans.

        Returns:
            A string describing the table.
        """
        name_and_type = "  {} ({}): ".format(self.name, self.datatype)
        return console.fill(name_and_type + ", ".join(self.fields),
                            hanging=len(name_and_type))
Ejemplo n.º 6
0
    def __repr__(self):
        """A string describing the dataset

        The string describes the dataset and lists all fields. This string is mainly meant to be used when working
        interactively.

        Note: This is more typically implemented as `__str__` instead of `__repr__`. This is a pragmatic choice to make
        it easier and more informational to work with datasets. The usual `__repr__` string is available in the
        `repr`-property, while we use `__str__` to provide even more information.

        Returns:
            A string describing the dataset.
        """
        description = "{description}: {num_obs} obs\n".format(description=self.description, num_obs=self.num_obs)
        return description + console.fill("Fields: " + ", ".join(self.fields), hanging=8)
Ejemplo n.º 7
0
    def __str__(self):
        """A string describing the table

        The string describes the table, including listing the table name, datatype and all the fields. This string is
        mainly meant to be read by humans. In addition to what is shown by default by Table, we add information about
        which time and other object the position is connected to.

        Returns:
            A string describing the table.
        """
        name_and_type = "  {} ({}): ".format(self.name, self.datatype)
        fields = ", ".join(self.fields)
        time_and_other = " (time: {}, other: {})".format(
            self._time_tbl.name, self._other_tbl.name if self._other_tbl else None
        )
        return console.fill("".join((name_and_type, fields, time_and_other)), hanging=len(name_and_type))
Ejemplo n.º 8
0
def _get_paths() -> str:
    """Get file paths of used files

    Returns:
        Header file path lines
    """
    lines = "[file_paths]\n"
    key_width = 25
    fill_args = dict(width=120, hanging=key_width + 3, break_long_words=False, break_on_hyphens=False)
    path_def = {"Broadcast orbit": "gnss_rinex_nav_."}

    for name, file_key in sorted(path_def.items()):
        path = ", ".join(str(p) for p in sorted(pipelines.paths(file_key)))
        lines += console.fill(f"{name:<{key_width}} = {path}", **fill_args)
        lines += "\n"

    lines += "\n\n"
    return lines
Ejemplo n.º 9
0
def test_fill_one_paragraph(one_paragraph_width_80):
    """Test that one paragraph is filled correctly"""
    non_filled_text = one_paragraph_width_80.replace("\n", " ")
    filled_text = console.fill(non_filled_text, width=80)
    assert filled_text == one_paragraph_width_80
Ejemplo n.º 10
0
def test_fill_short_is_same(two_words):
    """Test that when a short text is filled, the same text is returned (without newline)"""
    filled_text = console.fill(two_words, width=len(two_words) * 2)
    assert filled_text == two_words
Ejemplo n.º 11
0
 def __str__(self) -> str:
     """A string describing the dataset"""
     fields = console.fill(f"Fields: {', '.join(self.fields)}", hanging=8)
     return f"{self!r}\n{fields}"