From acbb54d35f2c064d9c460171e650cd1cfa322c9d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 13 Oct 2020 21:32:48 -0400 Subject: [PATCH] tweak testing and add at test run for history expansion --- unittest/tools/test_lammps_shell.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/unittest/tools/test_lammps_shell.py b/unittest/tools/test_lammps_shell.py index 993b8fd50f..36c375fa59 100644 --- a/unittest/tools/test_lammps_shell.py +++ b/unittest/tools/test_lammps_shell.py @@ -4,7 +4,7 @@ import os, re, subprocess, unittest # enable test mode os.putenv('LAMMPS_SHELL_TESTING','1') -shell_prompt_re = r"(.*LAMMPS Shell> ([a-z0-9_]+) *([a-z0-9_\.]+)?.*)+" +shell_prompt_re = r"([^>]*LAMMPS Shell> ([a-z0-9_]+) *([a-z0-9_\.]+)?.*\n)+" # class LammpsShell(unittest.TestCase): @@ -26,23 +26,38 @@ class LammpsShell(unittest.TestCase): proc.kill() [outs,errs] = proc.communicate() - #print(outs.decode()) - return re.findall(shell_prompt_re, outs.decode('UTF-8'), re.MULTILINE)[0] + return outs.decode('UTF-8') def testExpandClear(self): """Test expansion of a shell specific command""" - self.assertEqual(self.InputRunner(b'cle\t\n')[1],"clear") + matches = re.findall(shell_prompt_re, self.InputRunner(b'cle\t\n'), re.MULTILINE) + self.assertEqual(matches[0][1],"clear") def testExpandSource(self): """Test expansion of a shell command and a file name""" with open('.tmp.in.source', 'w') as out: print('units real', file=out) out.close() - matches=self.InputRunner(b'sour\t.tmp.in.sou\t\n') + matches = re.findall(shell_prompt_re, self.InputRunner(b'sour\t.tmp.in.sou\t\n'), re.MULTILINE) os.remove('.tmp.in.source') - self.assertEqual(matches[1],"source") - self.assertEqual(matches[2],".tmp.in.source") + self.assertEqual(matches[0][1],"source") + self.assertEqual(matches[0][2],".tmp.in.source") + def testHistory(self): + """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') + idx = 0 + lines = out.splitlines() + for line in lines: + if line.startswith('LAMMPS Shell>'): break + idx += 1 + + self.assertEqual(lines[idx+4],"dimension 2") + self.assertEqual(lines[idx+6],"units real") + 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__":