Skip to content

Commit

Permalink
Merge pull request #31 from tony/config-fixes
Browse files Browse the repository at this point in the history
Test tweaks and refactoring
  • Loading branch information
tony committed May 26, 2016
2 parents 3224ab9 + a1cc7ce commit de1fbbe
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 212 deletions.
2 changes: 1 addition & 1 deletion bootstrap_env.py
Expand Up @@ -103,7 +103,7 @@ def which(exe=None, throw=True):
message = (
'pip is required for this bootstrap to run.\n'
'Find instructions on how to install at: %s' %
'http://pip.readthedocs.org/en/latest/installing.html'
'http://pip.readthedocs.io/en/latest/installing.html'
)
fail(message)

Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Expand Up @@ -280,4 +280,4 @@
#texinfo_no_detailmenu = false

# example configuration for intersphinx: refer to the python standard library.
intersphinx_mapping = {'http://docs.python.org/': None, 'pip': ('http://sphinx.readthedocs.org/en/latest/', None)}
intersphinx_mapping = {'http://docs.python.org/': None, 'pip': ('http://sphinx.readthedocs.io/en/latest/', None)}
8 changes: 4 additions & 4 deletions tests/fixtures/repoduplicate1.yaml
@@ -1,5 +1,5 @@
{TMP_DIR}/test/:
/path/to/test/:
subRepoDiffVCS:
url: svn+file://${svn_repo_path}
subRepoSameVCS: git+file://${git_repo_path}
vcsOn1: svn+file://${svn_repo_path}
url: svn+file:///path/to/svnrepo
subRepoSameVCS: git+file://path/to/gitrepo
vcsOn1: svn+file:///path/to/another/svn
8 changes: 4 additions & 4 deletions tests/fixtures/repoduplicate2.yaml
@@ -1,5 +1,5 @@
{TMP_DIR}/test/:
/path/to/test/:
subRepoDiffVCS:
url: git+file://${git_repo_path}
subRepoSameVCS: git+file://${git_repo_path}
vcsOn2: svn+file://${svn_repo_path}
url: git+file:///path/to/diffrepo
subRepoSameVCS: git+file:///path/to/gitrepo
vcsOn2: svn+file:///path/to/another/svn
89 changes: 38 additions & 51 deletions tests/test_config.py
Expand Up @@ -9,7 +9,7 @@
import pytest

from vcspull import config, exc
from vcspull.config import expand_config
from vcspull.config import extract_repos, expand_dir

from .fixtures import example as fixtures
from .fixtures._util import loadfixture
Expand Down Expand Up @@ -38,7 +38,7 @@ def sample_json_config(config_dir):


def test_dict_equals_yaml():
"""Verify that example YAML is returning expected dict format."""
# Verify that example YAML is returning expected dict format.
config = kaptan.Kaptan(handler='yaml').import_config(
loadfixture('example1.yaml'))

Expand Down Expand Up @@ -100,19 +100,14 @@ def test_scan_config(tmpdir):


def test_expand_shell_command_after():
"""Expand configuration into full form."""
# Expand shell commands from string to list."""
config = expand_config(fixtures.config_dict)
# Expand shell commands from string to list.
config = extract_repos(fixtures.config_dict)

assert config, fixtures.config_dict_expanded


def test_expandenv_and_homevars():
"""Assure ~ tildes and environment template vars expand."""

expanduser = os.path.expanduser
expandvars = os.path.expandvars

# Assure ~ tildes and environment template vars expand.
config_yaml = loadfixture('expand.yaml')
config_json = loadfixture("expand.json")

Expand All @@ -122,21 +117,21 @@ def test_expandenv_and_homevars():
config2 = kaptan.Kaptan(handler='json') \
.import_config(config_json).export('dict')

config1_expanded = expand_config(config1)
config2_expanded = expand_config(config2)
config1_expanded = extract_repos(config1)
config2_expanded = extract_repos(config2)

paths = [r['parent_dir'] for r in config1_expanded]
assert expanduser(expandvars('${HOME}/github_projects/')) in paths
assert expanduser('~/study/') in paths
assert expanduser('~') in paths
assert expand_dir('${HOME}/github_projects/') in paths
assert expand_dir('~/study/') in paths
assert expand_dir('~') in paths

paths = [r['parent_dir'] for r in config2_expanded]
assert expandvars('${HOME}/github_projects/') in paths
assert expanduser('~/study/') in paths
assert expand_dir('${HOME}/github_projects/') in paths
assert expand_dir('~/study/') in paths


def test_find_config_files(tmpdir):
"""Test find_config_files in home directory."""
# Test find_config_files in home directory.

tmpdir.join('.vcspull.yaml').write('')
with EnvironmentVarGuard() as env:
Expand All @@ -149,7 +144,6 @@ def test_find_config_files(tmpdir):


def test_multiple_configs_raises_exception(tmpdir):

