示例#1
0
    def test_print_initialization(self, stdout):
        printer = ProgressPrinter()
        write_queue = []
        def write_action(args):
            write_queue.append(args)

        stdout.write = Mock(side_effect = write_action)
        printer.print_progress([], False)
        self.assertEqual(len(write_queue), 1)
        self.assertEqual(write_queue[0], "\rinitializing...")
示例#2
0
    def test_print_initialization(self, stdout):
        printer = ProgressPrinter()
        write_queue = []

        def write_action(args):
            write_queue.append(args)

        stdout.write = Mock(side_effect=write_action)
        printer.print_progress([], False)
        self.assertEqual(len(write_queue), 1)
        self.assertEqual(write_queue[0], "\rinitializing...")
示例#3
0
    def test_print_receive_progress(self, stdout):
        printer = ProgressPrinter()
        write_queue = []
        def write_action(args):
            write_queue.append(args)

        stdout.write = Mock(side_effect = write_action)
        printer.print_progress([], False)
        printer.print_progress([{"progress": 30.0, "tasks_info": {"retries": 0}}], False)

        self.assertEqual(len(write_queue), 2)
        self.assertEqual(write_queue[0], "\rinitializing...")
        self.assertEqual(write_queue[1], "\r[=======..................]  30.00% Tasks retries:0 Time 0:00:00")
示例#4
0
    def test_multiple_progress_come_right_after_initializing_stage(self, stdout):
        printer = ProgressPrinter()
        write_queue = []
        def write_action(args):
            write_queue.append(args)

        stdout.write = Mock(side_effect = write_action)
        printer.print_progress([], False)
        printer.print_progress([{"progress": 100.0, "tasks_info": {"retries": 0}},
                                {"progress": 100.0, "tasks_info": {"retries": 0}},
                                {"progress": 50.0, "tasks_info": {"retries": 0}}], True)

        self.assertEqual(len(write_queue), 4)
        self.assertEqual(write_queue[0], "\rinitializing...")
        self.assertEqual(write_queue[1], "\r[=========================] 100.00% Tasks retries:0 Time 0:00:00\n")
        self.assertEqual(write_queue[2], "\r[=========================] 100.00% Tasks retries:0 Time 0:00:00\n")
        self.assertEqual(write_queue[3], "\r[============.............]  50.00% Tasks retries:0 Time 0:00:00\n")
示例#5
0
    def test_multiple_progress_come_right_after_initializing_stage(
            self, stdout):
        printer = ProgressPrinter()
        write_queue = []

        def write_action(args):
            write_queue.append(args)

        stdout.write = Mock(side_effect=write_action)
        printer.print_progress([], False)
        printer.print_progress([{
            "progress": 100.0,
            "tasks_info": {
                "retries": 0
            }
        }, {
            "progress": 100.0,
            "tasks_info": {
                "retries": 0
            }
        }, {
            "progress": 50.0,
            "tasks_info": {
                "retries": 0
            }
        }], True)

        self.assertEqual(len(write_queue), 4)
        self.assertEqual(write_queue[0], "\rinitializing...")
        self.assertEqual(
            write_queue[1],
            "\r[=========================] 100.00% Tasks retries:0 Time 0:00:00\n"
        )
        self.assertEqual(
            write_queue[2],
            "\r[=========================] 100.00% Tasks retries:0 Time 0:00:00\n"
        )
        self.assertEqual(
            write_queue[3],
            "\r[============.............]  50.00% Tasks retries:0 Time 0:00:00\n"
        )
示例#6
0
    def test_print_receive_progress(self, stdout):
        printer = ProgressPrinter()
        write_queue = []

        def write_action(args):
            write_queue.append(args)

        stdout.write = Mock(side_effect=write_action)
        printer.print_progress([], False)
        printer.print_progress([{
            "progress": 30.0,
            "tasks_info": {
                "retries": 0
            }
        }], False)

        self.assertEqual(len(write_queue), 2)
        self.assertEqual(write_queue[0], "\rinitializing...")
        self.assertEqual(
            write_queue[1],
            "\r[=======..................]  30.00% Tasks retries:0 Time 0:00:00"
        )