Added the beginnings of #77.
parent
5ad757394b
commit
692342a2b0
|
@ -0,0 +1,39 @@
|
|||
import imp
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
class ErrorlessImport(object):
|
||||
def find_module(self, name, path):
|
||||
try:
|
||||
return imp.find_module(name, path)
|
||||
except ImportError:
|
||||
#raise
|
||||
return FreeLoader()
|
||||
|
||||
|
||||
class Mock(object):
|
||||
def __repr__(self):
|
||||
return "<Silly Human, I'm not real>"
|
||||
|
||||
def __eq__(self, b):
|
||||
return True
|
||||
|
||||
def __getattr__(self, *args, **kwargs):
|
||||
return Mock()
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return Mock()
|
||||
|
||||
|
||||
class FreeLoader:
|
||||
def load_module(self, fullname):
|
||||
return Mock()
|
||||
|
||||
|
||||
def patch_meta_path():
|
||||
FreeLoader._class = ErrorlessImport()
|
||||
sys.meta_path += [FreeLoader._class]
|
||||
|
||||
def unpatch_meta_path():
|
||||
sys.meta_path.remove(FreeLoader._class)
|
||||
#sys.meta_path = []
|
|
@ -3,3 +3,4 @@ from view_tests import *
|
|||
from test_doc_building import *
|
||||
from test_backend import *
|
||||
from test_celery import *
|
||||
from test_hacks import *
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
from django.test import TestCase
|
||||
from readthedocs.core import hacks
|
||||
|
||||
class TestHacks(TestCase):
|
||||
fixtures = ['eric.json', 'test_data.json']
|
||||
|
||||
def setUp(self):
|
||||
import ipdb; ipdb.set_trace()
|
||||
hacks.patch_meta_path()
|
||||
|
||||
def tearDown(self):
|
||||
hacks.unpatch_meta_path()
|
||||
|
||||
def test_hack_failed_import(self):
|
||||
import boogy
|
||||
self.assertTrue(str(boogy), "<Silly Human, I'm not real>")
|
||||
|
||||
def test_hack_correct_import(self):
|
||||
import itertools
|
||||
self.assertFalse(str(itertools), "<Silly Human, I'm not real>")
|
Loading…
Reference in New Issue