Runs all the python tests, or just those that match the system property #TEST_PATTERN_SYSTEM_PROPERTY if it exists. Use #TEST_INVOCATIONS_SYSTEM_PROPERTY to specify the number of repetitions, or use 0 for unlimited repetitions.
| 41 | * for unlimited repetitions. |
| 42 | */ |
| 43 | public class JythonTest |
| 44 | { |
| 45 | public interface PathBuilder { |
| 46 | public PathBuilder append(String path); |
| 47 | } |
| 48 | |
| 49 | private static final Logger LOGGER = Logger.getLogger(JythonTest.class.getName()); |
| 50 | |
| 51 | /* System properties expected to be defined in test/pom.xml */ |
| 52 | protected static final String PROTON_JYTHON_BINDING = "protonJythonBinding"; |
| 53 | protected static final String PROTON_JYTHON_SHIM = "protonJythonShim"; |
| 54 | protected static final String PROTON_JYTHON_TEST_ROOT = "protonJythonTestRoot"; |
| 55 | protected static final String PROTON_JYTHON_TEST_SCRIPT = "protonJythonTestScript"; |
| 56 | protected static final String PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY = "protonJythonTestXmlOutputDirectory"; |
| 57 | protected static final String PROTON_JYTHON_IGNORE_FILE = "protonJythonIgnoreFile"; |
| 58 | |
| 59 | /** Name of the junit style xml report to be written by the python test script */ |
| 60 | private static final String XML_REPORT_NAME = "TEST-jython-test-results.xml"; |
| 61 | |
| 62 | public static final String TEST_PATTERN_SYSTEM_PROPERTY = "proton.pythontest.pattern"; |
| 63 | public static final String IGNORE_FILE_SYSTEM_PROPERTY = "proton.pythontest.ignore_file"; |
| 64 | |
| 65 | /** The number of times to run the test, or forever if zero */ |
| 66 | public static final String TEST_INVOCATIONS_SYSTEM_PROPERTY = "proton.pythontest.invocations"; |
| 67 | |
| 68 | public static final String ALWAYS_COLORIZE_SYSTEM_PROPERTY = "proton.pythontest.always_colorize"; |
| 69 | |
| 70 | @Test |
| 71 | public void test() throws Exception |
| 72 | { |
| 73 | String testScript = getJythonTestScript(); |
| 74 | String testRoot = getJythonTestRoot(); |
| 75 | String xmlReportFile = getOptionalXmlReportFilename(); |
| 76 | String ignoreFile = getOptionalIgnoreFile(); |
| 77 | |
| 78 | final PythonInterpreter interp = createInterpreterWithArgs(xmlReportFile, ignoreFile); |
| 79 | PathBuilder pathBuilder = new PathBuilder() { |
| 80 | @Override |
| 81 | public PathBuilder append(String path) { |
| 82 | interp.getSystemState().path.insert(0, new PyString(path)); |
| 83 | return this; |
| 84 | } |
| 85 | }; |
| 86 | extendPath(pathBuilder); |
| 87 | |
| 88 | LOGGER.info("About to call Jython test script: '" + testScript |
| 89 | + "' with '" + testRoot + "' added to Jython path"); |
| 90 | |
| 91 | int maxInvocations = Integer.getInteger(TEST_INVOCATIONS_SYSTEM_PROPERTY, 1); |
| 92 | assertTrue("Number of invocations should be non-negative", maxInvocations >= 0); |
| 93 | boolean loopForever = maxInvocations == 0; |
| 94 | if(maxInvocations > 1) |
| 95 | { |
| 96 | LOGGER.info("Will invoke Python test " + maxInvocations + " times"); |
| 97 | } |
| 98 | if(loopForever) |
| 99 | { |
| 100 | LOGGER.info("Will repeatedly invoke Python test forever"); |