示例#1
0
    def render(self, **kwargs: Any):
        from dvc.ui import ui

        if kwargs.pop("csv", False):
            ui.write(self.to_csv(), end="")
        else:
            ui.table(self, headers=self.keys(), **kwargs)
示例#2
0
def test_rich_headerless(capsys: CaptureFixture[str]):
    ui.table(
        [("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
        rich_table=True,
    )
    captured = capsys.readouterr()
    assert [row.strip() for row in captured.out.splitlines()
            if row.strip()] == ["foo   bar", "foo1  bar1", "foo2  bar2"]
示例#3
0
def test_plain_headerless(capsys: CaptureFixture[str]):
    ui.table([("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")], )
    captured = capsys.readouterr()
    assert captured.out == textwrap.dedent("""\
        foo   bar
        foo1  bar1
        foo2  bar2
    """)
示例#4
0
def test_rich_styles(capsys: CaptureFixture[str], extra_opts):
    ui.table([("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
             headers=["first", "second"],
             rich_table=True,
             **extra_opts)
    # not able to test the actual style for now
    captured = capsys.readouterr()
    assert [row.strip() for row in captured.out.splitlines() if row.strip()
            ] == ["first  second", "foo    bar", "foo1   bar1", "foo2   bar2"]
示例#5
0
def test_rich_pager(mocker: MockerFixture):
    pager_mock = mocker.patch("dvc.utils.pager.pager")

    ui.table(
        [("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
        headers=["first", "second"],
        rich_table=True,
        pager=True,
    )
    received_text = pager_mock.call_args[0][0]
    assert [row.strip() for row in received_text.splitlines() if row.strip()
            ] == ["first  second", "foo    bar", "foo1   bar1", "foo2   bar2"]
示例#6
0
def test_plain(capsys: CaptureFixture[str]):
    ui.table(
        [("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
        headers=["first", "second"],
    )
    captured = capsys.readouterr()
    assert captured.out == textwrap.dedent("""\
        first    second
        foo      bar
        foo1     bar1
        foo2     bar2
    """)
示例#7
0
def test_plain_pager(mocker: MockerFixture):
    pager_mock = mocker.patch("dvc.utils.pager.pager")
    ui.table(
        [("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
        headers=["first", "second"],
        pager=True,
    )

    pager_mock.assert_called_once_with(
        textwrap.dedent("""\
            first    second
            foo      bar
            foo1     bar1
            foo2     bar2"""))
示例#8
0
def test_plain_md(capsys: CaptureFixture[str]):
    ui.table(
        [("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
        headers=["first", "second"],
        markdown=True,
    )
    captured = capsys.readouterr()
    assert captured.out == textwrap.dedent("""\
        | first   | second   |
        |---------|----------|
        | foo     | bar      |
        | foo1    | bar1     |
        | foo2    | bar2     |\n
    """)
示例#9
0
def test_rich_border(capsys: CaptureFixture[str]):
    ui.table(
        [("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
        headers=["first", "second"],
        rich_table=True,
        borders="simple",
    )
    captured = capsys.readouterr()
    assert [row.strip() for row in captured.out.splitlines()
            if row.strip()] == [
                "first   second",
                "────────────────",
                "foo     bar",
                "foo1    bar1",
                "foo2    bar2",
            ]
示例#10
0
    def run(self):
        from dvc.ui import ui

        def log_error(relpath: str, exc: Exception):
            if self.args.fail:
                raise exc
            logger.debug("Stages from %s failed to load", relpath)

        # silence stage collection error by default
        self.repo.stage_collection_error_handler = log_error

        stages = self._get_stages()
        data = prepare_stages_data(stages, description=not self.args.name_only)
        ui.table(data.items())

        return 0
示例#11
0
文件: diff.py 项目: nik123/dvc
def _show_markdown(diff, show_hash=False, hide_missing=False):
    headers = ["Status", "Hash", "Path"] if show_hash else ["Status", "Path"]
    rows = []
    statuses = ["added", "deleted", "renamed", "modified"]
    if not hide_missing:
        statuses.append("not in cache")

    for status in statuses:
        entries = diff.get(status, [])
        if not entries:
            continue
        for entry in entries:
            path = entry["path"]
            if isinstance(path, dict):
                path = f"{path['old']} -> {path['new']}"
            if show_hash:
                check_sum = _digest(entry.get("hash", ""))
                rows.append([status, check_sum, path])
            else:
                rows.append([status, path])

    ui.table(rows, headers=headers, markdown=True)
示例#12
0
    def render(self, **kwargs: Any):
        from dvc.ui import ui

        ui.table(self, headers=self.keys(), **kwargs)
示例#13
0
def test_empty_markdown(capsys: CaptureFixture[str]):
    ui.table([], headers=["Col1", "Col2"], markdown=True)
    out, err = capsys.readouterr()
    assert (out, err) == ("| Col1   | Col2   |\n|--------|--------|\n\n", "")
示例#14
0
def test_empty(capsys: CaptureFixture[str], rich_table: str):
    ui.table([], rich_table=rich_table)
    out, err = capsys.readouterr()
    assert (out, err) == ("", "")