add c/python unit tests for lammps_error()
This commit is contained in:
@ -198,3 +198,32 @@ TEST(lammps_open_fortran, no_args)
|
||||
if (verbose) std::cout << output;
|
||||
MPI_Comm_free(&mycomm);
|
||||
}
|
||||
|
||||
TEST(lammps_open_no_mpi, lammps_error)
|
||||
{
|
||||
const char *args[] = {"liblammps", "-log", "none", "-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args) / sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
void *alt_ptr;
|
||||
void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_EQ(handle, alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_NE(lmp->screen, nullptr);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
EXPECT_EQ(lmp->suffix_enable, 0);
|
||||
|
||||
EXPECT_STREQ(lmp->exename, "liblammps");
|
||||
EXPECT_EQ(lmp->num_package, 0);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_error(handle, 0, "test_warning");
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_THAT(output, HasSubstr("WARNING: test_warning"));
|
||||
}
|
||||
|
||||
|
||||
@ -45,11 +45,21 @@ class PythonOpen(unittest.TestCase):
|
||||
|
||||
def testWithArgs(self):
|
||||
"""Create LAMMPS instance with a few arguments"""
|
||||
lmp=lammps(name=self.machine,
|
||||
cmdargs=['-nocite','-sf','opt','-log','none'])
|
||||
lmp=lammps(name=self.machine,cmdargs=['-nocite','-sf','opt','-log','none'])
|
||||
self.assertIsNot(lmp.lmp,None)
|
||||
self.assertEqual(lmp.opened,1)
|
||||
|
||||
def testError(self):
|
||||
"""Print warning message through LAMMPS Error class"""
|
||||
lmp=lammps(name=self.machine,cmdargs=['-nocite','-log','none','-screen','tmp.error.output'])
|
||||
lmp.error(0,'test_warning')
|
||||
lmp.close()
|
||||
with open('tmp.error.output','r') as f:
|
||||
output = f.read()
|
||||
self.assertTrue('LAMMPS' in output)
|
||||
self.assertTrue('Total wall time' in output)
|
||||
self.assertTrue('WARNING: test_warning' in output)
|
||||
|
||||
def testContextManager(self):
|
||||
"""Automatically clean up LAMMPS instance"""
|
||||
with lammps(name=self.machine) as lmp:
|
||||
|
||||
Reference in New Issue
Block a user