mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
Add unit tests for svtplay.output.progressbar
This commit is contained in:
parent
53ecb46338
commit
1ef76e2f9d
0
lib/svtplay/tests/__init__.py
Normal file
0
lib/svtplay/tests/__init__.py
Normal file
61
lib/svtplay/tests/output.py
Normal file
61
lib/svtplay/tests/output.py
Normal file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/python
|
||||
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):
|
||||
svtplay.output.progressbar(100, 0)
|
||||
self.assertEqual(
|
||||
self.mockfile.read(),
|
||||
"\r[000/100][..................................................] "
|
||||
)
|
||||
|
||||
def test_progress_1_100(self):
|
||||
svtplay.output.progressbar(100, 1)
|
||||
self.assertEqual(
|
||||
self.mockfile.read(),
|
||||
"\r[001/100][..................................................] "
|
||||
)
|
||||
|
||||
def test_progress_2_100(self):
|
||||
svtplay.output.progressbar(100, 2)
|
||||
self.assertEqual(
|
||||
self.mockfile.read(),
|
||||
"\r[002/100][=.................................................] "
|
||||
)
|
||||
|
||||
def test_progress_50_100(self):
|
||||
svtplay.output.progressbar(100, 50)
|
||||
self.assertEqual(
|
||||
self.mockfile.read(),
|
||||
"\r[050/100][=========================.........................] "
|
||||
)
|
||||
|
||||
def test_progress_100_100(self):
|
||||
svtplay.output.progressbar(100, 100)
|
||||
self.assertEqual(
|
||||
self.mockfile.read(),
|
||||
"\r[100/100][==================================================] "
|
||||
)
|
||||
|
||||
def test_progress_20_100_msg(self):
|
||||
svtplay.output.progressbar(100, 20, "msg")
|
||||
self.assertEqual(
|
||||
self.mockfile.read(),
|
||||
"\r[020/100][==========........................................] msg"
|
||||
)
|
Loading…
Reference in New Issue
Block a user