Esempio n. 1
0
    def test_customizations(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 10)
        bar.set_bar_width(10)
        bar.set_bar_character('_')
        bar.set_empty_bar_character(' ')
        bar.set_progress_character('/')
        bar.set_format(' %current%/%max% [%bar%] %percent:3s%%')
        bar.start()
        bar.advance()

        expected = self.generate_output(
            ['  0/10 [/         ]   0%', '  1/10 [_/        ]  10%'])

        self.assertEqual(expected, self.get_output_content(output))
Esempio n. 2
0
    def test_multiline_format(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 3)
        bar.set_format('%bar%\nfoobar')

        bar.start()
        bar.advance()
        bar.clear()
        bar.finish()

        expected = self.generate_output([
            '>---------------------------\nfoobar',
            '=========>------------------\nfoobar                      ',
            '                            \n                            ',
            '============================\nfoobar                      '
        ])

        self.assertEqual(expected, self.get_output_content(output))
Esempio n. 3
0
    def test_format(self):
        expected = self.generate_output([
            '  0/10 [>---------------------------]   0%',
            ' 10/10 [============================] 100%',
            ' 10/10 [============================] 100%'
        ])

        # max in construct, no format
        output = self.get_output_stream()
        bar = ProgressBar(output, 10)
        bar.start()
        bar.advance(10)
        bar.finish()

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

        # max in start, no format
        output = self.get_output_stream()
        bar = ProgressBar(output)
        bar.start(10)
        bar.advance(10)
        bar.finish()

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

        # max in construct, explicit format before
        output = self.get_output_stream()
        bar = ProgressBar(output, 10)
        bar.set_format('normal')
        bar.start()
        bar.advance(10)
        bar.finish()

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

        # max in start, explicit format before
        output = self.get_output_stream()
        bar = ProgressBar(output)
        bar.set_format('normal')
        bar.start(10)
        bar.advance(10)
        bar.finish()

        self.assertEqual(expected, self.get_output_content(output))
Esempio n. 4
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))