From aa2778c5a4602137ee86db6c5fa9810b5c566b5d Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 15 Jan 2019 13:48:15 +0100 Subject: Add proxy object for logging libnitrokey calls Signed-off-by: Szczepan Zalega --- unittest/conftest.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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") + -- cgit v1.2.3