This repository was archived by the owner on Jun 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
67 lines (48 loc) · 1.76 KB
/
test.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
import os
import coindata
class TestBasicOperations(unittest.TestCase):
possible_input_formats = ('btc', 'BTC', 'bitcoin', 'BITCOIN')
@staticmethod
def is_same(data1, data2):
"""Compare 2 coindata outputs."""
# length case
if not len(data1) == len(data2):
return False
# comparing keys
for i in range(len(data1)):
for key in data1[i]:
if not data1[i][key] == data2[i][key]:
return False
# passed
return True
def test_retrieve_with_all_input_formats(self):
"""Try retrieve with all possible input formats."""
for inp in self.possible_input_formats:
output = coindata.request.retrieve(inp)
if not output:
raise ValueError("No output with following input: " + inp)
def test_write_read(self):
"""Compare request.retrieve and request.read outputs."""
# retrieve
data = coindata.request.retrieve('btc')
# write and read
dir_test = os.path.dirname(os.path.realpath(__file__))
file_path = coindata.request.write('btc', dir_test)
data_comp = coindata.request.read(file_path)
# clean up
os.remove(file_path)
# test
if not self.is_same(data, data_comp):
raise ValueError("Written and read data aren't same!")
def test_cache_and_get(self):
"""Test basic caching and get."""
cache = coindata.cache('BITCOIN')
get = coindata.get('btc')
if __name__ == "__main__":
try:
unittest.main()
except ConnectionError:
print("No internet connection, aborting!")