diff --git a/ci/utils/nbtest.sh b/ci/utils/nbtest.sh deleted file mode 100755 index ae8b52d..0000000 --- a/ci/utils/nbtest.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -# Copyright (c) 2019-2021, NVIDIA CORPORATION. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Any failing command will set EXITCODE to non-zero -set +e # do not abort the script on error -set -o pipefail # piped commands propagate their error -set -E # ERR traps are inherited by subcommands -trap "EXITCODE=1" ERR - -# Prepend the following code to all scripts generated from nbconvert. This -# allows all cell and line magic code to run and update the namespace as if -# running in jupyter, but will also tolerate failures due to running in a -# non-jupyter env. -# Note: depending on the assumptions of the notebook script, ignoring failures -# may not be acceptable (meaning the converted notebook simply cannot run -# outside of jupyter as-is), hence the warning. -MAGIC_OVERRIDE_CODE=" -def my_run_line_magic(*args, **kwargs): - g=globals() - l={} - for a in args: - try: - exec(str(a),g,l) - except Exception as e: - print('WARNING: %s\n While executing this magic function code:\n%s\n continuing...\n' % (e, a)) - else: - g.update(l) - -def my_run_cell_magic(*args, **kwargs): - my_run_line_magic(*args, **kwargs) - -get_ipython().run_line_magic=my_run_line_magic -get_ipython().run_cell_magic=my_run_cell_magic - -" - -NO_COLORS=--colors=NoColor -EXITCODE=0 -NBTMPDIR=${WORKSPACE}/tmp -mkdir -p ${NBTMPDIR} - -for nb in $*; do - NBFILENAME=$1 - NBNAME=${NBFILENAME%.*} - NBNAME=${NBNAME##*/} - NBTESTSCRIPT=${NBTMPDIR}/${NBNAME}-test.py - shift - - echo -------------------------------------------------------------------------------- - echo STARTING: ${NBNAME} - echo -------------------------------------------------------------------------------- - jupyter nbconvert --to script ${NBFILENAME} --output ${NBTMPDIR}/${NBNAME}-test - echo "${MAGIC_OVERRIDE_CODE}" > ${NBTMPDIR}/tmpfile - cat ${NBTESTSCRIPT} >> ${NBTMPDIR}/tmpfile - mv ${NBTMPDIR}/tmpfile ${NBTESTSCRIPT} - - echo "Running \"ipython ${NO_COLORS} ${NBTESTSCRIPT}\" on $(date)" - echo - time bash -c "ipython ${NO_COLORS} ${NBTESTSCRIPT}; EC=\$?; echo -------------------------------------------------------------------------------- ; echo DONE: ${NBNAME}; exit \$EC" - NBEXITCODE=$? - echo EXIT CODE: ${NBEXITCODE} - echo -done - -exit ${EXITCODE} diff --git a/ci/utils/nbtestlog2junitxml.py b/ci/utils/nbtestlog2junitxml.py deleted file mode 100644 index e971225..0000000 --- a/ci/utils/nbtestlog2junitxml.py +++ /dev/null @@ -1,175 +0,0 @@ -# Copyright (c) 2019-2020, NVIDIA CORPORATION. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Generate a junit-xml file from parsing a nbtest log - -import re -from xml.etree.ElementTree import Element, ElementTree -from os import path -import string -from enum import Enum - - -startingPatt = re.compile("^STARTING: ([\w\.\-]+)$") -skippingPatt = re.compile("^SKIPPING: ([\w\.\-]+)\s*(\(([\w\.\-\ \,]+)\))?\s*$") -exitCodePatt = re.compile("^EXIT CODE: (\d+)$") -folderPatt = re.compile("^FOLDER: ([\w\.\-]+)$") -timePatt = re.compile("^real\s+([\d\.ms]+)$") -linePatt = re.compile("^" + ("-" * 80) + "$") - - -def getFileBaseName(filePathName): - return path.splitext(path.basename(filePathName))[0] - - -def makeTestCaseElement(attrDict): - return Element("testcase", attrib=attrDict) - - -def makeSystemOutElement(outputLines): - e = Element("system-out") - e.text = "".join(filter(lambda c: c in string.printable, outputLines)) - return e - - -def makeFailureElement(outputLines): - e = Element("failure", message="failed") - e.text = "".join(filter(lambda c: c in string.printable, outputLines)) - return e - - -def setFileNameAttr(attrDict, fileName): - attrDict.update(file=fileName, - classname="", - line="", - name="", - time="" - ) - -def setClassNameAttr(attrDict, className): - attrDict["classname"] = className - - -def setTestNameAttr(attrDict, testName): - attrDict["name"] = testName - - -def setTimeAttr(attrDict, timeVal): - (mins, seconds) = timeVal.split("m") - seconds = float(seconds.strip("s")) + (60 * int(mins)) - attrDict["time"] = str(seconds) - - -def incrNumAttr(element, attr): - newVal = int(element.attrib.get(attr)) + 1 - element.attrib[attr] = str(newVal) - - -def parseLog(logFile, testSuiteElement): - # Example attrs: - # errors="0" failures="0" hostname="a437d6835edf" name="pytest" skipped="2" tests="6" time="6.174" timestamp="2019-11-18T19:49:47.946307" - - with open(logFile) as lf: - testSuiteElement.attrib["tests"] = "0" - testSuiteElement.attrib["errors"] = "0" - testSuiteElement.attrib["failures"] = "0" - testSuiteElement.attrib["skipped"] = "0" - testSuiteElement.attrib["time"] = "0" - testSuiteElement.attrib["timestamp"] = "" - - attrDict = {} - #setFileNameAttr(attrDict, logFile) - setFileNameAttr(attrDict, "nbtest") - - parserStateEnum = Enum("parserStateEnum", - "newTest startingLine finishLine exitCode") - parserState = parserStateEnum.newTest - - testOutput = "" - - for line in lf.readlines(): - if parserState == parserStateEnum.newTest: - m = folderPatt.match(line) - if m: - setClassNameAttr(attrDict, m.group(1)) - continue - - m = skippingPatt.match(line) - if m: - setTestNameAttr(attrDict, getFileBaseName(m.group(1))) - setTimeAttr(attrDict, "0m0s") - skippedElement = makeTestCaseElement(attrDict) - message = m.group(3) or "" - skippedElement.append(Element("skipped", message=message, type="")) - testSuiteElement.append(skippedElement) - incrNumAttr(testSuiteElement, "skipped") - incrNumAttr(testSuiteElement, "tests") - continue - - m = startingPatt.match(line) - if m: - parserState = parserStateEnum.startingLine - testOutput = "" - setTestNameAttr(attrDict, m.group(1)) - setTimeAttr(attrDict, "0m0s") - continue - - continue - - elif parserState == parserStateEnum.startingLine: - if linePatt.match(line): - parserState = parserStateEnum.finishLine - testOutput = "" - continue - - elif parserState == parserStateEnum.finishLine: - if linePatt.match(line): - parserState = parserStateEnum.exitCode - else: - testOutput += line - continue - - elif parserState == parserStateEnum.exitCode: - m = exitCodePatt.match(line) - if m: - testCaseElement = makeTestCaseElement(attrDict) - if m.group(1) != "0": - failureElement = makeFailureElement(testOutput) - testCaseElement.append(failureElement) - incrNumAttr(testSuiteElement, "failures") - else: - systemOutElement = makeSystemOutElement(testOutput) - testCaseElement.append(systemOutElement) - - testSuiteElement.append(testCaseElement) - parserState = parserStateEnum.newTest - testOutput = "" - incrNumAttr(testSuiteElement, "tests") - continue - - m = timePatt.match(line) - if m: - setTimeAttr(attrDict, m.group(1)) - continue - - continue - - -if __name__ == "__main__": - import sys - - testSuitesElement = Element("testsuites") - testSuiteElement = Element("testsuite", name="nbtest", hostname="") - parseLog(sys.argv[1], testSuiteElement) - testSuitesElement.append(testSuiteElement) - ElementTree(testSuitesElement).write(sys.argv[1]+".xml", xml_declaration=True)