From 180e8168862f0d50cd5a6cbed8e5f1a6c8553708 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Mar 2021 19:55:08 -0400 Subject: [PATCH] Simplify PythonPackage tests --- unittest/python/test_python_package.cpp | 44 +++++++++++++------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index cba77ee2b0..5974592997 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -40,6 +40,8 @@ protected: LAMMPS *lmp; Info *info; + void command(const std::string &line) { lmp->input->one(line.c_str()); } + void SetUp() override { const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"}; @@ -51,16 +53,16 @@ protected: ASSERT_NE(lmp, nullptr); info = new Info(lmp); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("region box block -4 4 -4 4 -4 4"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 single 0.0 0.0 0.0 units box"); - lmp->input->one("create_atoms 1 single 1.9 -1.9 1.9999 units box"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("pair_coeff * *"); - lmp->input->one("mass * 1.0"); - lmp->input->one("variable input_dir index " + INPUT_FOLDER); + command("units real"); + command("dimension 3"); + command("region box block -4 4 -4 4 -4 4"); + command("create_box 1 box"); + command("create_atoms 1 single 0.0 0.0 0.0 units box"); + command("create_atoms 1 single 1.9 -1.9 1.9999 units box"); + command("pair_style zero 2.0"); + command("pair_coeff * *"); + command("mass * 1.0"); + command("variable input_dir index " + INPUT_FOLDER); if (!verbose) ::testing::internal::GetCapturedStdout(); } @@ -78,31 +80,31 @@ TEST_F(PythonPackageTest, python_invoke) if (!info->has_style("command", "python")) GTEST_SKIP(); // execute python function from file if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("python printnum file ${input_dir}/func.py"); + command("python printnum file ${input_dir}/func.py"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("python printnum invoke"); + command("python printnum invoke"); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); // execute another python function from same file if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("python printtxt exists"); + command("python printtxt exists"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("python printtxt invoke"); + command("python printtxt invoke"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("python.*sometext.*")); // execute python function that uses the LAMMPS python module if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable idx equal 2.25"); - lmp->input->one("python getidxvar input 1 SELF format p exists"); + command("variable idx equal 2.25"); + command("python getidxvar input 1 SELF format p exists"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("python getidxvar invoke"); + command("python getidxvar invoke"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); @@ -112,12 +114,12 @@ TEST_F(PythonPackageTest, python_variable) { if (!info->has_style("command", "python")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable sq python square"); - lmp->input->one("variable val index 1.5"); - lmp->input->one("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py"); + command("variable sq python square"); + command("variable val index 1.5"); + command("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("print \"${sq}\""); + command("print \"${sq}\""); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("print.*2.25.*"));