Skip to content

Commit

Permalink
adding expiremental zc.recipe.egg mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Mar 4, 2015
1 parent ce570bb commit 37cae39
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/uranium
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
VENV_URL = "https://pypi.python.org/packages/source/v/virtualenv/virtualenv-{major}.{minor}.{rev}.tar.gz"
VENV_MAJOR = 12
VENV_MINOR = 0
VENV_REV = 5
VENV_REV = 6

import io
import logging
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
'requests==2.5.1',
'six==1.9.0',
'virtualenv==12.0.6',
# we need these two for
# buildout compatibilty purposes.
'zc.buildout'
]

Expand All @@ -19,7 +21,7 @@
]

setup(name='uranium',
version='0.0.60',
version='0.0.62',
description='a build system for python',
long_description='a build system for python',
author='Yusuke Tsutsumi',
Expand Down
8 changes: 7 additions & 1 deletion uranium/buildout_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
from .compat import DictMixin
from .cache import DEFAULT_CACHE_DIRECTORY
import zc.buildout
import logging

Expand Down Expand Up @@ -74,8 +75,13 @@ def __len__(self):
def _buildout(self):
""" return a buildout """
return {
'allow-hosts': '*',
'directory': self._uranium.root,
'download-cache': '.cache',
'download-cache': DEFAULT_CACHE_DIRECTORY,
# should be site-packages
'develop-eggs-directory': '',
'eggs-directory': '',
'find-links': '',
'install-from-cache': 'false',
'offline': 'false',
'parts-directory': self._uranium.parts_directory
Expand Down
20 changes: 20 additions & 0 deletions uranium/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
from .exceptions import CacheException

DEFAULT_CACHE_DIRECTORY = ".cache"


class Cache(object):
""" TODO: create a way to cache downloaded data for uranium """

def __init__(self, path):
self._path = path

def ensure_directory(self):
if os.path.isfile(self._path):
raise CacheException("{0} needs to be a directory.".format(
self._path
))

if not os.path.exists(self._path):
os.makedirs(self._path)
7 changes: 7 additions & 0 deletions uranium/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UraniumException(Exception):
pass


class CacheException(UraniumException):
""" exception with the cache object """
pass
11 changes: 11 additions & 0 deletions uranium/tests/test_buildout_adapter/test_buildout_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ def test_install_from_cache(self):
# configparser only supports strings.
# uranium should support real values
eq_(self.buildout['buildout']['install-from-cache'], 'false')

def test_find_links(self):
"""
uranium does not currently support find-links. We'll
just have an empty string for now.
"""
eq_(self.buildout['buildout']['find-links'], '')

def test_allow_hosts(self):
""" just allow the default. """
eq_(self.buildout['buildout']['allow-hosts'], '*')
39 changes: 39 additions & 0 deletions uranium/tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import shutil
import tempfile
from nose.tools import ok_, raises
from uranium.cache import Cache
from uranium.exceptions import CacheException


class _TestCache(object):

def setUp(self):
self.temp_dir = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.temp_dir)

def test_ensure_directory(self):
cache_dir = os.path.join(self.temp_dir, '.cache')
cache = Cache(cache_dir)
cache.ensure_directory()
ok_(os.path.isdir(cache_dir))

def test_ensure_directory_already_exists(self):
cache_dir = os.path.join(self.temp_dir, '.cache')
os.makedirs(cache_dir)
cache = Cache(cache_dir)
cache.ensure_directory()
ok_(os.path.isdir(cache_dir))

@raises(CacheException)
def test_ensure_directory_with_file(self):
"""
if a file exists where the cache directory
should be, raise an exception.
"""
cache_dir = os.path.join(self.temp_dir, '.cache')
open(cache_dir, 'w+').close()
cache = Cache(cache_dir)
cache.ensure_directory()
38 changes: 38 additions & 0 deletions uranium/tests/test_full/test_buildout_cache_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
tests for the warmup script
"""
import os
import subprocess
from uranium.tests.utils import FullUraniumBaseTest
from nose.tools import eq_

BASE = os.path.dirname(__file__)
URANIUM_ROOT_PATH = os.path.join(BASE, os.pardir, os.pardir, os.pardir)


class TestDownloadPlugin(FullUraniumBaseTest):

config = {
'phases': {
'after-eggs': ['node']
},
'parts': {
'node': {
'recipe': 'gp.recipe.node',
'npms': """
wd
appium@1.3.5
""".strip(),
'scripts': 'appium',
}
}
}

def test_plugin_is_downloaded(self):
"""
ensure that a plugin is downloaded when it must be utilized.
"""
code = subprocess.check_call(['./bin/python', '-c',
'import gp.recipe.node'],
cwd=self.root)
eq_(code, 0)
6 changes: 4 additions & 2 deletions uranium/uranium.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from .bin import BinDirectory
from .buildout_adapter import BuildoutAdapter
from .cache import Cache, DEFAULT_CACHE_DIRECTORY
from .classloader import ClassLoader
from .config import Config
from .messages import START_URANIUM, END_URANIUM
Expand All @@ -11,13 +12,12 @@
from .state import State
LOGGER = logging.getLogger(__name__)

PARTS_DIRECTORY = "parts"


class UraniumException(Exception):
pass

BIN_DIRECTORY = "bin"
PARTS_DIRECTORY = "parts"


class Uranium(object):
Expand All @@ -28,6 +28,7 @@ def __init__(self, config, root, state_file=None):
if type(config) == dict:
config = Config(config)

self._cache = Cache(os.path.join(root, DEFAULT_CACHE_DIRECTORY))
self._root = root
self._config = config
self._pip = PipManager(index_urls=self._config.indexes,
Expand Down Expand Up @@ -73,6 +74,7 @@ def parts_directory(self):
return os.path.join(self.root, PARTS_DIRECTORY)

def run(self):
self._cache.ensure_directory()
self._state.load()
[LOGGER.info(l) for l in START_URANIUM]

Expand Down
1 change: 0 additions & 1 deletion uranium/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import traceback


def log_exception(logger, level):
"""
log an exception at a specific level
Expand Down
1 change: 1 addition & 0 deletions zc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions zc/recipe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
14 changes: 14 additions & 0 deletions zc/recipe/egg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Scripts(object):
"""
a mock object for scripts, as a compatibliity
measure.
"""

def __init__(self, buildout, name, options):
pass

def install(self):
pass

def update(self):
pass

0 comments on commit 37cae39

Please sign in to comment.