Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 250 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
import os
import shutil
import subprocess
import tarfile
import unittest
import zipfile
from shutil import which
from tempfile import TemporaryDirectory
from urllib.parse import urljoin
from urllib.request import pathname2url

import yaml


def to_file_url(path):
return urljoin('file:', pathname2url(path))


class StagedReposFile(unittest.TestCase):
_git = which('git')
_git_env = {
**os.environ,
'GIT_AUTHOR_NAME': 'vcs2l',
'GIT_AUTHOR_DATE': '2005-01-01T00:00:00-06:00',
'GIT_AUTHOR_EMAIL': 'vcs2l@example.com',
'GIT_COMMITTER_NAME': 'vcs2l',
'GIT_COMMITTER_DATE': '2005-01-01T00:00:00-06:00',
'GIT_COMMITTER_EMAIL': 'vcs2l@example.com',
'GIT_CONFIG_GLOBAL': os.path.join(os.path.dirname(__file__), '.gitconfig'),
'LANG': 'en_US.UTF-8',
}
_commit_date = '2005-01-01T00:00:00'

temp_dir = None
repos_file_path = None

@classmethod
def setUpClass(cls):
if not cls._git:
raise unittest.SkipTest('`git` was not found')

cls.temp_dir = TemporaryDirectory(suffix='.vcstmp')

# Create the staged git repository
gitrepo_path = os.path.join(cls.temp_dir.name, 'gitrepo')
os.mkdir(gitrepo_path)
shutil.copy(
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'LICENSE'),
gitrepo_path,
)
for command in (
('init', '--quiet', '.'),
('commit', '--quiet', '--allow-empty', '-m', '0.1.26'),
('tag', '0.1.26'),
('checkout', '--quiet', '-b', 'license'),
('add', 'LICENSE'),
('commit', '--quiet', '-m', 'Add LICENSE'),
('checkout', '--quiet', 'main'),
('merge', '--no-ff', '--quiet', 'license', '-m', "Merge branch 'license'"),
('branch', '--quiet', '-D', 'license'),
('commit', '--quiet', '--allow-empty', '-m', 'update changelog'),
('commit', '--quiet', '--allow-empty', '-m', '0.1.27'),
('tag', '0.1.27', '-m', '0.1.27'),
('commit', '--quiet', '--allow-empty', '-m', "codin' codin' codin'"),
):
subprocess.check_call(
[
cls._git,
*command,
],
cwd=gitrepo_path,
env=cls._git_env,
)

# Create the archive stage
archive_path = os.path.join(cls.temp_dir.name, 'archive_dir')
os.mkdir(archive_path)
with open(os.path.join(archive_path, 'file_name.txt'), 'w') as f:
f.write('Lorem Ipsum\n')

# Create a tar file
tarball_path = os.path.join(cls.temp_dir.name, 'archive.tar.gz')
with tarfile.TarFile.open(tarball_path, 'w:gz') as f:
f.add(archive_path, 'archive_dir')

# Create a zip file
zip_path = os.path.join(cls.temp_dir.name, 'archive.zip')
with zipfile.ZipFile(zip_path, mode='w') as f:
f.write(
os.path.join(archive_path, 'file_name.txt'),
os.path.join('archive_dir', 'file_name.txt'),
)

# Populate the staged.repos file
repos = {
'immutable/hash': {
'type': 'git',
'url': to_file_url(gitrepo_path),
'version': '5b3504594f7354121cf024dc734bf79e270cffd3',
},
'immutable/hash_tar': {
'type': 'tar',
'url': to_file_url(tarball_path),
'version': 'archive_dir',
},
'immutable/hash_zip': {
'type': 'zip',
'url': to_file_url(zip_path),
'version': 'archive_dir',
},
'immutable/tag': {
'type': 'git',
'url': to_file_url(gitrepo_path),
'version': 'tags/0.1.27',
},
'vcs2l': {
'type': 'git',
'url': to_file_url(gitrepo_path),
'version': 'heads/main',
},
'without_version': {
'type': 'git',
'url': to_file_url(gitrepo_path),
},
}

cls.repos_file_path = os.path.join(cls.temp_dir.name, 'staged.repos')
with open(cls.repos_file_path, 'w') as f:
yaml.safe_dump({'repositories': repos}, f)

