Ejemplo n.º 1
0
 def test_two_messages(self, capfd: Any, printer: TTYPrinter) -> None:
     printer.print("message1")
     printer.print("message2")
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f"message1{linesep}message2{linesep}"
Ejemplo n.º 2
0
class DetailedDockerImageProgress(DockerImageProgress):
    def __init__(self) -> None:
        self._mapping: Dict[str, int] = {}
        self._printer = TTYPrinter()

    def push(self, data: ImageProgressPush) -> None:
        src = click.style(str(data.src), bold=True)
        dst = click.style(str(data.dst), bold=True)
        self._printer.print(f"Pushing image {src} => {dst}")

    def pull(self, data: ImageProgressPull) -> None:
        src = click.style(str(data.src), bold=True)
        dst = click.style(str(data.dst), bold=True)
        self._printer.print(f"Pulling image {src} => {dst}")

    def step(self, data: ImageProgressStep) -> None:
        if data.layer_id:
            if data.layer_id in self._mapping.keys():
                lineno = self._mapping[data.layer_id]
                self._printer.print(data.message, lineno)
            else:
                self._mapping[data.layer_id] = self._printer.total_lines
                self._printer.print(data.message)
        else:
            self._printer.print(data.message)

    def save(self, data: ImageProgressSave) -> None:
        job = click.style(str(data.job), bold=True)
        dst = click.style(str(data.dst), bold=True)
        self._printer.print(f"Saving {job} -> {dst}")

    def commit_started(self, data: ImageCommitStarted) -> None:
        img = click.style(str(data.target_image), bold=True)
        self._printer.print(
            f"Creating image {img} image from the job container")

    def commit_finished(self, data: ImageCommitFinished) -> None:
        self._printer.print("Image created")

    def close(self) -> None:
        self._printer.close()
Ejemplo n.º 3
0
 def test_message_lineno(self, printer: TTYPrinter, capfd: Any) -> None:
     assert printer.total_lines == 0
     printer.print("message1")
     assert printer.total_lines == 1
     printer.print("message1-replace", 0)
     assert printer.total_lines == 1
     printer.print("message3", 2)
     assert printer.total_lines == 3
     printer.print("message7", 6)
     assert printer.total_lines == 7
     printer.print("message2", 1)
     assert printer.total_lines == 7
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert "message1" in out
     assert "message1-replace" in out
     assert "message3" in out
     assert "message7" in out
     assert "message2" in out
     CSI = "\033["
     assert CSI in out
     assert f"{CSI}0A" not in out
     assert f"{CSI}0B" not in out
Ejemplo n.º 4
0
 def test_one_message(self, capfd: Any, printer: TTYPrinter) -> None:
     printer.print("message")
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f"message{linesep}"
Ejemplo n.º 5
0
 def test_no_messages(self, capfd: Any, printer: TTYPrinter) -> None:
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == ""