Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dfab55

Browse files
author
Kotsias, Panagiotis-Christos
committed
Added unittests for pro module
1 parent c4b1b51 commit 2dfab55

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/test_pro_modules.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
from datetime import datetime
3+
import os
4+
from unittest import TestCase
5+
6+
from etherscan.etherscan import Etherscan
7+
8+
CONFIG_PATH = "configs/stable.json"
9+
API_PRO_KEY = os.environ["API_PRO_KEY"] # Encrypted env var by Travis
10+
11+
12+
def load(fname):
13+
with open(fname, "r") as f:
14+
return json.load(f)
15+
16+
17+
def dump(data, fname):
18+
with open(fname, "w") as f:
19+
json.dump(data, f, indent=2)
20+
21+
22+
class Case(TestCase):
23+
_MODULE = ""
24+
25+
def test_methods(self):
26+
print(f"\nMODULE: {self._MODULE}")
27+
config = load(CONFIG_PATH)
28+
etherscan = Etherscan.from_config(CONFIG_PATH, API_PRO_KEY)
29+
for fun, v in config.items():
30+
if not fun.startswith("_"): # disabled if _
31+
if v["module"] == self._MODULE:
32+
res = getattr(etherscan, fun)(**v["kwargs"])
33+
print(f"METHOD: {fun}, RTYPE: {type(res)}")
34+
# Create log files (will update existing ones)
35+
fname = f"logs/{fun}.json"
36+
log = {
37+
"method": fun,
38+
"module": v["module"],
39+
"kwargs": v["kwargs"],
40+
"log_timestamp": datetime.now().strftime("%Y-%m-%d-%H:%M:%S"),
41+
"res": res,
42+
}
43+
dump(log, fname)
44+
45+
46+
class TestProModules(Case):
47+
_MODULE = "pro"

0 commit comments

Comments
 (0)