""" Tests dealing with script parsing and execution. """ #c Copyright 2008-2025, the GAVO project #c #c This program is free software, covered by the GNU GPL. See the #c COPYING file in the source distribution. from gavo.helpers import testhelpers from gavo import base from gavo import rscdesc from gavo import rsc from gavo import rscdef from gavo.rscdef import scripting import tresc class FakeRunner(scripting.ScriptRunner): """a script runner that just notices something has run. Fetch the stuff run destructively by using getRunScripts() """ _scriptsRun = [] @classmethod def getScriptsRun(cls): try: return cls._scriptsRun[:] finally: cls._scriptsRun[:] = [] @classmethod def reset(cls): cls._scriptsRun = [] def _prepare(self, script): self.toNote = script.id def run(self, table, **kwargs): self._scriptsRun.append(table.tableDef.id+"-"+self.toNote) scripting.RUNNER_CLASSES["Fake"] = FakeRunner scripting.Script._lang.validValues.add("Fake") class ScriptTest(testhelpers.VerboseTest): """tests for script elements (but not actual scripting, that's somewhere else) """ def testOkScripts(self): s = base.parseFromString(scripting.Script, '') self.assertEqual(s.type, "beforeDrop") self.assertEqual(s.name, "test") self.assertEqual(s.content_, "drop table foo") def testBadScripts(self): self.assertRaises(base.StructureError, base.parseFromString, *(scripting.Script, '')) self.assertRaises(base.StructureError, base.parseFromString, *(scripting.Script, '')) def testBadScriptType(self): self.assertRaisesWithMsg(base.StructureError, 'At IO:\'
""") try: t = rsc.TableForDef(rd.getById("foo"), connection=self.conn) self.assertRaisesWithMsg( base.StructureError, 'At IO:\'
""") try: t = rsc.TableForDef(rd.getById("foo"), connection=self.conn) self.assertRaisesWithMsg( base.StructureError, 'At IO:\'