コード例 #1
0
    def test_display_without_start(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 50)
        bar.display()

        expected = self.generate_output(
            '  0/50 [>---------------------------]   0%')

        self.assertEqual(expected, self.get_output_content(output))
コード例 #2
0
    def test_percent_not_hundred_before_complete(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 200)
        bar.start()
        bar.display()
        bar.advance(199)
        bar.advance()

        expected = self.generate_output([
            '   0/200 [>---------------------------]   0%',
            '   0/200 [>---------------------------]   0%',
            ' 199/200 [===========================>]  99%',
            ' 200/200 [============================] 100%',
        ])

        self.assertEqual(expected, self.get_output_content(output))
コード例 #3
0
    def test_percent(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 50)
        bar.start()
        bar.display()
        bar.advance()
        bar.advance()

        expected = self.generate_output([
            '  0/50 [>---------------------------]   0%',
            '  0/50 [>---------------------------]   0%',
            '  1/50 [>---------------------------]   2%',
            '  2/50 [=>--------------------------]   4%',
        ])

        self.assertEqual(expected, self.get_output_content(output))
コード例 #4
0
    def test_set_current_progress(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 50)
        bar.start()
        bar.display()
        bar.advance()
        bar.set_progress(15)
        bar.set_progress(25)

        expected = self.generate_output([
            '  0/50 [>---------------------------]   0%',
            '  0/50 [>---------------------------]   0%',
            '  1/50 [>---------------------------]   2%',
            ' 15/50 [========>-------------------]  30%',
            ' 25/50 [==============>-------------]  50%',
        ])

        self.assertEqual(expected, self.get_output_content(output))
コード例 #5
0
    def test_overwrite_with_shorter_line(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 50)
        bar.set_format(' %current%/%max% [%bar%] %percent:3s%%')
        bar.start()
        bar.display()
        bar.advance()

        # Set shorter format
        bar.set_format(' %current%/%max% [%bar%]')
        bar.advance()

        expected = self.generate_output([
            '  0/50 [>---------------------------]   0%',
            '  0/50 [>---------------------------]   0%',
            '  1/50 [>---------------------------]   2%',
            '  2/50 [=>--------------------------]     ',
        ])

        self.assertEqual(expected, self.get_output_content(output))
コード例 #6
0
    def test_display_with_quiet_verbosity(self):
        output = self.get_output_stream(verbosity=StreamOutput.VERBOSITY_QUIET)
        bar = ProgressBar(output, 50)
        bar.display()

        self.assertEqual('', self.get_output_content(output))