increase timeout, properly handle timeouts, and fix symbol lookup in exception handling

This commit is contained in:
Axel Kohlmeyer
2020-10-27 15:04:05 -04:00
parent 5872b05e2f
commit 5dc09ae3c0

View File

@ -22,68 +22,97 @@ class LammpsShell(unittest.TestCase):
def InputRunner(self,text): def InputRunner(self,text):
"""Test tab expansions""" """Test tab expansions"""
try: try:
[outs,errs] = self.proc.communicate(input=text, timeout=1) [outs,errs] = self.proc.communicate(input=text, timeout=10)
except TimeoutExpired: self.timeout = 0
proc.kill() except subprocess.TimeoutExpired:
[outs,errs] = proc.communicate() self.proc.kill()
[outs,errs] = self.proc.communicate()
self.timeout = 1
return outs.decode('UTF-8') return outs.decode('UTF-8')
def testExpandClearHistory(self): def testExpandClearHistory(self):
"""Test expansion of a shell specific command""" """Test expansion of a shell specific command"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'clear_his\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'clear_his\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"clear_history") if self.timeout:
self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"clear_history")
def testExpandDimension(self): def testExpandDimension(self):
"""Test expansion of a LAMMPS command""" """Test expansion of a LAMMPS command"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'dimens\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'dimens\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"dimension") if self.timeout:
self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"dimension")
def testExpandPairStyle(self): def testExpandPairStyle(self):
"""Test expansion of a pair style""" """Test expansion of a pair style"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'pair_st\t zer\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'pair_st\t zer\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"pair_style") if self.timeout:
self.assertEqual(matches[0][2],"zero") self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"pair_style")
self.assertEqual(matches[0][2],"zero")
def testExpandBondStyle(self): def testExpandBondStyle(self):
"""Test expansion of a bond style""" """Test expansion of a bond style"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'bond_st\t zer\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'bond_st\t zer\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"bond_style") if self.timeout:
self.assertEqual(matches[0][2],"zero") self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"bond_style")
self.assertEqual(matches[0][2],"zero")
def testExpandAngleStyle(self): def testExpandAngleStyle(self):
"""Test expansion of a angle style""" """Test expansion of a angle style"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'angle_st\t zer\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'angle_st\t zer\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"angle_style") if self.timeout:
self.assertEqual(matches[0][2],"zero") self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"angle_style")
self.assertEqual(matches[0][2],"zero")
def testExpandDihedralStyle(self): def testExpandDihedralStyle(self):
"""Test expansion of a dihedral style""" """Test expansion of a dihedral style"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'dihedral_st\t zer\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'dihedral_st\t zer\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"dihedral_style") if self.timeout:
self.assertEqual(matches[0][2],"zero") self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"dihedral_style")
self.assertEqual(matches[0][2],"zero")
def testExpandImproperStyle(self): def testExpandImproperStyle(self):
"""Test expansion of a improper style""" """Test expansion of a improper style"""
matches = re.findall(shell_prompt_re, self.InputRunner(b'improper_st\t zer\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'improper_st\t zer\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"improper_style") if self.timeout:
self.assertEqual(matches[0][2],"zero") self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"improper_style")
self.assertEqual(matches[0][2],"zero")
def testExpandComputeGroup(self): def testExpandComputeGroup(self):
"""Test expansion of a group-ID and a compute command""" """Test expansion of a group-ID and a compute command"""
matches = re.findall(cmd_group_re, self.InputRunner(b'compute test al\tcentro/at\t\n'), re.MULTILINE) matches = re.findall(cmd_group_re, self.InputRunner(b'compute test al\tcentro/at\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"compute") if self.timeout:
self.assertEqual(matches[0][2],"test") self.fail("Timeout")
self.assertEqual(matches[0][3],"all") else:
self.assertEqual(matches[0][4],"centro/atom") self.assertEqual(matches[0][1],"compute")
self.assertEqual(matches[0][2],"test")
self.assertEqual(matches[0][3],"all")
self.assertEqual(matches[0][4],"centro/atom")
def testExpandFixGroup(self): def testExpandFixGroup(self):
"""Test expansion of a group-ID and a fix command""" """Test expansion of a group-ID and a fix command"""
matches = re.findall(cmd_group_re, self.InputRunner(b'fix test al\tcontroll\t\n'), re.MULTILINE) matches = re.findall(cmd_group_re, self.InputRunner(b'fix test al\tcontroll\t\n'), re.MULTILINE)
self.assertEqual(matches[0][1],"fix") if self.timeout:
self.assertEqual(matches[0][2],"test") self.fail("Timeout")
self.assertEqual(matches[0][3],"all") else:
self.assertEqual(matches[0][4],"controller") self.assertEqual(matches[0][1],"fix")
self.assertEqual(matches[0][2],"test")
self.assertEqual(matches[0][3],"all")
self.assertEqual(matches[0][4],"controller")
def testExpandSource(self): def testExpandSource(self):
"""Test expansion of a shell command and a file name""" """Test expansion of a shell command and a file name"""
@ -92,24 +121,30 @@ class LammpsShell(unittest.TestCase):
out.close() out.close()
matches = re.findall(shell_prompt_re, self.InputRunner(b'sour\t.tmp.in.sou\t\n'), re.MULTILINE) matches = re.findall(shell_prompt_re, self.InputRunner(b'sour\t.tmp.in.sou\t\n'), re.MULTILINE)
os.remove('.tmp.in.source') os.remove('.tmp.in.source')
self.assertEqual(matches[0][1],"source") if self.timeout:
self.assertEqual(matches[0][2],".tmp.in.source") self.fail("Timeout")
else:
self.assertEqual(matches[0][1],"source")
self.assertEqual(matches[0][2],".tmp.in.source")
def testHistory(self): def testHistory(self):
"""Test history expansion""" """Test history expansion"""
out = self.InputRunner(b'clear_history\nunits real\ndimension 2\n!!:p\n!-3:p\n!dim:p\n!uni:p\nprint !!:$\nprint !dim:1\n') out = self.InputRunner(b'clear_history\nunits real\ndimension 2\n!!:p\n!-3:p\n!dim:p\n!uni:p\nprint !!:$\nprint !dim:1\n')
idx = 0 idx = 0
lines = out.splitlines() if self.timeout:
for line in lines: self.fail("Timeout")
if line.startswith('LAMMPS Shell>'): break else:
idx += 1 lines = out.splitlines()
for line in lines:
self.assertEqual(lines[idx+4],"dimension 2") if line.startswith('LAMMPS Shell>'): break
self.assertEqual(lines[idx+6],"units real") idx += 1
self.assertEqual(lines[idx+8],"dimension 2")
self.assertEqual(lines[idx+10],"units real") self.assertEqual(lines[idx+4],"dimension 2")
self.assertEqual(lines[idx+12],"real") self.assertEqual(lines[idx+6],"units real")
self.assertEqual(lines[idx+14],"2") self.assertEqual(lines[idx+8],"dimension 2")
self.assertEqual(lines[idx+10],"units real")
self.assertEqual(lines[idx+12],"real")
self.assertEqual(lines[idx+14],"2")
########################### ###########################
if __name__ == "__main__": if __name__ == "__main__":