2013-03-02 00:00:32 +01:00
|
|
|
#!/usr/bin/python
|
2013-03-02 21:26:28 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2013-03-02 22:01:25 +01:00
|
|
|
|
|
|
|
# The unittest framwork doesn't play nice with pylint:
|
|
|
|
# pylint: disable-msg=C0103
|
|
|
|
|
2013-03-02 00:00:32 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import unittest
|
|
|
|
import svtplay.output
|
|
|
|
|
|
|
|
class mockfile(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.content = []
|
|
|
|
|
|
|
|
def write(self, string):
|
|
|
|
self.content.append(string)
|
|
|
|
|
|
|
|
def read(self):
|
|
|
|
return self.content.pop()
|
|
|
|
|
|
|
|
class progressbarTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.mockfile = mockfile()
|
|
|
|
svtplay.output.progress_stream = self.mockfile
|
|
|
|
|
|
|
|
def test_0_100(self):
|
2013-03-02 21:28:58 +01:00
|
|
|
svtplay.output.progressbar(100, 0)
|
2013-03-02 00:00:32 +01:00
|
|
|
self.assertEqual(
|
2013-03-02 21:28:58 +01:00
|
|
|
self.mockfile.read(),
|
|
|
|
"\r[000/100][..................................................] "
|
|
|
|
)
|
2013-03-02 00:00:32 +01:00
|
|
|
|
|
|
|
def test_progress_1_100(self):
|
2013-03-02 21:28:58 +01:00
|
|
|
svtplay.output.progressbar(100, 1)
|
2013-03-02 00:00:32 +01:00
|
|
|
self.assertEqual(
|
2013-03-02 21:28:58 +01:00
|
|
|
self.mockfile.read(),
|
|
|
|
"\r[001/100][..................................................] "
|
|
|
|
)
|
2013-03-02 00:00:32 +01:00
|
|
|
|
|
|
|
def test_progress_2_100(self):
|
2013-03-02 21:28:58 +01:00
|
|
|
svtplay.output.progressbar(100, 2)
|
2013-03-02 00:00:32 +01:00
|
|
|
self.assertEqual(
|
2013-03-02 21:28:58 +01:00
|
|
|
self.mockfile.read(),
|
|
|
|
"\r[002/100][=.................................................] "
|
|
|
|
)
|
2013-03-02 00:00:32 +01:00
|
|
|
|
|
|
|
def test_progress_50_100(self):
|
2013-03-02 21:28:58 +01:00
|
|
|
svtplay.output.progressbar(100, 50)
|
2013-03-02 00:00:32 +01:00
|
|
|
self.assertEqual(
|
2013-03-02 21:28:58 +01:00
|
|
|
self.mockfile.read(),
|
|
|
|
"\r[050/100][=========================.........................] "
|
|
|
|
)
|
2013-03-02 00:00:32 +01:00
|
|
|
|
|
|
|
def test_progress_100_100(self):
|
2013-03-02 21:28:58 +01:00
|
|
|
svtplay.output.progressbar(100, 100)
|
2013-03-02 00:00:32 +01:00
|
|
|
self.assertEqual(
|
2013-03-02 21:28:58 +01:00
|
|
|
self.mockfile.read(),
|
|
|
|
"\r[100/100][==================================================] "
|
|
|
|
)
|
2013-03-02 00:00:32 +01:00
|
|
|
|
|
|
|
def test_progress_20_100_msg(self):
|
2013-03-02 21:28:58 +01:00
|
|
|
svtplay.output.progressbar(100, 20, "msg")
|
2013-03-02 00:00:32 +01:00
|
|
|
self.assertEqual(
|
2013-03-02 21:28:58 +01:00
|
|
|
self.mockfile.read(),
|
|
|
|
"\r[020/100][==========........................................] msg"
|
|
|
|
)
|