@classmethod
def tearDownClass(cls):
cls.repos_file_path = None
cls.temp_dir and cls.temp_dir.cleanup()
cls.temp_dir = None


class StagedReposFile2(unittest.TestCase):
_svn = which('svn')
_svnadmin = which('svnadmin')
_hg = which('hg')
_hg_env = {
**os.environ,
'HGUSER': 'vcs2l',
'EMAIL': 'vcs2l@example.com',
}
_commit_date = '2005-01-01T00:00:00-06:00'

temp_dir = None
repos_file_path = None

@classmethod
def setUpClass(cls):
if not cls._svn:
raise unittest.SkipTest('`svn` was not found')
if not cls._svnadmin:
raise unittest.SkipTest('`svnadmin` was not found')
if not cls._hg:
raise unittest.SkipTest('`hg` was not found')
try:
# check if the svn executable is usable (on macOS)
# and not only exists to state that the program is not installed
subprocess.check_call([cls._svn, '--version'], stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError:
raise unittest.SkipTest('`svn` was not found')

cls.temp_dir = TemporaryDirectory(suffix='.vcstmp')

# Create the staged subversion repository
svnrepo_path = os.path.join(cls.temp_dir.name, 'svnrepo')
os.mkdir(svnrepo_path)
subprocess.check_call(
[
'svnadmin',
'create',
'.',
],
cwd=svnrepo_path,
)

svnclone_path = os.path.join(cls.temp_dir.name, 'svnclone')
os.mkdir(svnclone_path)
shutil.copy(
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'LICENSE'),
svnclone_path,
)
for command in (
('checkout', to_file_url(svnrepo_path), '.', '--quiet'),
('add', 'LICENSE', '--quiet'),
('commit', 'LICENSE', '-m', 'Initial commit', '--quiet'),
):
subprocess.check_call(
[
cls._svn,
*command,
],
cwd=svnclone_path,
)

# Create the staged mercurial repository
hgrepo_path = os.path.join(cls.temp_dir.name, 'hgrepo')
os.mkdir(hgrepo_path)
for command in (
('init', '.'),
('branch', '--quiet', 'stable'),
('commit', '-m', 'Initial commit', '-d', cls._commit_date),
('tag', '-d', cls._commit_date, '5.8'),
):
subprocess.check_call(
[
cls._hg,
*command,
],
cwd=hgrepo_path,
env=cls._hg_env,
)

# Populate the staged.repos file
repos = {
'hg/branch': {
'type': 'hg',
'url': to_file_url(hgrepo_path),
'version': 'stable',
},
'hg/hash': {
'type': 'hg',
'url': to_file_url(hgrepo_path),
'version': '9bd654917508',
},
'hg/tag': {
'type': 'hg',
'url': to_file_url(hgrepo_path),
'version': '5.8',
},
'svn/rev': {
'type': 'svn',
'url': to_file_url(svnrepo_path),
'version': '1',
},
}

cls.repos_file_path = os.path.join(cls.temp_dir.name, 'staged.repos')
with open(cls.repos_file_path, 'w') as f:
yaml.safe_dump({'repositories': repos}, f)

