Repository: duecredit/duecredit

Issue:
Internal failure: VerificationError (cryptography)
Hi, 

I'm trying to follow the PyMVPA tutorial (http://www.pymvpa.org/tutorial.html), but the first import already fails due to an internal duecredit error:

`from mvpa2.tutorial_suite import *`

gives:

```
2019-01-18 11:00:43,590 [WARNING] DueCredit internal failure while running <function _get_inactive_due at 0x7f651a76b0c8>: VerificationError("importing '/usr/lib/python2.7/dist-packages/cryptography/_Cryptography_cffi_813c10e0x7adb75f8.x86_64-linux-gnu.so': /usr/lib/python2.7/dist-packages/cryptography/_Cryptography_cffi_813c10e0x7adb75f8.x86_64-linux-gnu.so: symbol SSLv2_client_method, version OPENSSL_1.0.0 not defined in file libssl.so.1.0.0 with link time reference",). Please report to developers at https://github.com/duecredit/duecredit/issues (utils.py:199)
2019-01-18 11:00:44,258 [WARNING] DueCredit internal failure while running <function _get_active_due at 0x7f651a76b1b8>: VerificationError("importing '/usr/lib/python2.7/dist-packages/cryptography/_Cryptography_cffi_813c10e0x7adb75f8.x86_64-linux-gnu.so': /usr/lib/python2.7/dist-packages/cryptography/_Cryptography_cffi_813c10e0x7adb75f8.x86_64-linux-gnu.so: symbol SSLv2_client_method, version OPENSSL_1.0.0 not defined in file libssl.so.1.0.0 with link time reference",). Please report to developers at https://github.com/duecredit/duecredit/issues (utils.py:199)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/mvpa2/__init__.py", line 179, in <module>
    due.cite(
AttributeError: 'DueSwitch' object has no attribute 'cite'
```

It seems to me like this is a problem with duecredit and not PyMVPA, so I'm opening the issue here. I'm running a VirtualBox instance with NeuroDebian 8.0.0 (64-bit) and Python 2.7.9. Not really sure what's the issue, so any help would be appreciated. Thanks!



Discussion:

Patch:
diff --git a/duecredit/dueswitch.py b/duecredit/dueswitch.py
index 99e9319..63de5ba 100644
--- a/duecredit/dueswitch.py
+++ b/duecredit/dueswitch.py
@@ -22,13 +22,13 @@ def _get_duecredit_enable():
                     "Use 'yes' or 'no', or '0' or '1'")
     return env_enable.lower() in ('1', 'yes', 'true')
 
+
 @never_fail
 def _get_inactive_due():
-    # keeping duplicate but separate so later we could even place it into a separate
-    # submodule to possibly minimize startup time impact even more
-    from .collector import InactiveDueCreditCollector
+    from .stub import InactiveDueCreditCollector
     return InactiveDueCreditCollector()
 
+
 @never_fail
 def _get_active_due():
     from .config import CACHE_DIR, DUECREDIT_FILE
@@ -62,6 +62,11 @@ class DueSwitch(object):
         self.__active = None
         self.__collectors = {False: inactive, True: active}
         self.__activations_done = False
+        if not (inactive and active):
+            raise ValueError(
+                "Both inactive and active collectors should be provided. "
+                "Got active=%r, inactive=%r" % (active, inactive)
+            )
         self.activate(activate)
 
     @property


Test patch:
diff --git a/duecredit/tests/test_api.py b/duecredit/tests/test_api.py
index 63e8926..83259d2 100644
--- a/duecredit/tests/test_api.py
+++ b/duecredit/tests/test_api.py
@@ -163,7 +163,16 @@ def test_noincorrect_import_if_no_lxml_numpy(monkeypatch, kwargs, env, stubbed_e
         monkeypatch.setitem(os.environ, key, fake_env_nolxml_[key])
 
     ret, out, err = run_python_command(**kwargs)
-    assert err == ''
+    direct_duecredit_import = 'import duecredit' in kwargs.get('cmd', '')
+    if direct_duecredit_import and env.get('DUECREDIT_TEST_EARLY_IMPORT_ERROR', ''):
+        # We do fail then upon regular import but stubbed script should be ok
+        # since should use the stub
+        assert 'Both inactive and active collectors should be provided' in err
+        assert ret == 1
+    else:
+        assert err == ''
+        assert ret == 0  # but we must not fail overall regardless
+
     if os.environ.get('DUECREDIT_ENABLE', False) and on_windows:  # TODO this test fails on windows
         pytest.xfail("Fails for some reason on Windows")
     elif os.environ.get('DUECREDIT_ENABLE', False):  # we enabled duecredit
@@ -179,10 +188,12 @@ def test_noincorrect_import_if_no_lxml_numpy(monkeypatch, kwargs, env, stubbed_e
     elif os.environ.get('DUECREDIT_TEST_EARLY_IMPORT_ERROR'):
         assert 'ImportError' in out
         assert 'DUECREDIT_TEST_EARLY_IMPORT_ERROR' in out
-        assert 'done123' in out
+        if direct_duecredit_import:
+            assert 'Please report' in out
+        else:
+            assert 'done123' in out
     else:
         assert 'done123\n' or 'done123\r\n' == out
-    assert ret == 0  # but we must not fail overall regardless
 
 
 if __name__ == '__main__':
diff --git a/duecredit/tests/test_dueswitch.py b/duecredit/tests/test_dueswitch.py
index c1d664d..bcaf135 100644
--- a/duecredit/tests/test_dueswitch.py
+++ b/duecredit/tests/test_dueswitch.py
@@ -11,7 +11,7 @@ import atexit
 import pytest
 
 from ..injections.injector import DueCreditInjector
-from ..dueswitch import due
+from ..dueswitch import DueSwitch, due
 
 
 def test_dueswitch_activate(monkeypatch):
@@ -39,3 +39,10 @@ def test_dueswitch_activate(monkeypatch):
     assert state["activate"] == 1
     assert state["register"] == 1
     assert state["register_func"] == due.dump
+
+
+def test_a_bad_one():
+    # We might get neither of those and should fail
+    # see https://github.com/duecredit/duecredit/issues/142
+    # So let's through ValueError right away
+    pytest.raises(ValueError, DueSwitch, None, None, True)
\ No newline at end of file