-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple tests so far: - test resolution for - auto - copy - hard - soft - test parsington with argument `1+3`
- Loading branch information
1 parent
c62b42d
commit eea0c71
Showing
3 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import glob | ||
import io | ||
import jgo | ||
import os | ||
import pathlib | ||
import unittest | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
|
||
import logging | ||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
IGNORE_JGORC = '--ignore-jgorc' | ||
LINK_TYPE = '--link-type' | ||
PARSINGTON_VERSION = '1.0.4' | ||
PARSINGTON_ENDPOINT = 'org.scijava:parsington:{}'.format(PARSINGTON_VERSION) | ||
|
||
def run_parsington(cache_dir, link_type, parsington_args): | ||
argv = (IGNORE_JGORC, LINK_TYPE, link_type, PARSINGTON_ENDPOINT) + parsington_args | ||
os.environ[jgo.jgo.jgo_cache_dir_environment_variable()] = cache_dir | ||
return jgo.jgo.jgo_main(argv=argv, stdout=subprocess.PIPE) | ||
|
||
def resolve_parsington(cache_dir, link_type, m2_repo): | ||
return jgo.resolve_dependencies( | ||
PARSINGTON_ENDPOINT, | ||
m2_repo=m2_repo, | ||
cache_dir=cache_dir, | ||
link_type=link_type) | ||
|
||
class ParsingtonTest(unittest.TestCase): | ||
|
||
def test_resolve_hard(self): | ||
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir') | ||
m2_repo = os.path.join(str(pathlib.Path.home()), '.m2', 'repository') | ||
try: | ||
_, workspace = resolve_parsington(cache_dir=tmp_dir, link_type='hard', m2_repo=m2_repo) | ||
jars = glob.glob(os.path.join(workspace, '*jar')) | ||
self.assertEqual(len(jars), 1, 'Expected exactly one jar in workspace') | ||
self.assertEqual(jars[0], os.path.join(workspace, 'parsington-%s.jar' % PARSINGTON_VERSION), 'Expected parsington jar') | ||
self.assertFalse(os.path.islink(jars[0]), 'Expected hard link but found symbolic link.') | ||
self.assertTrue(os.path.isfile(jars[0])) | ||
self.assertGreaterEqual(os.stat(jars[0]).st_nlink, 2, 'Expected ref count of at least 2 for hard link.') | ||
except OSError as e: | ||
if e.errno == 18: | ||
_logger.warning('Unable to cross-device hard link, skipping hard link test: %s', str(e)) | ||
else: | ||
raise e | ||
finally: | ||
shutil.rmtree(tmp_dir) | ||
|
||
def test_resolve_soft(self): | ||
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir') | ||
m2_repo = os.path.join(str(pathlib.Path.home()), '.m2', 'repository') | ||
try: | ||
_, workspace = resolve_parsington(cache_dir=tmp_dir, link_type='soft', m2_repo=m2_repo) | ||
jars = glob.glob(os.path.join(workspace, '*jar')) | ||
self.assertEqual(len(jars), 1, 'Expected exactly one jar in workspace') | ||
self.assertEqual(jars[0], os.path.join(workspace, 'parsington-%s.jar' % PARSINGTON_VERSION), 'Expected parsington jar') | ||
self.assertTrue(os.path.islink(jars[0]), 'Expected soft link.') | ||
finally: | ||
shutil.rmtree(tmp_dir) | ||
|
||
def test_resolve_copy(self): | ||
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir') | ||
m2_repo = os.path.join(str(pathlib.Path.home()), '.m2', 'repository') | ||
try: | ||
_, workspace = resolve_parsington(cache_dir=tmp_dir, link_type='copy', m2_repo=m2_repo) | ||
jars = glob.glob(os.path.join(workspace, '*jar')) | ||
self.assertEqual(len(jars), 1, 'Expected exactly one jar in workspace') | ||
self.assertEqual(jars[0], os.path.join(workspace, 'parsington-%s.jar' % PARSINGTON_VERSION), 'Expected parsington jar') | ||
self.assertFalse(os.path.islink(jars[0]), 'Expected copied file but found symbolic link.') | ||
self.assertTrue(os.path.isfile(jars[0])) | ||
self.assertEqual(os.stat(jars[0]).st_nlink, 1, 'Expected ref count of exactly 1 for copied file.') | ||
finally: | ||
shutil.rmtree(tmp_dir) | ||
|
||
def test_resolve_auto(self): | ||
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir') | ||
m2_repo = os.path.join(str(pathlib.Path.home()), '.m2', 'repository') | ||
try: | ||
_, workspace = resolve_parsington(cache_dir=tmp_dir, link_type='auto', m2_repo=m2_repo) | ||
jars = glob.glob(os.path.join(workspace, '*jar')) | ||
self.assertEqual(len(jars), 1, 'Expected exactly one jar in workspace') | ||
self.assertEqual(jars[0], os.path.join(workspace, 'parsington-%s.jar' % PARSINGTON_VERSION), 'Expected parsington jar') | ||
finally: | ||
shutil.rmtree(tmp_dir) | ||
|
||
def test_run_jgo(self): | ||
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir') | ||
|
||
try: | ||
completed_process = run_parsington(cache_dir=tmp_dir, link_type='auto', parsington_args=('1+3',)) | ||
self.assertEqual(completed_process.returncode, 0, 'Expected return code zero.') | ||
self.assertEqual(completed_process.stdout.decode('ascii').strip(), str(1+3)) | ||
finally: | ||
shutil.rmtree(tmp_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
||
|
||
|