@classmethod
def tearDownClass(cls):
cls.repos_file_path = None
cls.temp_dir and cls.temp_dir.cleanup()
cls.temp_dir = None
2 changes: 1 addition & 1 deletion test/branch.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
....
=== ./immutable/hash (git) ===
(HEAD detached at 377d5b3)
(HEAD detached at 5b35045)
=== ./immutable/tag (git) ===
(HEAD detached at 0.1.27)
=== ./vcs2l (git) ===
Expand Down
8 changes: 4 additions & 4 deletions test/export_exact.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repositories:
hash:
type: git
url: https://github.com/ros-infrastructure/vcs2l.git
version: 377d5b3d03c212f015cc832fdb368f4534d0d583
url: file:///vcstmp/gitrepo
version: 5b3504594f7354121cf024dc734bf79e270cffd3
tag:
type: git
url: https://github.com/ros-infrastructure/vcs2l.git
version: bf9ca56de693a02b93ed423bcef589259d75eb0f
url: file:///vcstmp/gitrepo
version: 8087b72504968800cdf54759b11e0b753ec90736
6 changes: 3 additions & 3 deletions test/export_exact_with_tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repositories:
hash:
type: git
url: https://github.com/ros-infrastructure/vcs2l.git
version: 377d5b3d03c212f015cc832fdb368f4534d0d583
url: file:///vcstmp/gitrepo
version: 5b3504594f7354121cf024dc734bf79e270cffd3
tag:
type: git
url: https://github.com/ros-infrastructure/vcs2l.git
url: file:///vcstmp/gitrepo
version: 0.1.27
10 changes: 5 additions & 5 deletions test/import.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
......
=== ./immutable/hash (git) ===
Cloning into '.'...
Note: switching to '377d5b3d03c212f015cc832fdb368f4534d0d583'.
Note: switching to '5b3504594f7354121cf024dc734bf79e270cffd3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
Expand All @@ -18,11 +18,11 @@ Or undo this operation with:

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 377d5b3... update changelog
HEAD is now at 5b35045... update changelog
=== ./immutable/hash_tar (tar) ===
Downloaded tarball from 'https://github.com/ros-infrastructure/vcs2l/archive/377d5b3d03c212f015cc832fdb368f4534d0d583.tar.gz' and unpacked it
Downloaded tarball from 'file:///vcstmp/archive.tar.gz' and unpacked it
=== ./immutable/hash_zip (zip) ===
Downloaded zipfile from 'https://github.com/ros-infrastructure/vcs2l/archive/377d5b3d03c212f015cc832fdb368f4534d0d583.zip' and unpacked it
Downloaded zipfile from 'file:///vcstmp/archive.zip' and unpacked it
=== ./immutable/tag (git) ===
Cloning into '.'...
Note: switching to 'tags/0.1.27'.
Expand All @@ -42,7 +42,7 @@ Or undo this operation with:

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at bf9ca56... 0.1.27
HEAD is now at 8087b72... 0.1.27
=== ./vcs2l (git) ===
Cloning into '.'...
=== ./without_version (git) ===
Expand Down
16 changes: 8 additions & 8 deletions test/import_shallow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
=== ./immutable/hash (git) ===
Initialized empty Git repository in ./immutable/hash/.git/

From https://github.com/ros-infrastructure/vcs2l
* branch 377d5b3d03c212f015cc832fdb368f4534d0d583 -> FETCH_HEAD
Note: switching to '377d5b3d03c212f015cc832fdb368f4534d0d583'.
From file:///vcstmp/gitrepo
* branch 5b3504594f7354121cf024dc734bf79e270cffd3 -> FETCH_HEAD
Note: switching to '5b3504594f7354121cf024dc734bf79e270cffd3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
Expand All @@ -21,15 +21,15 @@ Or undo this operation with:

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 377d5b3... update changelog
HEAD is now at 5b35045... update changelog
=== ./immutable/hash_tar (tar) ===
Downloaded tarball from 'https://github.com/ros-infrastructure/vcs2l/archive/377d5b3d03c212f015cc832fdb368f4534d0d583.tar.gz' and unpacked it
Downloaded tarball from 'file:///vcstmp/archive.tar.gz' and unpacked it
=== ./immutable/hash_zip (zip) ===
Downloaded zipfile from 'https://github.com/ros-infrastructure/vcs2l/archive/377d5b3d03c212f015cc832fdb368f4534d0d583.zip' and unpacked it
Downloaded zipfile from 'file:///vcstmp/archive.zip' and unpacked it
=== ./immutable/tag (git) ===
Initialized empty Git repository in ./immutable/tag/.git/

From https://github.com/ros-infrastructure/vcs2l
From file:///vcstmp/gitrepo
* [new tag] 0.1.27 -> 0.1.27
Note: switching to 'tags/0.1.27'.

Expand All @@ -48,7 +48,7 @@ Or undo this operation with:

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at bf9ca56... 0.1.27
HEAD is now at 8087b72... 0.1.27
=== ./vcs2l (git) ===
Cloning into '.'...
=== ./without_version (git) ===
Expand Down
24 changes: 0 additions & 24 deletions test/list.repos

This file was deleted.

Loading