Skip to content

Commit

Permalink
Working on it
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenvp committed May 13, 2018
1 parent 4350ef7 commit bb38fa4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
13 changes: 12 additions & 1 deletion README.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ The cache will contain the following::
build, build,
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.

8 changes: 4 additions & 4 deletions src/git_sphinx_build/virtualenv.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class VirtualEnv(object):
with '../somefile.txt'. with '../somefile.txt'.
""" """


def __init__(self, prompt=None, log=None): def __init__(self, prompt, log):


self.prompt = prompt if prompt else commandline.Prompt() self.prompt = prompt
self.log = log if log else logging.getLogger(__name__) self.log = log


def create_environment(self, path): def create_environment(self, path):


Expand Down Expand Up @@ -71,7 +71,7 @@ def from_git(git, clone_path, log):
log.debug('Using virtualenv from {}'.format(URL, repo_path)) log.debug('Using virtualenv from {}'.format(URL, repo_path))


env = dict(os.environ) env = dict(os.environ)
env.update({'PYTHONPATH': clone_path}) env.update({'PYTHONPATH': repo_path})


prompt = commandline.Prompt(env=env) prompt = commandline.Prompt(env=env)


Expand Down
49 changes: 26 additions & 23 deletions test/test_virtualenv.py
Original file line number Original file line Diff line number Diff line change
@@ -1,42 +1,45 @@
import mock import mock
import os import os
import sys


import git_sphinx_build import git_sphinx_build
import git_sphinx_build.virtualenv as venv 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 prompt = mock.Mock()
# # will not download one log = mock.Mock()
# download_path = os.path.join(testdirectory.path(), 'download') 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 env = virtualenv.create_environment(path=path)
# #runner_environment = venv.environment(download_path=download_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') # Depending on our platform the path should be modified
# # create_dir = testdirectory.mkdir('create') 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()) # We should be first in the PATH environment variable

assert env['PATH'].startswith(expected_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')

0 comments on commit bb38fa4

Please sign in to comment.