-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_hitman.py
92 lines (71 loc) · 2.44 KB
/
test_hitman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import shutil
import tempfile
import unittest
from unittest import mock
import pxml
from click.testing import CliRunner
from hitman import Database, export_opml, requests_get
# class TestDatabase(unittest.TestCase):
# d = {'data': 'value', 'cheese': 'many'}
# def setUp(self):
# self.mydb = Database("test")
# self.mydb.db['data'] = 'value'
# self.mydb.db['cheese'] = 'many'
# # self.mydb.db.update(self.d) # doesn't fucking work on travis
# # option to use `semidbm`
# # self.mydb.db.sync()
# def test_write(self):
# self.assertEqual(dict(self.mydb.db), self.d)
# def test_with(self):
# with Database("test") as db:
# db.update(self.d)
# self.assertEqual(db, self.d)
# def tearDown(self):
# self.mydb.db.clear()
# self.mydb.db.close()
class ClosableDict(dict):
"""a thin shim to make the tests run"""
def __init__(self, *args, **kwargs):
super(ClosableDict, self).__init__(*args, **kwargs)
def close(self):
pass
class TestOPML(unittest.TestCase, pxml.XmlTestMixin):
outOPML =b"""<opml version="1.0">
<body>
<outline text="Democracy Now! Video" xmlUrl="http://www.democracynow.org/podcast-video.xml" type="rss" />
</body>
</opml>
"""
inOPML =""""""
@mock.patch('semidbm.open')
def test_export(self, patched_dbm):
our_d = ClosableDict()
our_d["Democracy Now! Video"] = "http://www.democracynow.org/podcast-video.xml"
patched_dbm.return_value = our_d
runner = CliRunner()
result = runner.invoke(export_opml)
self.assertXmlEqual(result.output.encode("utf-8"), self.outOPML)
def test_import(self):
pass
# class TestCalls(unittest.TestCase):
# def test_main(self):
# func = baker.test()
# self.assertEqual(func, "hitsquad()")
# def test_main_args(self):
# baker.test(['s', 'add'])
class TestDownloaders(unittest.TestCase):
def setUp(self):
self.dest = tempfile.mkdtemp()
@mock.patch("clint.textui.progress.Bar")
def test_requests_get(self, patched_bar):
url = "https://httpbin.org/image/png"
requests_get(url, self.dest)
f = os.path.join(self.dest, 'png')
self.assertTrue(os.path.exists(f))
def test_requests_resume(self):
pass
def tearDown(self):
shutil.rmtree(self.dest)
if __name__ == '__main__':
unittest.main()