1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-09 09:59:51 +01:00

test printing results

This commit is contained in:
Viktor Stanchev 2015-09-03 23:29:20 -07:00
parent 383e5a101d
commit 0c2415bb47
2 changed files with 32 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import gzip
import colorama
import urllib.parse as parse
import urllib.request as request
import shutil
from io import BytesIO
import pirate.data
@ -31,8 +32,9 @@ def print(*args, **kwargs):
return builtins.print(*args, **kwargs)
# TODO: extract the name from the search results instead of the magnet link when possible
def search_results(results, local=None):
columns = int(os.popen('stty size', 'r').read().split()[1])
columns = shutil.get_terminal_size((80, 20)).columns
cur_color = 'zebra_0'
if local:

29
tests/test_print.py Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import unittest
from unittest.mock import patch
from unittest.mock import call
import pirate.print
class TestPrint(unittest.TestCase):
def test_print_results(self):
with patch('pirate.print.print') as mock:
results = [{
'magnet': 'dn=name',
'seeds': 1,
'leechers': 2,
'size': ['3','MiB'],
'uploaded': 'never'
}]
pirate.print.search_results(results)
actual = mock.call_args_list
expected = [
call('LINK SEED LEECH RATIO SIZE UPLOAD NAME ', color='header'),
call(' 0 1 2 0.5 3.0 MiB never name ', color='zebra_1'),
]
self.assertEqual(expected, actual)
if __name__ == '__main__':
unittest.main()