14 lines
980 B
Python
14 lines
980 B
Python
import importlib.util,pathlib,unittest
|
|
path=pathlib.Path(__file__).resolve().parents[1]/'scripts/publish-jarvis-dev-form.py'
|
|
spec=importlib.util.spec_from_file_location('dev_form',path);module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
|
|
class DevFormPublisherTests(unittest.TestCase):
|
|
def test_only_new_form_replaced_and_history_preserved(self):
|
|
old="<head></head>HISTORY ORIGINAL<?php elseif($view==='new'):?>OLD FORM<?php endif;?>\n<footer>UNCHANGED FOOTER"
|
|
result=module.patch_view(old)
|
|
self.assertIn('HISTORY ORIGINAL',result);self.assertIn('UNCHANGED FOOTER',result)
|
|
self.assertNotIn('OLD FORM',result);self.assertIn("require __DIR__.'/dev-jarvis-form.php'",result)
|
|
self.assertEqual(result,module.patch_view(result))
|
|
def test_changed_boundaries_are_rejected(self):
|
|
for value in ['no marker',"<?php elseif($view==='new'):?>no end"]:
|
|
with self.assertRaises(ValueError):module.patch_view(value)
|
|
if __name__=='__main__':unittest.main()
|

Staff