Skip to content

Commit

Permalink
Set tests to use a NETRC fixture instead of global
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanconn committed Dec 29, 2023
1 parent e4d82c6 commit ca17030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ska_ftp/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest
import ska_ftp

@pytest.fixture()
def NETRC():
return ska_ftp.parse_netrc()
15 changes: 7 additions & 8 deletions ska_ftp/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

logger = pyyaks.logger.get_logger()

NETRC = ska_ftp.parse_netrc()
LUCKY = 'lucky.cfa.harvard.edu'


def roundtrip(FtpClass, logger=None):
def roundtrip(NETRC, FtpClass, logger=None):
user = NETRC[LUCKY]['login']
homedir = ('/home/' if FtpClass is ska_ftp.SFTP else '/') + user
lucky = FtpClass(LUCKY, logger=logger)
Expand Down Expand Up @@ -42,17 +41,17 @@ def roundtrip(FtpClass, logger=None):
assert orig == roundtrip


def test_roundtrip():
def test_roundtrip(NETRC):
# roundtrip(FtpClass=ska_ftp.FTP, logger=logger) # legacy of non-secure ftp
roundtrip(FtpClass=ska_ftp.SFTP, logger=logger)
roundtrip(NETRC, FtpClass=ska_ftp.SFTP, logger=logger)


def test_roundtrip_no_logger():
def test_roundtrip_no_logger(NETRC):
# roundtrip(FtpClass=ska_ftp.FTP)
roundtrip(FtpClass=ska_ftp.SFTP)
roundtrip(NETRC, FtpClass=ska_ftp.SFTP)


def test_sftp_mkdir_rmdir_rename():
def test_sftp_mkdir_rmdir_rename(NETRC):
user = NETRC[LUCKY]['login']
homedir = '/home/{}'.format(user)
lucky = ska_ftp.SFTP(LUCKY, logger=logger)
Expand Down Expand Up @@ -90,7 +89,7 @@ def test_delete_when_ftp_session_already_gone(capfd):
def test_parse_netrc():
cwd = os.path.dirname(__file__)
netrc = ska_ftp.parse_netrc(os.path.join(cwd, 'netrc'))
assert netrc == {'test1': {'account': None,
assert netrc == {'test1': {'account': '',
'login': 'test1_login',
'password': 'test1_password'},
'test2': {'account': 'test2_account',
Expand Down

0 comments on commit ca17030

Please sign in to comment.