Move fake_paths mock to more generic place in rtd_tests.mock.paths

front-end-standardization
Gregor Müllegger 2015-07-13 10:28:39 +02:00
parent d0d23dee8a
commit 7ba2f7ff2e
3 changed files with 22 additions and 16 deletions

View File

@ -0,0 +1,18 @@
import os
import mock
def fake_paths(*paths):
"""
Returns a context manager that patches ``os.path.exists`` to return
``True`` for the given ``paths``.
"""
original_exists = os.path.exists
def patched_exists(path):
if path in paths:
return True
return original_exists(path)
return mock.patch.object(os.path, 'exists', patched_exists)

View File

@ -6,6 +6,7 @@ import mock
from projects.tasks import build_docs
from rtd_tests.factories.projects_factories import ProjectFactory
from rtd_tests.mocks.paths import fake_paths
from doc_builder.loader import get_builder_class
@ -29,22 +30,6 @@ def build_subprocess_side_effect(*args, **kwargs):
return subprocess.Popen(*args, **kwargs)
def fake_paths(*paths):
"""
Returns a context manager that patches ``os.path.exists`` to return
``True`` for the given ``paths``.
"""
original_exists = os.path.exists
def patched_exists(path):
if path in paths:
return True
return original_exists(path)
return mock.patch.object(os.path, 'exists', patched_exists)
class BuildTests(TestCase):
@mock.patch('slumber.Resource')

View File

@ -1,6 +1,9 @@
import os
from bamboo_boy.utils import with_canopy
import json
import mock
from django.test import TestCase
from builds.constants import LATEST
from projects.models import Project
from rtd_tests.factories.projects_factories import OneProjectWithTranslationsOneWithout,\
ProjectFactory