Skip to content

Commit

Permalink
Merge pull request #1 from boegel/repository
Browse files Browse the repository at this point in the history
add additional unit tests, fix bugs in GitRepository and SvnRepository, code cleanup
  • Loading branch information
cclerget committed May 6, 2014
2 parents da17ce8 + b947d2a commit e6fbf91
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 20 deletions.
3 changes: 0 additions & 3 deletions easybuild/tools/repository/filerepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
@author: Ward Poelmans (Ghent University)
@author: Fotis Georgatos (University of Luxembourg)
"""
import getpass
import os
import socket
import tempfile
import time

from easybuild.framework.easyconfig.easyconfig import EasyConfig
Expand Down
6 changes: 2 additions & 4 deletions easybuild/tools/repository/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import time
from vsc import fancylogger

from easybuild.framework.easyconfig.easyconfig import EasyConfig
from easybuild.tools.filetools import rmtree2
from easybuild.tools.repository.filerepo import FileRepository

Expand Down Expand Up @@ -101,9 +100,8 @@ def create_working_copy(self):
# try to get a copy of
try:
client = git.Git(self.wc)
out = client.clone(self.repo)
# out = 'Cloning into easybuild...'
reponame = out.split("\n")[0].split()[-1].strip(".").strip("'")
client.clone(self.repo)
reponame = os.listdir(self.wc)[0]
self.log.debug("rep name is %s" % reponame)
except git.GitCommandError, err:
# it might already have existed
Expand Down
9 changes: 1 addition & 8 deletions easybuild/tools/repository/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
# #
"""
Set of repository tools
We have a plain filesystem, an svn and a git repository
Generic support for dealing with repositories
@author: Stijn De Weirdt (Ghent University)
@author: Dries Verdegem (Ghent University)
Expand All @@ -36,11 +34,6 @@
@author: Ward Poelmans (Ghent University)
@author: Fotis Georgatos (University of Luxembourg)
"""
import getpass
import os
import socket
import tempfile
import time
from vsc import fancylogger
from vsc.utils.missing import get_subclasses

Expand Down
3 changes: 1 addition & 2 deletions easybuild/tools/repository/svnrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import time
from vsc import fancylogger

from easybuild.framework.easyconfig.easyconfig import EasyConfig
from easybuild.tools.filetools import rmtree2
from easybuild.tools.repository.filerepo import FileRepository

Expand Down Expand Up @@ -87,7 +86,7 @@ def setup_repo(self):
"""
self.repo = os.path.join(self.repo, self.subdir)
try:
raise pysvn.ClientError # IGNORE:E0611 pysvn fails to recognize ClientError is available
pysvn.ClientError # IGNORE:E0611 pysvn fails to recognize ClientError is available
except NameError, err:
self.log.exception("pysvn not available (%s). Make sure it is installed " % err +
"properly. Run 'python -c \"import pysvn\"' to test.")
Expand Down
64 changes: 61 additions & 3 deletions test/framework/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@
@author: Toon Willems (Ghent University)
"""

import os
import shutil
import tempfile
from test.framework.utilities import EnhancedTestCase
from unittest import TestLoader, main

from easybuild.tools.repository.filerepo import FileRepository
from easybuild.tools.repository.gitrepo import GitRepository
from easybuild.tools.repository.svnrepo import SvnRepository
from easybuild.tools.repository.repository import init_repository
from easybuild.tools.run import run_cmd


GITHUB_LOGIN = os.environ.get('EASYBUILD_GITHUB_LOGIN', None)
GITHUB_TOKEN = os.environ.get('EASYBUILD_GITHUB_TOKEN', None)


class RepositoryTest(EnhancedTestCase):
""" very basis FileRepository test, we don't want git / svn dependency """
Expand All @@ -46,8 +54,8 @@ def setUp(self):
self.path = tempfile.mkdtemp(prefix='easybuild-repo-')
shutil.rmtree(self.path, True)

def test_filerepository(self):
"""Test creating instance of FileRepository."""
def test_filerepo(self):
"""Test using FileRepository."""
repo = FileRepository(self.path)
repo.init()
self.assertEqual(repo.wc, self.path)
Expand All @@ -58,6 +66,56 @@ def test_filerepository(self):
self.assertEqual(repo.wc, self.path)
self.assertEqual(repo.subdir, subdir)

def test_gitrepo(self):
"""Test using GitRepository."""
# only run this test if git Python module is available
try:
from git import GitCommandError
except ImportError:
print "(skipping GitRepository test)"
return

test_repo_url = 'https://github.com/hpcugent/testrepository'

# URL
repo = GitRepository(test_repo_url)
repo.init()
self.assertEqual(os.path.basename(repo.wc), 'testrepository')
self.assertTrue(os.path.exists(os.path.join(repo.wc, 'README.md')))
shutil.rmtree(repo.wc)

# filepath
tmpdir = tempfile.mkdtemp()
cmd = "cd %s && git clone --bare %s" % (tmpdir, test_repo_url)
_, ec = run_cmd(cmd, simple=False, log_all=False, log_ok=False)

# skip remainder of test if creating bare git repo didn't work
if ec == 0:
repo = GitRepository(os.path.join(tmpdir, 'testrepository.git'))
repo.init()
toy_ec_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0.eb')
repo.add_easyconfig(toy_ec_file, 'test', '1.0', {}, False)

shutil.rmtree(repo.wc)
shutil.rmtree(tmpdir)

def test_svnrepo(self):
"""Test using SvnRepository."""
# only run this test if git Python module is available
try:
from pysvn import ClientError
except ImportError:
print "(skipping SvnRepository test)"
return

# GitHub also supports SVN
test_repo_url = 'https://github.com/hpcugent/testrepository'

repo = SvnRepository(test_repo_url)
repo.init()
self.assertTrue(os.path.exists(os.path.join(repo.wc, 'trunk', 'README.md')))
shutil.rmtree(repo.wc)

def test_init_repository(self):
"""Test use of init_repository function."""
repo = init_repository('FileRepository', self.path)
Expand Down

0 comments on commit e6fbf91

Please sign in to comment.