@@ -448,11 +448,16 @@ def test_jsonsink(tmpdir, inputs_attributes):
448
448
449
449
@pytest .mark .skipif (no_paramiko , reason = "paramiko library is not available" )
450
450
def test_SSHDataGrabber (tmpdir ):
451
- """Test SSHDataGrabber by connecting to localhost and finding this test
452
- file.
451
+ """Test SSHDataGrabber by connecting to localhost and collecting some data.
453
452
"""
454
453
old_cwd = tmpdir .chdir ()
455
454
455
+ source_dir = tmpdir .mkdir ('source' )
456
+ source_hdr = source_dir .join ('somedata.hdr' )
457
+ source_dat = source_dir .join ('somedata.img' )
458
+ source_hdr .ensure () # create
459
+ source_dat .ensure () # create
460
+
456
461
# ssh client that connects to localhost, current user, regardless of
457
462
# ~/.ssh/config
458
463
def _mock_get_ssh_client (self ):
@@ -465,24 +470,24 @@ def _mock_get_ssh_client(self):
465
470
MockSSHDataGrabber = copy .copy (nio .SSHDataGrabber )
466
471
MockSSHDataGrabber ._get_ssh_client = _mock_get_ssh_client
467
472
468
- this_dir = os .path .dirname (__file__ )
469
- this_file = os .path .basename (__file__ )
470
- this_test = this_file [:- 3 ] # without .py
471
-
473
+ # grabber to get files from source_dir matching test.hdr
472
474
ssh_grabber = MockSSHDataGrabber (infields = ['test' ],
473
475
outfields = ['test_file' ])
474
- # ssh_grabber.base_dir = str(tmpdir)
475
- ssh_grabber .inputs .base_directory = this_dir
476
+ ssh_grabber .inputs .base_directory = str (source_dir )
476
477
ssh_grabber .inputs .hostname = 'localhost'
477
- ssh_grabber .inputs .field_template = dict (test_file = '%s.py ' )
478
+ ssh_grabber .inputs .field_template = dict (test_file = '%s.hdr ' )
478
479
ssh_grabber .inputs .template = ''
479
480
ssh_grabber .inputs .template_args = dict (test_file = [['test' ]])
480
- ssh_grabber .inputs .test = this_test
481
+ ssh_grabber .inputs .test = 'somedata'
481
482
ssh_grabber .inputs .sort_filelist = True
482
483
483
484
runtime = ssh_grabber .run ()
484
485
485
- # did we successfully get this file?
486
- assert runtime .outputs .test_file == str (tmpdir .join (this_file ))
486
+ # did we successfully get the header?
487
+ assert runtime .outputs .test_file == str (tmpdir .join (source_hdr .basename ))
488
+ # did we successfully get the data?
489
+ assert (tmpdir .join (source_hdr .basename ) # header file
490
+ .new (ext = '.img' ) # data file
491
+ .check (file = True , exists = True )) # exists?
487
492
488
493
old_cwd .chdir ()
0 commit comments