Esempio n. 1
0
    def info(
        self,
        max_rows: int = None,
        max_length: int = None,
        show_values: bool = False,
        path: tuple = None,
    ):
        """Print the content to the stdout.

        Parameters
        ----------
        max_rows :
            The maximum number of rows that will be printed. If rows are cut, a
            corresponding message will be printed
        max_length :
            The maximum line length. Longer lines will be truncated
        show_values :
            Set to `True` if primitive values should be displayed
        path
            tuple representing the lookup path in the yaml/asdf tree

        """
        tree = {
            key: value
            for key, value in self._asdf_handle.tree.items()
            if key not in ["asdf_library", "history"]
        }
        if path is not None:
            tree = get_path(tree, path)
        asdf.info(tree,
                  max_rows=max_rows,
                  max_cols=max_length,
                  show_values=show_values)
Esempio n. 2
0
 def _assert_correct_info(node_or_path):
     asdf.info(node_or_path)
     captured = capsys.readouterr()
     assert "foo" in captured.out
     assert "bar" in captured.out
     assert "baz" in captured.out
Esempio n. 3
0
def test_info_module(capsys, tmpdir):
    tree = dict(foo=42,
                bar="hello",
                baz=np.arange(20),
                nested={
                    "woo": "hoo",
                    "yee": "haw"
                },
                long_line="a" * 100)
    af = asdf.AsdfFile(tree)

    def _assert_correct_info(node_or_path):
        asdf.info(node_or_path)
        captured = capsys.readouterr()
        assert "foo" in captured.out
        assert "bar" in captured.out
        assert "baz" in captured.out

    _assert_correct_info(af)
    _assert_correct_info(af.tree)

    tmpfile = str(tmpdir.join("written.asdf"))
    af.write_to(tmpfile)
    af.close()

    _assert_correct_info(tmpfile)
    _assert_correct_info(pathlib.Path(tmpfile))

    for i in range(1, 10):
        asdf.info(af, max_rows=i)
        lines = capsys.readouterr().out.strip().split("\n")
        assert len(lines) <= i

    asdf.info(af, max_cols=80)
    assert "(truncated)" in capsys.readouterr().out
    asdf.info(af, max_cols=None)
    captured = capsys.readouterr().out
    assert "(truncated)" not in captured
    assert "a" * 100 in captured

    asdf.info(af, show_values=True)
    assert "hello" in capsys.readouterr().out
    asdf.info(af, show_values=False)
    assert "hello" not in capsys.readouterr().out

    tree = {"foo": ["alpha", "bravo", "charlie", "delta", "eagle"]}
    af = asdf.AsdfFile(tree)
    asdf.info(af, max_rows=(None, ))
    assert "alpha" not in capsys.readouterr().out
    for i in range(1, 5):
        asdf.info(af, max_rows=(None, i))
        captured = capsys.readouterr()
        for val in tree["foo"][0:i - 1]:
            assert val in captured.out
        for val in tree["foo"][i - 1:]:
            assert val not in captured.out