@@ -55,8 +55,8 @@ def setUpClass(cls):
5555 def tearDownClass (cls ):
5656 with helpers .make_session () as sess :
5757 try :
58- resc = sess . resources . get ( cls .register_resc )
59- resc .remove ()
58+ if cls .register_resc :
59+ sess . resources . get ( cls . register_resc ) .remove ()
6060 except Exception as e :
6161 print ( "Could not remove resc {!r} due to: {} " .format (cls .register_resc ,e ),
6262 file = sys .stderr )
@@ -338,20 +338,34 @@ def test_multiple_criteria_on_one_column_name(self):
338338 results = [r [DataObject .name ] for r in q ]
339339 self .assertTrue (len (results ) == len (dummy_test ))
340340
341- @unittest .skipIf (six .PY3 , 'Test is for python2 only' )
342- def test_query_for_data_object_with_utf8_name_python2 (self ):
343341
344- if not helpers .irods_session_host_local (self .sess ) and not ( self .register_resc ):
345- self .skipTest ('for non-local server - registering data objects requires a shared path' )
342+ def common_dir_or_vault_info (self ):
343+ register_opts = {}
344+ dir_ = None
345+ if self .register_resc :
346+ dir_ = irods_shared_reg_resc_vault ()
347+ register_opts [ kw .RESC_NAME_KW ] = self .register_resc
348+ if not (dir_ ) and helpers .irods_session_host_local (self .sess ):
349+ dir_ = tempfile .gettempdir ()
350+ if not dir_ :
351+ return ()
352+ else :
353+ return (dir_ , register_opts )
346354
355+
356+ @unittest .skipIf (six .PY3 , 'Test is for python2 only' )
357+ def test_query_for_data_object_with_utf8_name_python2 (self ):
358+ reg_info = self .common_dir_or_vault_info ()
359+ if not reg_info :
360+ self .skipTest ('server is non-localhost and no common path exists for object registration' )
361+ (dir_ ,resc_option ) = reg_info
347362 filename_prefix = '_prefix_ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸ'
348363 self .assertEqual (self .FILENAME_PREFIX .encode ('utf-8' ), filename_prefix )
349- dir_ = irods_shared_reg_resc_vault ()
350364 _ ,test_file = tempfile .mkstemp (dir = dir_ ,prefix = filename_prefix )
351365 obj_path = os .path .join (self .coll .path , os .path .basename (test_file ))
352366 results = None
353367 try :
354- self .sess .data_objects .register (test_file , obj_path , ** { kw . RESC_NAME_KW : self . register_resc } )
368+ self .sess .data_objects .register (test_file , obj_path , ** resc_option )
355369 results = self .sess .query (DataObject , Collection .name ).filter (DataObject .path == test_file ).first ()
356370 result_logical_path = os .path .join (results [Collection .name ], results [DataObject .name ])
357371 result_physical_path = results [DataObject .path ]
@@ -366,10 +380,10 @@ def test_query_for_data_object_with_utf8_name_python2(self):
366380
367381 @unittest .skipIf (six .PY2 , 'Test is for python3 only' )
368382 def test_query_for_data_object_with_utf8_name_python3 (self ):
369-
370- if not helpers . irods_session_host_local ( self . sess ) and not ( self . register_resc ) :
371- self .skipTest ('for non-local server - registering data objects requires a shared path ' )
372-
383+ reg_info = self . common_dir_or_vault_info ()
384+ if not reg_info :
385+ self .skipTest ('server is non-localhost and no common path exists for object registration ' )
386+ ( dir_ , resc_option ) = reg_info
373387 def python34_unicode_mkstemp ( prefix , dir = None , open_mode = 0o777 ):
374388 file_path = os .path .join ((dir or os .environ .get ('TMPDIR' ) or '/tmp' ), prefix + '-' + str (uuid .uuid1 ()))
375389 encoded_file_path = file_path .encode ('utf-8' )
@@ -379,7 +393,6 @@ def python34_unicode_mkstemp( prefix, dir = None, open_mode = 0o777 ):
379393 u'\u01e0 \u01e1 \u01e2 \u01e3 \u01e4 \u01e5 \u01e6 \u01e7 \u01e8 \u01e9 \u01ea \u01eb \u01ec \u01ed \u01ee \u01ef ' \
380394 u'\u01f0 \u01f1 \u01f2 \u01f3 \u01f4 \u01f5 \u01f6 \u01f7 \u01f8 ' # make more visible/changeable in VIM
381395 self .assertEqual (self .FILENAME_PREFIX , filename_prefix )
382- dir_ = irods_shared_reg_resc_vault ()
383396 (fd ,encoded_test_file ) = tempfile .mkstemp (dir = dir_ .encode ('utf-8' ),prefix = filename_prefix .encode ('utf-8' )) \
384397 if sys .version_info >= (3 ,5 ) \
385398 else python34_unicode_mkstemp (dir = dir_ , prefix = filename_prefix )
@@ -388,7 +401,7 @@ def python34_unicode_mkstemp( prefix, dir = None, open_mode = 0o777 ):
388401 obj_path = os .path .join (self .coll .path , os .path .basename (test_file ))
389402 results = None
390403 try :
391- self .sess .data_objects .register (test_file , obj_path , ** { kw . RESC_NAME_KW : self . register_resc } )
404+ self .sess .data_objects .register (test_file , obj_path , ** resc_option )
392405 results = list (self .sess .query (DataObject , Collection .name ).filter (DataObject .path == test_file ))
393406 if results :
394407 results = results [0 ]
0 commit comments