Skip to content

Commit b4f5fd3

Browse files
committed
updating tests, instance was running out of room
1 parent 414356e commit b4f5fd3

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

singularity/cli.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import tempfile
4545
import shutil
4646
import json
47+
import sys
4748
import os
4849
import re
4950

@@ -259,20 +260,22 @@ def inspect(self,image_path,json=True,labels=True,
259260
return output
260261

261262

262-
def pull(self,image_path,pull_folder=None,name_by=None,image_name=None):
263+
def pull(self,image_path,pull_folder=None,
264+
name_by_hash=False,
265+
name_by_commit=False,
266+
image_name=None):
263267
'''pull will pull a singularity hub image
264268
:param image_path: full path to image
265269
:param name_by: can be one of commit or hash, default is by image name
266270
'''
267271
if image_name is not None:
268-
name_by = None
269-
if name_by is not None:
270-
name_by = name_by.lower()
272+
name_by_hash=False
273+
name_by_commit=False
271274

272275
if pull_folder is not None:
273276
os.environ['SINGULARITY_PULLFOLDER'] = pull_folder
274277

275-
if not image_path.startswith('shub://') or not image_path.startswith('docker://'):
278+
if not image_path.startswith('shub://') and not image_path.startswith('docker://'):
276279
bot.logger.error("pull is only valid for docker and shub, %s is invalid.",image_name)
277280
sys.exit(1)
278281

@@ -282,20 +285,22 @@ def pull(self,image_path,pull_folder=None,name_by=None,image_name=None):
282285
cmd = ['singularity','pull']
283286

284287
if image_path.startswith('shub://'):
285-
if name_by in ['commit','hash']:
286-
bot.logger.debug("user specified naming pulled image by %s",name_by)
287-
name_by = "--%s " %name_by
288-
cmd.append(name_by)
289-
elif image_name is not None:
290-
name_by = "--name %s" %(image_name)
291-
288+
if image_name is not None:
289+
bot.logger.debug("user specified naming pulled image %s",image_name)
290+
cmd = cmd +["--name",image_name]
291+
elif name_by_commit is True:
292+
bot.logger.debug("user specified naming by commit.")
293+
cmd.append("--commit")
294+
elif name_by_hash is True:
295+
bot.logger.debug("user specified naming by hash.")
296+
cmd.append("--hash")
297+
292298
elif image_path.startswith('docker://'):
293299
if image_name is not None:
294300
bot.logger.debug("user specified name of image as %s",image_name)
295-
name_by = "--name %s" %(image_name)
301+
cmd = cmd + ["--name",image_name]
296302

297303
cmd.append(image_path)
298-
299304
output = self.run_command(cmd)
300305
output = self.println(output,quiet=True)
301306
return output.split("Container is at:")[-1].strip('\n').strip()

singularity/tests/test_client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,22 @@ def test_import(self):
7373
self.cli.importcmd(container,'docker://ubuntu')
7474
result = test_container(container)
7575
self.assertEqual(result['return_code'],0)
76+
os.remove(container)
7677

7778
def test_run(self):
7879
print("Testing client.run command")
7980
container = create_container(do_import=True)
8081
result = self.cli.run(container)
8182
self.assertEqual(result,'')
83+
os.remove(container)
84+
8285

8386
def test_exec(self):
8487
print('Testing client.execute command')
8588
container = create_container(do_import=True)
8689
result = self.cli.execute(container,'ls /')
8790
print(result)
91+
os.remove(container)
8892
#if isinstance(result,bytes):
8993
# result = result.decode('utf-8')
9094
#self.assertTrue(len(result)>0)
@@ -96,20 +100,24 @@ def test_inspect(self):
96100
result = self.cli.inspect(container,quiet=True)
97101
labels = json.loads(result)
98102
self.assertTrue('data' in labels)
103+
os.remove(container)
99104

100105

101106
def test_run(self):
102107
print("Testing client.run command")
103108
container = create_container(do_import=True)
104109
result = self.cli.run(container)
105110
self.assertEqual(result,'')
111+
os.remove(container)
106112

107113

108114
def test_exec(self):
109115
print('Testing client.execute command')
110116
container = create_container(do_import=True)
111117
result = self.cli.execute(container,'ls /')
112118
print(result)
119+
os.remove(container)
120+
113121
#if isinstance(result,bytes):
114122
# result = result.decode('utf-8')
115123
#self.assertTrue(len(result)>0)
@@ -121,15 +129,27 @@ def test_pull(self):
121129

122130
print("Case 1: Testing naming pull by image name")
123131
image = self.cli.pull("shub://vsoch/singularity-images")
132+
self.assertTrue(os.path.exists(image))
124133
print(image)
134+
os.remove(image)
125135

126136
print("Case 2: Testing naming pull by image commit")
127-
image = self.cli.pull("shub://vsoch/singularity-images",name_by="commit")
137+
image = self.cli.pull("shub://vsoch/singularity-images",name_by_commit=True)
138+
self.assertTrue(os.path.exists(image))
128139
print(image)
140+
os.remove(image)
129141

130142
print("Case 3: Testing naming pull by image hash")
131-
image = self.cli.pull("shub://vsoch/singularity-images",name_by="hash")
143+
image = self.cli.pull("shub://vsoch/singularity-images",name_by_hash=True)
144+
self.assertTrue(os.path.exists(image))
145+
print(image)
146+
os.remove(image)
147+
148+
print("Case 3: Testing docker pull")
149+
image = self.cli.pull("docker://ubuntu:14.04")
132150
print(image)
151+
self.assertTrue(os.path.exists(image))
152+
os.remove(image)
133153

134154

135155
def test_get_image(self):

0 commit comments

Comments
 (0)