Add tests for LAMMPS exceptions in Python

This commit is contained in:
Richard Berger
2020-10-02 16:53:41 -04:00
parent 52c6353f86
commit b57c8f6b77

View File

@ -18,6 +18,7 @@ try:
machine = "" machine = ""
lmp = lammps(name=machine) lmp = lammps(name=machine)
has_mpi = lmp.has_mpi_support has_mpi = lmp.has_mpi_support
has_exceptions = lmp.has_exceptions
lmp.close() lmp.close()
except: except:
pass pass
@ -57,5 +58,32 @@ class PythonOpen(unittest.TestCase):
self.assertEqual(lmp.opened,1) self.assertEqual(lmp.opened,1)
lmp.close() lmp.close()
@unittest.skipIf(not has_exceptions,"Skipping death test since LAMMPS isn't compiled with exception support")
def testUnknownCommand(self):
lmp = lammps(name=self.machine)
with self.assertRaisesRegex(Exception, "ERROR: Unknown command: write_paper"):
lmp.command("write_paper")
lmp.close()
@unittest.skipIf(not has_exceptions,"Skipping death test since LAMMPS isn't compiled with exception support")
def testUnknownCommandInList(self):
lmp = lammps(name=self.machine)
with self.assertRaisesRegex(Exception, "ERROR: Unknown command: write_paper"):
lmp.commands_list(["write_paper"])
lmp.close()
@unittest.skipIf(not has_exceptions,"Skipping death test since LAMMPS isn't compiled with exception support")
def testUnknownCommandInList(self):
lmp = lammps(name=self.machine)
with self.assertRaisesRegex(Exception, "ERROR: Unknown command: write_paper"):
lmp.commands_string("write_paper")
lmp.close()
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()