Permalink
Browse files

Working on it

  • Loading branch information...
mortenvp committed May 13, 2018
1 parent 4350ef7 commit bb38fa4374a82d540d42f54f66521b3885d9adf3
Showing with 42 additions and 28 deletions.
  1. +12 −1 README.rst
  2. +4 −4 src/git_sphinx_build/virtualenv.py
  3. +26 −23 test/test_virtualenv.py
View
@@ -40,4 +40,15 @@ The cache will contain the following::
build,
build
]
}
}
Factories and Dependency Injection
----------------------------------
Testability is a key feature of any modern software library and one of the key
techniques for writing testable code is dependency injection (DI).
In Python DI is relatively simple to implement due to the dynamic nature of the
language.
@@ -27,10 +27,10 @@ class VirtualEnv(object):
with '../somefile.txt'.
"""
def __init__(self, prompt=None, log=None):
def __init__(self, prompt, log):
self.prompt = prompt if prompt else commandline.Prompt()
self.log = log if log else logging.getLogger(__name__)
self.prompt = prompt
self.log = log
def create_environment(self, path):
@@ -71,7 +71,7 @@ def from_git(git, clone_path, log):
log.debug('Using virtualenv from {}'.format(URL, repo_path))
env = dict(os.environ)
env.update({'PYTHONPATH': clone_path})
env.update({'PYTHONPATH': repo_path})
prompt = commandline.Prompt(env=env)
View
@@ -1,42 +1,45 @@
import mock
import os
import sys
import git_sphinx_build
import git_sphinx_build.virtualenv as venv
# def test_virtualenv_download_path():
def test_virtualenv_from_git(testdirectory):
# assert venv.default_download_path() != ""
git = mock.Mock()
log = mock.Mock()
clone_path = testdirectory.path()
virtualenv = venv.VirtualEnv.from_git(
git=git, clone_path=clone_path, log=log)
# def test_virtualenv_download(testdirectory):
# The following directory should be in the PYTHONPATH of the virtualenv
# prompt
virtualenv_path = os.path.join(clone_path, venv.VERSION)
# venv.download(download_path=testdirectory.path())
assert virtualenv.prompt.env['PYTHONPATH'] == virtualenv_path
# def test_virtualenv_create(testdirectory):
def test_virtualenv(testdirectory):
# # Set a download dir, it should not exist otherwise the test
# # will not download one
# download_path = os.path.join(testdirectory.path(), 'download')
prompt = mock.Mock()
log = mock.Mock()
path = os.path.join(testdirectory.path(), 'venv')
# # venv.download(download_path=download_path)
virtualenv = venv.VirtualEnv(prompt=prompt, log=log)
# # Create an environment where the virtualenv is available
# #runner_environment = venv.environment(download_path=download_path)
env = virtualenv.create_environment(path=path)
# #virtualenv_root = testdirectory.mkdir('virtualenv_root')
prompt.run.assert_called_once_with(
command=['python', '-m', 'virtualenv', path, '--no-site-packages'])
# # clone_dir = testdirectory.mkdir('clone')
# # create_dir = testdirectory.mkdir('create')
# Depending on our platform the path should be modified
if sys.platform == 'win32':
expected_path = os.path.join(path, 'Scripts')
else:
expected_path = os.path.join(path, 'bin')
# # path = VirtualEnv.download(download_path=clone_dir.path())
# # env = dict(os.environ)
# # env.update({'PYTHONPATH': path})
# # venv = VirtualEnv.create(cwd=testdirectory.path(), env=env)
# # venv.pip_install(packages=['sphinx'])
# # venv.run('sphinx-build --help')
# We should be first in the PATH environment variable
assert env['PATH'].startswith(expected_path)

0 comments on commit bb38fa4

Please sign in to comment.