Skip to content

Commit 2fc33b8

Browse files
committed
fix unittest; will skip test when cannot build ssh connections
1 parent 5d63955 commit 2fc33b8

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

tests/test_ssh_context.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
import os,sys,json,glob,shutil,uuid,getpass
22
import unittest
3-
from pathlib import Path
3+
import pathlib
44
from paramiko.ssh_exception import NoValidConnectionsError
5+
from paramiko.ssh_exception import SSHException
56

67
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
78
__package__ = 'tests'
89
from .context import SSHContext, SSHSession
10+
from .context import Machine
11+
from .sample_class import SampleClass
912

1013
class TestSSHContext(unittest.TestCase):
14+
@classmethod
15+
def setUpClass(cls):
16+
with open('jsons/machine_ali_ehpc.json', 'r') as f:
17+
mdata = json.load(f)
18+
try:
19+
cls.machine = Machine.load_from_dict(mdata['machine'])
20+
except SSHException:
21+
self.skipTest("SSHException cannot connect")
22+
cls.submission = SampleClass.get_sample_submission()
23+
cls.submission.bind_machine(cls.machine)
24+
cls.submission_hash = cls.submission.submission_hash
25+
file_list = ['bct-1/log.lammps', 'bct-2/log.lammps', 'bct-3/log.lammps', 'bct-4/log.lammps']
26+
for file in file_list:
27+
cls.machine.context.write_file(file, '# mock log')
28+
1129
def setUp(self):
12-
self.tmp_local_root = 'test_context_dir/'
13-
self.tmp_remote_root = 'tmp_ssh_context_dir/'
30+
self.context = self.__class__.machine.context
1431

15-
self.username = getpass.getuser()
16-
# try:
17-
self.ssh_session = SSHSession(
18-
hostname='localhost',
19-
username=self.username
32+
def test_ssh_session(self):
33+
self.assertIsInstance(
34+
self.__class__.machine.context.ssh_session, SSHSession
2035
)
21-
# except NoValidConnectionsError:
22-
# self.skipTest("skip ssh tests due to ssh connection errors")
2336

24-
def test_ssh_session(self):
25-
pass
26-
# with self.
37+
def test_upload(self):
38+
self.context.upload(self.__class__.submission)
39+
check_file_list = ['graph.pb', 'bct-1/conf.lmp', 'bct-4/input.lammps']
40+
for file in check_file_list:
41+
self.assertTrue(self.context.check_file_exists(os.path.join(self.context.remote_root, file)))
42+
43+
def test_download(self):
44+
self.context.download(self.__class__.submission)
45+
2746

2847

0 commit comments

Comments
 (0)