mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
test printing results
This commit is contained in:
parent
383e5a101d
commit
0c2415bb47
@ -5,6 +5,7 @@ import gzip
|
|||||||
import colorama
|
import colorama
|
||||||
import urllib.parse as parse
|
import urllib.parse as parse
|
||||||
import urllib.request as request
|
import urllib.request as request
|
||||||
|
import shutil
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import pirate.data
|
import pirate.data
|
||||||
@ -31,8 +32,9 @@ def print(*args, **kwargs):
|
|||||||
return builtins.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):
|
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'
|
cur_color = 'zebra_0'
|
||||||
|
|
||||||
if local:
|
if local:
|
||||||
|
29
tests/test_print.py
Executable file
29
tests/test_print.py
Executable 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()
|
Loading…
Reference in New Issue
Block a user