diff options
| author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-15 13:48:15 +0100 | 
|---|---|---|
| committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-15 13:48:15 +0100 | 
| commit | aa2778c5a4602137ee86db6c5fa9810b5c566b5d (patch) | |
| tree | 316d79aeae56c9c5888640a6363bde4c122bc28c /unittest | |
| parent | 5b45be4e83c7e0d62fb949dba32bb9f832c1df5b (diff) | |
| download | libnitrokey-aa2778c5a4602137ee86db6c5fa9810b5c566b5d.tar.gz libnitrokey-aa2778c5a4602137ee86db6c5fa9810b5c566b5d.tar.bz2 | |
Add proxy object for logging libnitrokey calls
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest')
| -rw-r--r-- | unittest/conftest.py | 29 | 
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") + | 
