From cc18927ccfcd33f13990d8cba0bb96b5ee7d380a Mon Sep 17 00:00:00 2001 From: Sam Leeman-Munk Date: Mon, 8 Jan 2024 08:49:07 -0500 Subject: [PATCH] Improved error message when calling symget on a dead session --- saspy/sasbase.py | 2 ++ saspy/tests/test_symget.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 saspy/tests/test_symget.py diff --git a/saspy/sasbase.py b/saspy/sasbase.py index 9bb8ab4e..9405826f 100644 --- a/saspy/sasbase.py +++ b/saspy/sasbase.py @@ -2093,6 +2093,8 @@ def symexist(self, name: str): ll = self._io.submit("%put " + name + "BEGIN=%symexist(" + name + ") "+ name+"END=;\n") l2 = ll['LOG'].rpartition(name + "BEGIN=")[2].rpartition(name+"END=")[0].strip().replace('\n','') + if l2 == '': + raise ValueError("Failed to execute symexist. Your session may be dead.") var = int(l2) return bool(var) diff --git a/saspy/tests/test_symget.py b/saspy/tests/test_symget.py new file mode 100644 index 00000000..e6ef15ba --- /dev/null +++ b/saspy/tests/test_symget.py @@ -0,0 +1,18 @@ +import unittest +import saspy + + +class TestSASViyaML(unittest.TestCase): + + def testSymgetOnDeadSession(self): + sas = saspy.SASsession() + + results = sas.submit("endsas;") + + try: + sas.SYSINFO() + except ValueError as e: + self.assertFalse(str(e)!="Failed to execute symexist. Your session may be dead.") + +if __name__ == '__main__': + unittest.main()