Skip to content

Commit

Permalink
Merge pull request #176 from M0ses/fix_scm_extension
Browse files Browse the repository at this point in the history
[bugfix] Decoupled self.scm from class name in TarSCM/scm/*
  • Loading branch information
M0ses authored Jul 5, 2017
2 parents a15f28d + 610fbdb commit 42fa499
Show file tree
Hide file tree
Showing 27 changed files with 653 additions and 146 deletions.
426 changes: 426 additions & 0 deletions .pylinttestsrc

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ CLEAN_TEST_PYFILES = \
./tests/__init__.py \
./tests/utils.py \
./tests/tarfixtures.py \
./tests/unittestcases.py \
./tests/archiveobscpiotestcases.py \


PYLINT_READY_TEST_MODULES = \
Expand Down Expand Up @@ -49,7 +51,6 @@ PYLINT_NOT_READY_MODULES = \
./tests/gittests.py \
./tests/svntests.py \
./tests/testenv.py \
./tests/unittestcases.py \
./tests/bzrtests.py \
./tests/fixtures.py \
./tests/hgtests.py \
Expand Down Expand Up @@ -193,7 +194,7 @@ pylint: pylint2
pylint3:
@if [ "x$(PYLINT3)" != "x" ]; then \
$(PYLINT3) --rcfile=./.pylintrc $(PYLINT_READY_MODULES); \
PYTHONPATH=tests $(PYLINT3) --rcfile=./.pylintrc $(PYLINT_READY_TEST_MODULES); \
PYTHONPATH=tests $(PYLINT3) --rcfile=./.pylinttestsrc $(PYLINT_READY_TEST_MODULES); \
else \
echo "PYLINT3 not set - Skipping tests"; \
fi
Expand All @@ -202,7 +203,7 @@ pylint3:
pylint2:
@if [ "x$(PYLINT2)" != "x" ]; then \
$(PYLINT2) --rcfile=./.pylintrc $(PYLINT_READY_MODULES); \
PYTHONPATH=tests $(PYLINT2) --rcfile=./.pylintrc $(PYLINT_READY_TEST_MODULES); \
PYTHONPATH=tests $(PYLINT2) --rcfile=./.pylinttestsrc $(PYLINT_READY_TEST_MODULES); \
else \
echo "PYLINT2 not set - Skipping tests"; \
fi
Expand Down
9 changes: 7 additions & 2 deletions TarSCM/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def parse_args(self, options):
parser.add_argument('--history-depth',
help='Obsolete osc service parameter that does '
'nothing')
# This option is only used in test cases, in real life you would call
# obs_scm instead
parser.add_argument('--use-obs-scm', default = False,
help='use obs scm (obscpio) ')
args = parser.parse_args(options)

# basic argument validation
Expand All @@ -127,8 +131,9 @@ def parse_args(self, options):

# booleanize non-standard parameters
args.changesgenerate = bool(args.changesgenerate == 'enable')
args.package_meta = bool(args.package_meta == 'yes')
args.sslverify = bool(args.sslverify != 'disable')
args.package_meta = bool(args.package_meta == 'yes')
args.sslverify = bool(args.sslverify != 'disable')
args.use_obs_scm = bool(args.use_obs_scm)

# force verbose mode in test-mode
args.verbose = bool(os.getenv('DEBUG_TAR_SCM'))
Expand Down
3 changes: 2 additions & 1 deletion TarSCM/scm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class Scm():
def __init__(self, args, task):
# default settings
self.scm = self.__class__.__name__
# arch_dir - Directory which is used for the archive
# e.g. myproject-2.0
self.arch_dir = None
Expand Down Expand Up @@ -165,7 +164,9 @@ def _calc_dir_to_clone_to(self, prefix):
url_path = urllib.parse.urlparse(self.url)[2].rstrip('/')

# remove trailing scm extension
logging.debug("Stripping '%s' extension from '%s'", self.scm, url_path)
url_path = re.sub(r'\.%s$' % self.scm, '', url_path)
logging.debug(" - New url_path: '%s'", url_path)

# special handling for cloning bare repositories (../repo/.git/)
url_path = url_path.rstrip('/')
Expand Down
2 changes: 2 additions & 0 deletions TarSCM/scm/bzr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


class Bzr(Scm):
scm = 'bzr'

def fetch_upstream_scm(self):
"""SCM specific version of fetch_uptream for bzr."""
command = ['bzr', 'checkout', self.url, self.clone_dir]
Expand Down
2 changes: 2 additions & 0 deletions TarSCM/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


class Git(Scm):
scm = 'git'

def switch_revision(self):
"""Switch sources to revision. The git revision may refer to any of the
following:
Expand Down
2 changes: 2 additions & 0 deletions TarSCM/scm/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


class Hg(Scm):
scm = 'hg'

def switch_revision(self):
"""Switch sources to revision."""
if self.revision is None:
Expand Down
2 changes: 2 additions & 0 deletions TarSCM/scm/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


class Svn(Scm):
scm = 'svn'

def fetch_upstream_scm(self):
"""SCM specific version of fetch_uptream for svn."""
command = ['svn', 'checkout', '--non-interactive', self.url,
Expand Down
2 changes: 2 additions & 0 deletions TarSCM/scm/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class Tar(Scm):
scm = 'tar'

def fetch_upstream(self):
"""SCM specific version of fetch_uptream for tar."""
if self.args.obsinfo is None:
Expand Down
130 changes: 130 additions & 0 deletions tests/archiveobscpiotestcases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python2
from __future__ import print_function

import sys
import os
import re
import inspect

import TarSCM

from TarSCM.scm.git import Git
from TarSCM.archive import ObsCpio

if sys.version_info < (2, 7):
# pylint: disable=import-error
import unittest2 as unittest
else:
import unittest


class ArchiveOBSCpioTestCases(unittest.TestCase):
def setUp(self):
self.cli = TarSCM.Cli()
self.tasks = TarSCM.Tasks(self.cli)
self.tests_dir = os.path.abspath(os.path.dirname(__file__))
self.tmp_dir = os.path.join(self.tests_dir, 'tmp')
self.fixtures_dir = os.path.join(self.tests_dir, 'fixtures',
self.__class__.__name__)

self.cli.parse_args(['--outdir', '.'])
os.environ['CACHEDIRECTORY'] = ''

@unittest.skip("Broken test, relies on a fixture set which is a .git file"
" which is excluded while package building")
def test_obscpio_create_archive(self):
tc_name = inspect.stack()[0][3]
cl_name = self.__class__.__name__
scm_object = Git(self.cli, self.tasks)
scm_object.clone_dir = os.path.join(self.fixtures_dir, tc_name, 'repo')
scm_object.arch_dir = os.path.join(self.fixtures_dir, tc_name, 'repo')
outdir = os.path.join(self.tmp_dir, cl_name, tc_name,
'out')
self.cli.outdir = outdir
arch = ObsCpio()
os.makedirs(outdir)
arch.create_archive(
scm_object,
cli = self.cli,
basename = 'test',
dstname = 'test',
version = '0.1.1'
)

def test_obscpio_extract_of(self):
'''
Test obscpio to extract one file from archive
'''
tc_name = inspect.stack()[0][3]
cl_name = self.__class__.__name__

repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
files = ["test.spec"]
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
arch = ObsCpio()
os.makedirs(outdir)
arch.extract_from_archive(repodir, files, outdir)
for fname in files:
self.assertTrue(os.path.exists(
os.path.join(outdir, fname)))

def test_obscpio_extract_mf(self):
'''
Test obscpio to extract multiple files from archive
'''
tc_name = inspect.stack()[0][3]
cl_name = self.__class__.__name__

repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
files = ["test.spec", 'Readme.md']
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
arch = ObsCpio()
os.makedirs(outdir)
arch.extract_from_archive(repodir, files, outdir)
for fname in files:
self.assertTrue(os.path.exists(
os.path.join(outdir, fname)))

def test_obscpio_extract_nef(self):
'''
Test obscpio to extract non existant file from archive
'''
tc_name = inspect.stack()[0][3]
cl_name = self.__class__.__name__

repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
files = ['nonexistantfile']
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
arch = ObsCpio()
os.makedirs(outdir)
self.assertRaisesRegexp(
SystemExit,
re.compile('No such file or directory'),
arch.extract_from_archive,
repodir,
files,
outdir
)

@unittest.skip("Broken test, actually raises "
"SystemExit: No such file or directory")
def test_obscpio_extract_d(self):
'''
Test obscpio to extract directory from archive
'''
tc_name = inspect.stack()[0][3]
cl_name = self.__class__.__name__

repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
files = ['dir1']
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
arch = TarSCM.archive.ObsCpio()
os.makedirs(outdir)
self.assertRaisesRegexp(
IOError,
re.compile('Is a directory:'),
arch.extract_from_archive,
repodir,
files,
outdir
)

This file was deleted.

11 changes: 11 additions & 0 deletions tests/gittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ def test_match_tag(self):
self.tar_scm_std("--versionformat", "@PARENT_TAG@")
self.assertTarOnly(self.basename(version="latest"))

def test_obs_scm_cli(self):
fix = self.fixtures
fix.create_commits(2)
fix.safe_run('tag latest')
repo_path = fix.repo_path
os.chdir(repo_path)
self.tar_scm_std("--match-tag", 'tag*',
"--versionformat", "@PARENT_TAG@",
"--use-obs-scm", '1')
# self.assertTarOnly(self.basename(version="tag4"))

def test_gitlab_github_files(self):
fix = self.fixtures
fix.create_commits(2)
Expand Down
2 changes: 2 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tests.tasks import TasksTestCases
from tests.scm import SCMBaseTestCases
from tests.tartests import TarTestCases
from tests.archiveobscpiotestcases import ArchiveOBSCpioTestCases

if sys.version_info < (2, 7):
import unittest2 as unittest
Expand All @@ -40,6 +41,7 @@ def prepare_testclasses():
# export TAR_SCM_TC=UnitTestCases,TasksTestCases,SCMBaseTestCases,GitTests,SvnTests,HgTests,TarTestCases # noqa # pylint: disable=line-too-long
UnitTestCases,
TasksTestCases,
ArchiveOBSCpioTestCases,
SCMBaseTestCases,
GitTests,
SvnTests,
Expand Down
Loading

0 comments on commit 42fa499

Please sign in to comment.