aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2019-01-15 13:48:15 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2019-01-15 13:48:15 +0100
commitaa2778c5a4602137ee86db6c5fa9810b5c566b5d (patch)
tree316d79aeae56c9c5888640a6363bde4c122bc28c
parent5b45be4e83c7e0d62fb949dba32bb9f832c1df5b (diff)
downloadlibnitrokey-aa2778c5a4602137ee86db6c5fa9810b5c566b5d.tar.gz
libnitrokey-aa2778c5a4602137ee86db6c5fa9810b5c566b5d.tar.bz2
Add proxy object for logging libnitrokey calls
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--unittest/conftest.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/unittest/conftest.py b/unittest/conftest.py
index 669dc23..bf18fc8 100644
--- a/unittest/conftest.py
+++ b/unittest/conftest.py
@@ -33,6 +33,32 @@ def skip_if_device_version_lower_than(allowed_devices):
pytest.skip('This device model is not applicable to run this test')
+class AtrrCallProx(object):
+ def __init__(self, C, name):
+ self.C = C
+ self.name = name
+
+ def __call__(self, *args, **kwargs):
+ print('Calling {}{}'.format(self.name, args))
+ res = self.C(*args, **kwargs)
+ res_s = res
+ try:
+ res_s = '{} => '.format(res) + '{}'.format(gs(res))
+ except Exception as e:
+ pass
+ print('Result of {}: {}'.format(self.name, res_s))
+ return res
+
+
+class AttrProxy(object):
+ def __init__(self, C, name):
+ self.C = C
+ self.name = name
+
+ def __getattr__(self, attr):
+ return AtrrCallProx(getattr(self.C, attr), attr)
+
+
@pytest.fixture(scope="module")
def C(request=None):
fp = '../NK_C_API.h'
@@ -104,4 +130,5 @@ def C(request=None):
# C.NK_set_debug(True)
C.NK_set_debug_level(int(os.environ.get('LIBNK_DEBUG', 3)))
- return C
+ return AttrProxy(C, "libnitrokey C")
+