Example #1
0
    def test_finish_noprint_when_isquiet_and_randomized_docker_or_istty(self, patched_isatty, seed):
        console.init(quiet=True, assume_tty=False)
        random.seed(seed)
        patched_isatty.return_value = random.choice([True, False])
        console.RALLY_RUNNING_IN_DOCKER = random.choice([True, False])

        width = random.randint(20, 140)
        mock_printer = mock.Mock()
        progress_reporter = console.CmdLineProgressReporter(width=width, printer=mock_printer)
        progress_reporter.finish()
        mock_printer.assert_not_called()
Example #2
0
    def test_finish_prints_when_isnotquiet_and_randomized_assume_tty_or_istty(self, patched_isatty, seed):
        random.seed(seed)
        random_boolean = random.choice([True, False])
        console.init(quiet=False, assume_tty=random_boolean)
        console.RALLY_RUNNING_IN_DOCKER = False
        patched_isatty.return_value = not random_boolean

        width = random.randint(20, 140)
        mock_printer = mock.Mock()
        progress_reporter = console.CmdLineProgressReporter(width=width, printer=mock_printer)
        progress_reporter.finish()
        mock_printer.assert_called_once_with("")
Example #3
0
    def test_noprint_when_isnotquiet_and_nodocker_and_noistty(self, patched_isatty, patched_flush):
        console.init(quiet=False, assume_tty=False)
        patched_isatty.return_value = False
        console.RALLY_RUNNING_IN_DOCKER = False

        message = "Unit test message"
        width = random.randint(20, 140)
        mock_printer = mock.Mock()
        progress_reporter = console.CmdLineProgressReporter(width=width, printer=mock_printer)
        progress_reporter.print(message=message, progress=".")
        mock_printer.assert_not_called()
        patched_flush.assert_not_called()
Example #4
0
    def test_print_when_isquiet_and_any_docker_or_istty(self, patched_isatty, patched_flush, seed):
        console.init(quiet=True, assume_tty=False)
        random.seed(seed)
        patched_isatty.return_value = random.choice([True, False])
        console.RALLY_RUNNING_IN_DOCKER = random.choice([True, False])

        message = "Unit test message"
        width = random.randint(20, 140)
        mock_printer = mock.Mock()
        progress_reporter = console.CmdLineProgressReporter(width=width, printer=mock_printer)

        progress_reporter.print(message=message, progress=".")
        mock_printer.assert_not_called()
        patched_flush.assert_not_called()
Example #5
0
    def test_prints_when_isnotquiet_and_randomized_assume_tty_or_istty(self, patched_isatty, patched_flush, seed):
        random.seed(seed)
        random_boolean = random.choice([True, False])
        console.init(quiet=False, assume_tty=random_boolean)
        console.RALLY_RUNNING_IN_DOCKER = False
        patched_isatty.return_value = not random_boolean

        message = "Unit test message"
        width = random.randint(20, 140)
        mock_printer = mock.Mock()
        progress_reporter = console.CmdLineProgressReporter(width=width, printer=mock_printer)
        progress_reporter.print(message=message, progress=".")
        mock_printer.assert_has_calls([
            mock.call(" " * width, end=""),
            mock.call("\x1b[{}D{}{}.".format(width, message, " "*(width-len(message)-1)), end="")
        ])
        patched_flush.assert_called_once_with()