Exemple #1
0
    def test_non_decorated_output(self):
        output = self.get_output_stream(False)
        bar = ProgressBar(output, 200)
        bar.start()

        for i in range(200):
            bar.advance()

        bar.finish()

        expected = os.linesep.join([
            '   0/200 [>---------------------------]   0%',
            '  20/200 [==>-------------------------]  10%',
            '  40/200 [=====>----------------------]  20%',
            '  60/200 [========>-------------------]  30%',
            '  80/200 [===========>----------------]  40%',
            ' 100/200 [==============>-------------]  50%',
            ' 120/200 [================>-----------]  60%',
            ' 140/200 [===================>--------]  70%',
            ' 160/200 [======================>-----]  80%',
            ' 180/200 [=========================>--]  90%',
            ' 200/200 [============================] 100%',
        ])

        self.assertEqual(expected, self.get_output_content(output))
Exemple #2
0
    def test_finish_without_start(self):
        output = self.get_output_stream()
        bar = ProgressBar(output, 50)
        bar.finish()

        expected = self.generate_output(
            ' 50/50 [============================] 100%')

        self.assertEqual(expected, self.get_output_content(output))
Exemple #3
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))
Exemple #4
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))