(cls, name, *,
prescript=None,
import_first=False,
postscript=None,
postcleanup=False,
)
| 262 | |
| 263 | @classmethod |
| 264 | def build_script(cls, name, *, |
| 265 | prescript=None, |
| 266 | import_first=False, |
| 267 | postscript=None, |
| 268 | postcleanup=False, |
| 269 | ): |
| 270 | if postcleanup is True: |
| 271 | postcleanup = cls.CLEANUP_SCRIPT |
| 272 | elif isinstance(postcleanup, str): |
| 273 | postcleanup = textwrap.dedent(postcleanup).strip() |
| 274 | postcleanup = cls.CLEANUP_SCRIPT + os.linesep + postcleanup |
| 275 | else: |
| 276 | postcleanup = '' |
| 277 | prescript = textwrap.dedent(prescript).strip() if prescript else '' |
| 278 | postscript = textwrap.dedent(postscript).strip() if postscript else '' |
| 279 | |
| 280 | if postcleanup: |
| 281 | if postscript: |
| 282 | postscript = postscript + os.linesep * 2 + postcleanup |
| 283 | else: |
| 284 | postscript = postcleanup |
| 285 | |
| 286 | if import_first: |
| 287 | prescript += textwrap.dedent(f''' |
| 288 | |
| 289 | # Now import the module. |
| 290 | assert name not in sys.modules |
| 291 | import {name}''') |
| 292 | |
| 293 | return cls.SCRIPT.format( |
| 294 | imports=cls.IMPORTS.strip(), |
| 295 | name=name, |
| 296 | prescript=prescript.strip(), |
| 297 | body=cls.SCRIPT_BODY.strip(), |
| 298 | postscript=postscript, |
| 299 | ) |
| 300 | |
| 301 | @classmethod |
| 302 | def parse(cls, text): |
no test coverage detected