Skip to content

Commit 42fa499

Browse files
authored
Merge pull request #176 from M0ses/fix_scm_extension
[bugfix] Decoupled self.scm from class name in TarSCM/scm/*
2 parents a15f28d + 610fbdb commit 42fa499

File tree

27 files changed

+653
-146
lines changed

27 files changed

+653
-146
lines changed

.pylinttestsrc

Lines changed: 426 additions & 0 deletions
Large diffs are not rendered by default.

GNUmakefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ CLEAN_TEST_PYFILES = \
1818
./tests/__init__.py \
1919
./tests/utils.py \
2020
./tests/tarfixtures.py \
21+
./tests/unittestcases.py \
22+
./tests/archiveobscpiotestcases.py \
2123

2224

2325
PYLINT_READY_TEST_MODULES = \
@@ -49,7 +51,6 @@ PYLINT_NOT_READY_MODULES = \
4951
./tests/gittests.py \
5052
./tests/svntests.py \
5153
./tests/testenv.py \
52-
./tests/unittestcases.py \
5354
./tests/bzrtests.py \
5455
./tests/fixtures.py \
5556
./tests/hgtests.py \
@@ -193,7 +194,7 @@ pylint: pylint2
193194
pylint3:
194195
@if [ "x$(PYLINT3)" != "x" ]; then \
195196
$(PYLINT3) --rcfile=./.pylintrc $(PYLINT_READY_MODULES); \
196-
PYTHONPATH=tests $(PYLINT3) --rcfile=./.pylintrc $(PYLINT_READY_TEST_MODULES); \
197+
PYTHONPATH=tests $(PYLINT3) --rcfile=./.pylinttestsrc $(PYLINT_READY_TEST_MODULES); \
197198
else \
198199
echo "PYLINT3 not set - Skipping tests"; \
199200
fi
@@ -202,7 +203,7 @@ pylint3:
202203
pylint2:
203204
@if [ "x$(PYLINT2)" != "x" ]; then \
204205
$(PYLINT2) --rcfile=./.pylintrc $(PYLINT_READY_MODULES); \
205-
PYTHONPATH=tests $(PYLINT2) --rcfile=./.pylintrc $(PYLINT_READY_TEST_MODULES); \
206+
PYTHONPATH=tests $(PYLINT2) --rcfile=./.pylinttestsrc $(PYLINT_READY_TEST_MODULES); \
206207
else \
207208
echo "PYLINT2 not set - Skipping tests"; \
208209
fi

TarSCM/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def parse_args(self, options):
107107
parser.add_argument('--history-depth',
108108
help='Obsolete osc service parameter that does '
109109
'nothing')
110+
# This option is only used in test cases, in real life you would call
111+
# obs_scm instead
112+
parser.add_argument('--use-obs-scm', default = False,
113+
help='use obs scm (obscpio) ')
110114
args = parser.parse_args(options)
111115

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

128132
# booleanize non-standard parameters
129133
args.changesgenerate = bool(args.changesgenerate == 'enable')
130-
args.package_meta = bool(args.package_meta == 'yes')
131-
args.sslverify = bool(args.sslverify != 'disable')
134+
args.package_meta = bool(args.package_meta == 'yes')
135+
args.sslverify = bool(args.sslverify != 'disable')
136+
args.use_obs_scm = bool(args.use_obs_scm)
132137

133138
# force verbose mode in test-mode
134139
args.verbose = bool(os.getenv('DEBUG_TAR_SCM'))

TarSCM/scm/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
class Scm():
2222
def __init__(self, args, task):
2323
# default settings
24-
self.scm = self.__class__.__name__
2524
# arch_dir - Directory which is used for the archive
2625
# e.g. myproject-2.0
2726
self.arch_dir = None
@@ -165,7 +164,9 @@ def _calc_dir_to_clone_to(self, prefix):
165164
url_path = urllib.parse.urlparse(self.url)[2].rstrip('/')
166165

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

170171
# special handling for cloning bare repositories (../repo/.git/)
171172
url_path = url_path.rstrip('/')

TarSCM/scm/bzr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class Bzr(Scm):
9+
scm = 'bzr'
10+
911
def fetch_upstream_scm(self):
1012
"""SCM specific version of fetch_uptream for bzr."""
1113
command = ['bzr', 'checkout', self.url, self.clone_dir]

TarSCM/scm/git.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class Git(Scm):
9+
scm = 'git'
10+
911
def switch_revision(self):
1012
"""Switch sources to revision. The git revision may refer to any of the
1113
following:

TarSCM/scm/hg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66

77
class Hg(Scm):
8+
scm = 'hg'
9+
810
def switch_revision(self):
911
"""Switch sources to revision."""
1012
if self.revision is None:

TarSCM/scm/svn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
class Svn(Scm):
13+
scm = 'svn'
14+
1315
def fetch_upstream_scm(self):
1416
"""SCM specific version of fetch_uptream for svn."""
1517
command = ['svn', 'checkout', '--non-interactive', self.url,

TarSCM/scm/tar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
class Tar(Scm):
7+
scm = 'tar'
8+
79
def fetch_upstream(self):
810
"""SCM specific version of fetch_uptream for tar."""
911
if self.args.obsinfo is None:

tests/archiveobscpiotestcases.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env python2
2+
from __future__ import print_function
3+
4+
import sys
5+
import os
6+
import re
7+
import inspect
8+
9+
import TarSCM
10+
11+
from TarSCM.scm.git import Git
12+
from TarSCM.archive import ObsCpio
13+
14+
if sys.version_info < (2, 7):
15+
# pylint: disable=import-error
16+
import unittest2 as unittest
17+
else:
18+
import unittest
19+
20+
21+
class ArchiveOBSCpioTestCases(unittest.TestCase):
22+
def setUp(self):
23+
self.cli = TarSCM.Cli()
24+
self.tasks = TarSCM.Tasks(self.cli)
25+
self.tests_dir = os.path.abspath(os.path.dirname(__file__))
26+
self.tmp_dir = os.path.join(self.tests_dir, 'tmp')
27+
self.fixtures_dir = os.path.join(self.tests_dir, 'fixtures',
28+
self.__class__.__name__)
29+
30+
self.cli.parse_args(['--outdir', '.'])
31+
os.environ['CACHEDIRECTORY'] = ''
32+
33+
@unittest.skip("Broken test, relies on a fixture set which is a .git file"
34+
" which is excluded while package building")
35+
def test_obscpio_create_archive(self):
36+
tc_name = inspect.stack()[0][3]
37+
cl_name = self.__class__.__name__
38+
scm_object = Git(self.cli, self.tasks)
39+
scm_object.clone_dir = os.path.join(self.fixtures_dir, tc_name, 'repo')
40+
scm_object.arch_dir = os.path.join(self.fixtures_dir, tc_name, 'repo')
41+
outdir = os.path.join(self.tmp_dir, cl_name, tc_name,
42+
'out')
43+
self.cli.outdir = outdir
44+
arch = ObsCpio()
45+
os.makedirs(outdir)
46+
arch.create_archive(
47+
scm_object,
48+
cli = self.cli,
49+
basename = 'test',
50+
dstname = 'test',
51+
version = '0.1.1'
52+
)
53+
54+
def test_obscpio_extract_of(self):
55+
'''
56+
Test obscpio to extract one file from archive
57+
'''
58+
tc_name = inspect.stack()[0][3]
59+
cl_name = self.__class__.__name__
60+
61+
repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
62+
files = ["test.spec"]
63+
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
64+
arch = ObsCpio()
65+
os.makedirs(outdir)
66+
arch.extract_from_archive(repodir, files, outdir)
67+
for fname in files:
68+
self.assertTrue(os.path.exists(
69+
os.path.join(outdir, fname)))
70+
71+
def test_obscpio_extract_mf(self):
72+
'''
73+
Test obscpio to extract multiple files from archive
74+
'''
75+
tc_name = inspect.stack()[0][3]
76+
cl_name = self.__class__.__name__
77+
78+
repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
79+
files = ["test.spec", 'Readme.md']
80+
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
81+
arch = ObsCpio()
82+
os.makedirs(outdir)
83+
arch.extract_from_archive(repodir, files, outdir)
84+
for fname in files:
85+
self.assertTrue(os.path.exists(
86+
os.path.join(outdir, fname)))
87+
88+
def test_obscpio_extract_nef(self):
89+
'''
90+
Test obscpio to extract non existant file from archive
91+
'''
92+
tc_name = inspect.stack()[0][3]
93+
cl_name = self.__class__.__name__
94+
95+
repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
96+
files = ['nonexistantfile']
97+
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
98+
arch = ObsCpio()
99+
os.makedirs(outdir)
100+
self.assertRaisesRegexp(
101+
SystemExit,
102+
re.compile('No such file or directory'),
103+
arch.extract_from_archive,
104+
repodir,
105+
files,
106+
outdir
107+
)
108+
109+
@unittest.skip("Broken test, actually raises "
110+
"SystemExit: No such file or directory")
111+
def test_obscpio_extract_d(self):
112+
'''
113+
Test obscpio to extract directory from archive
114+
'''
115+
tc_name = inspect.stack()[0][3]
116+
cl_name = self.__class__.__name__
117+
118+
repodir = os.path.join(self.fixtures_dir, tc_name, 'repo')
119+
files = ['dir1']
120+
outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out')
121+
arch = TarSCM.archive.ObsCpio()
122+
os.makedirs(outdir)
123+
self.assertRaisesRegexp(
124+
IOError,
125+
re.compile('Is a directory:'),
126+
arch.extract_from_archive,
127+
repodir,
128+
files,
129+
outdir
130+
)

tests/fixtures/UnitTestCases/test_TarSCM_changes_get_changesauthor_from_oscrc/.oscrc

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_config_no_faked_header/test.ini

tests/gittests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ def test_match_tag(self):
248248
self.tar_scm_std("--versionformat", "@PARENT_TAG@")
249249
self.assertTarOnly(self.basename(version="latest"))
250250

251+
def test_obs_scm_cli(self):
252+
fix = self.fixtures
253+
fix.create_commits(2)
254+
fix.safe_run('tag latest')
255+
repo_path = fix.repo_path
256+
os.chdir(repo_path)
257+
self.tar_scm_std("--match-tag", 'tag*',
258+
"--versionformat", "@PARENT_TAG@",
259+
"--use-obs-scm", '1')
260+
# self.assertTarOnly(self.basename(version="tag4"))
261+
251262
def test_gitlab_github_files(self):
252263
fix = self.fixtures
253264
fix.create_commits(2)

tests/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from tests.tasks import TasksTestCases
2121
from tests.scm import SCMBaseTestCases
2222
from tests.tartests import TarTestCases
23+
from tests.archiveobscpiotestcases import ArchiveOBSCpioTestCases
2324

2425
if sys.version_info < (2, 7):
2526
import unittest2 as unittest
@@ -40,6 +41,7 @@ def prepare_testclasses():
4041
# export TAR_SCM_TC=UnitTestCases,TasksTestCases,SCMBaseTestCases,GitTests,SvnTests,HgTests,TarTestCases # noqa # pylint: disable=line-too-long
4142
UnitTestCases,
4243
TasksTestCases,
44+
ArchiveOBSCpioTestCases,
4345
SCMBaseTestCases,
4446
GitTests,
4547
SvnTests,

0 commit comments

Comments
 (0)