tmpdir.join('.vcspull.json').write('')
tmpdir.join('.vcspull.yaml').write('')
with EnvironmentVarGuard() as env:
Expand Down Expand Up @@ -386,45 +380,38 @@ def test_find_config_include_home_configs(


def test_merge_nested_dict(tmpdir, config_dir):
# remnants of RepoIntegrationTest", todo: remove this style of templating
config_yaml3 = loadfixture('repoduplicate1.yaml').format(
svn_repo_path='lol',
hg_repo_path='lol2',
git_repo_path='lol3',
TMP_DIR=str(tmpdir)
)
config1 = config_dir.join('repoduplicate1.yaml')
config1.write(loadfixture('repoduplicate1.yaml'))

config_yaml4 = loadfixture('repoduplicate2.yaml').format(
svn_repo_path='lol',
hg_repo_path='lol2',
git_repo_path='lol3',
TMP_DIR=str(tmpdir)
)
config2 = config_dir.join('repoduplicate2.yaml')
config2.write(loadfixture('repoduplicate2.yaml'))

config3 = config_dir.join('repoduplicate1.yaml')
config3.write(config_yaml3)
# Duplicate path + name with different repo URL / remotes raises.
configs = config.find_config_files(
path=str(config_dir),
match="repoduplicate[1-2]"
)

conf = kaptan.Kaptan(handler='yaml').import_config(str(config3))
config3_dict = conf.export('dict')
assert str(config1) in configs
assert str(config2) in configs
with pytest.raises(Exception):
config.load_configs(configs)

config4 = config_dir.join('repoduplicate2.yaml')
config4.write(config_yaml4)

conf = kaptan.Kaptan(handler='yaml').import_config(str(config4))
config4_dict = conf.export('dict')
def test_relative_dir(tmpdir):
arbitrary_dir = tmpdir.join('moo')
arbitrary_dir.mkdir()

# validate export of multiple configs + nested dirs
assert 'vcsOn1' in config3_dict[str(tmpdir.join('test/')) + '/']
assert 'vcsOn2' not in config3_dict[str(tmpdir.join('test/')) + '/']
assert 'vcsOn2' in config4_dict[str(tmpdir.join('test/')) + '/']
arbitrary_dir.join('rel.yaml').write("""
./relativedir:
docutils: svn+http://svn.code.sf.net/p/docutils/code/trunk
""")

"""Duplicate path + name with different repo URL / remotes raises."""
configs = config.find_config_files(
path=str(config_dir),
match="repoduplicate[1-2]"
path=str(arbitrary_dir)
)
repos = config.load_configs(configs, str(arbitrary_dir))

assert str(config3) in configs
assert str(config4) in configs
with pytest.raises(Exception):
config.load_configs(configs)
assert str(arbitrary_dir.join('relativedir')) == repos[0]['parent_dir']
assert str(arbitrary_dir.join('relativedir', 'docutils')) == \
repos[0]['repo_dir']
5 changes: 2 additions & 3 deletions tests/test_repo_object.py
Expand Up @@ -7,10 +7,9 @@

import kaptan

from vcspull.config import expand_config
from vcspull.config import extract_repos, filter_repos
from vcspull.repo import (BaseRepo, GitRepo, MercurialRepo, SubversionRepo,
create_repo)
from vcspull.util import filter_repos

from .fixtures import example as fixtures

Expand Down Expand Up @@ -147,7 +146,7 @@ def test_makes_recursive(tmpdir, git_dummy_repo_dir):
conf = kaptan.Kaptan(handler='yaml')
conf.import_config(YAML_CONFIG)
conf = conf.export('dict')
repos = expand_config(conf)
repos = extract_repos(conf)

for r in filter_repos(repos):
repo = create_repo(**r)
Expand Down
6 changes: 3 additions & 3 deletions vcspull/__init__.py
Expand Up @@ -17,9 +17,10 @@
import logging

from .cli import setup_logger
from .config import expand_config, is_config_file, load_configs
from .config import (extract_repos, filter_repos, in_dir, is_config_file,
load_configs)
from .log import DebugLogFormatter, LogFormatter, RepoFilter, RepoLogFormatter
from .util import in_dir, filter_repos, mkdir_p, run, update_dict, which
from .util import mkdir_p, run, update_dict, which

try: # Python 2.7+
from logging import NullHandler
Expand All @@ -29,4 +30,3 @@ def emit(self, record):
pass

logging.getLogger(__name__).addHandler(NullHandler())

3 changes: 1 addition & 2 deletions vcspull/cli.py
Expand Up @@ -14,10 +14,9 @@
import click

from .__about__ import __version__
from .config import find_config_files, load_configs
from .config import find_config_files, load_configs, filter_repos
from .log import DebugLogFormatter
from .repo import create_repo
from .util import filter_repos


MIN_ASYNC = 3 # minimum amount of repos to sync concurrently
Expand Down

0 comments on commit de1fbbe

Please sign in to comment.