2019-04-17 11:54:50 +02:00
|
|
|
import os
|
2017-03-08 00:44:32 -05:00
|
|
|
import sys
|
|
|
|
|
|
2020-07-01 13:07:22 +02:00
|
|
|
from drivers.base_driver import BaseDriver
|
2017-03-08 00:44:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PythonScriptDriver(BaseDriver):
|
|
|
|
|
"""
|
|
|
|
|
Driver to run a Python script.
|
|
|
|
|
|
|
|
|
|
Interface:
|
|
|
|
|
|
|
|
|
|
* put a "test.py" script in the test directory;
|
|
|
|
|
* put a "test.out" text file in the test directory.
|
|
|
|
|
|
|
|
|
|
This driver will run the Python script. Its output is then checked against
|
|
|
|
|
the expected output (test.out file). This mechanism is the most flexible
|
|
|
|
|
way to write a testcase, but also the more verbose one and the most complex
|
|
|
|
|
one. Use this driver when no other one fits.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def run(self):
|
2019-04-17 11:54:50 +02:00
|
|
|
env = dict(os.environ)
|
|
|
|
|
old_path = env.get('PYTHONPATH', '')
|
|
|
|
|
if old_path:
|
|
|
|
|
new_path = '{}{}{}'.format(
|
2020-07-01 13:07:22 +02:00
|
|
|
self.env.root_dir, os.path.pathsep, old_path)
|
2019-04-17 11:54:50 +02:00
|
|
|
else:
|
2020-07-01 13:07:22 +02:00
|
|
|
new_path = self.env.root_dir
|
2019-04-17 11:54:50 +02:00
|
|
|
env['PYTHONPATH'] = new_path
|
|
|
|
|
|
2020-07-01 13:07:22 +02:00
|
|
|
self.shell([sys.executable, 'test.py'], env=env)
|