Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Aug 7, 2018
1 parent 4aae7d1 commit 64cd38a
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,13 @@ def setUp(self):
self.project = Project.objects.get(slug='pip')
self.version = self.project.versions.first()

build_env = namedtuple('project', 'version')
build_env.project = self.project
build_env.version = self.version
self.build_env = namedtuple('project', 'version')
self.build_env.project = self.project
self.build_env.version = self.version

BaseSphinx.type = 'base'
BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()

python_env = Virtualenv(
version=self.version,
build_env=build_env,
config=None,
)
self.base_sphinx = BaseSphinx(
build_env=build_env,
python_env=python_env,
)

@patch(
'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR',
'/tmp/sphinx-template-dir',
Expand All @@ -57,7 +47,8 @@ def setUp(self):
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
@patch('readthedocs.builds.models.Version.get_conf_py_path')
@patch('readthedocs.builds.models.Project.conf_file')
def test_create_conf_py(self, conf_file, get_conf_py_path, _, get_config_params, create_index, docs_dir):
@patch('readthedocs.projects.models.Project.checkout_path')
def test_create_conf_py(self, checkout_path, conf_file, get_conf_py_path, _, get_config_params, create_index, docs_dir):
"""
Test for a project without ``conf.py`` file.
Expand All @@ -69,20 +60,35 @@ def test_create_conf_py(self, conf_file, get_conf_py_path, _, get_config_params,
any kind of exception raised by ``append_conf`` (we were originally
having a ``TypeError`` because of an encoding problem in Python3)
"""
checkout_path.return_value = tempfile.mkdtemp()
docs_dir.return_value = tempfile.mkdtemp()
create_index.return_value = 'README.rst'
get_config_params.return_value = {}
get_conf_py_path.side_effect = ProjectConfigurationError
conf_file.return_value = tempfile.mktemp()
python_env = Virtualenv(
version=self.version,
build_env=self.build_env,
config=None,
)
base_sphinx = BaseSphinx(
build_env=self.build_env,
python_env=python_env,
)
try:
self.base_sphinx.append_conf()
base_sphinx.append_conf()
except Exception:
pytest.fail('Exception was generated when append_conf called.')

# Check the content generated by our method is the same than what we
# expects from a pre-generated file
generated_conf_py = os.path.join(self.base_sphinx.docs_dir(), 'conf.py')
expected_conf_py = os.path.join(os.path.dirname(__file__), '..', 'files', 'conf.py')
generated_conf_py = os.path.join(base_sphinx.docs_dir(), 'conf.py')
expected_conf_py = os.path.join(
os.path.dirname(__file__),
'..',
'files',
'conf.py'
)
with open(generated_conf_py) as gf, open(expected_conf_py) as ef:
self.assertEqual(gf.read(), ef.read())

Expand All @@ -95,21 +101,13 @@ def setUp(self):
self.project = Project.objects.get(slug='pip')
self.version = self.project.versions.first()

build_env = namedtuple('project', 'version')
build_env.project = self.project
build_env.version = self.version

python_env = Virtualenv(
version=self.version,
build_env=build_env,
config=None,
)
self.searchbuilder = SearchBuilder(
build_env=build_env,
python_env=python_env,
)
self.build_env = namedtuple('project', 'version')
self.build_env.project = self.project
self.build_env.version = self.version

def test_ignore_patterns(self):
@patch('readthedocs.projects.models.Project.checkout_path')
def test_ignore_patterns(self, checkout_path):
checkout_path.return_value = tempfile.mkdtemp()
src = tempfile.mkdtemp()
src_static = os.path.join(src, '_static/')
src_other = os.path.join(src, 'other/')
Expand All @@ -120,14 +118,24 @@ def test_ignore_patterns(self):
dest_static = os.path.join(dest, '_static/')
dest_other = os.path.join(dest, 'other/')

self.searchbuilder.old_artifact_path = src
self.searchbuilder.target = dest
python_env = Virtualenv(
version=self.version,
build_env=self.build_env,
config=None,
)
searchbuilder = SearchBuilder(
build_env=self.build_env,
python_env=python_env,
)

searchbuilder.old_artifact_path = src
searchbuilder.target = dest

# There is a _static/ dir in src/ but not in dest/
self.assertTrue(os.path.exists(src_static))
self.assertFalse(os.path.exists(dest_static))

self.searchbuilder.move()
searchbuilder.move()

# There is a dest/other/ but not a dest/_static
self.assertFalse(os.path.exists(dest_static))
Expand Down

0 comments on commit 64cd38a

Please sign in to comment.