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