Skip to content

Commit

Permalink
Merge pull request #490 from Thrameos/fix_rtd2
Browse files Browse the repository at this point in the history
Fix docs for RTD with mock
  • Loading branch information
marscher authored Jun 24, 2019
2 parents 2b46678 + 122607f commit 217b4e0
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,33 @@
#
# The short X.Y version.
import mock
mock_modules = ('_jpype',)
for m in mock_modules:
sys.modules[m] = mock.MagicMock()

class TypeMock(type):
def __new__(cls, name, bases=None, methods={}):
if not bases:
bases = tuple()
methods['__init__'] = TypeMock._init
methods['__getattr__'] = TypeMock.__getattr__
return type.__new__(cls, name, bases, methods)

def __init__(self, name, bases=None, methods={}):
pass

def _init(self, *args):
pass

def __getattr__(self, key):
print("get",key)
return mock.Mock()

mockModule = mock.MagicMock()
mockModule.isStarted = mock.Mock(return_value=False)
mockModule.PyJPClass = TypeMock("PyJPClass")
sys.modules['_jpype']=mockModule

# For some reason jpype.imports does not work if called in sphinx. Importing
# it here solved the problem.
import jpype
# TODO: reconsider this
#import jpype.imports

#import java.lang
#import java.util
#import java.io
import jpype.imports
version = jpype.__version__
# The full version, including alpha/beta/rc tags.
release = jpype.__version__
Expand Down

0 comments on commit 217b4e0

Please sign in to comment.