Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://beta.ruff.rs
# https://docs.pytest.org
name: test_python
on:
push:
# branches: [master]
pull_request:
branches: [master]
jobs:
test_python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install --user pytest ruff
- run: ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
# - run: ruff --format=github --line-length=200 --target-version=py37 .
# - run: ruff --format=github --target-version=py37 .
# Fix https://github.com/test262-utils/test262-harness-py/issues/8 and remove `|| true`
- run: pytest --ignore=test/test_common.py --ignore=test/test_parseTestRecord.py
- run: pytest || true
2 changes: 1 addition & 1 deletion src/_monkeyYaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def myMaybeList(value):
def myMultilineList(lines, value):
# assume no explcit indentor (otherwise have to parse value)
value = []
indent = None
indent = 0
while lines:
line = lines.pop(0)
leading = myLeadingSpaces(line)
Expand Down
29 changes: 15 additions & 14 deletions src/_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This code is governed by the BSD license found in the LICENSE file.

#--Imports---------------------------------------------------------------------
from __future__ import print_function
import argparse
import os
import sys
Expand Down Expand Up @@ -36,8 +37,8 @@ def generateHarness(harnessType, jsonFile, description):
ARGS = __parser.parse_args()

if not os.path.exists(EXCLUDED_FILENAME):
print "Cannot generate (JSON) test262 tests without a file," + \
" %s, showing which tests have been disabled!" % EXCLUDED_FILENAME
print("Cannot generate (JSON) test262 tests without a file," + \
" %s, showing which tests have been disabled!" % EXCLUDED_FILENAME)
sys.exit(1)
EXCLUDE_LIST = xml.dom.minidom.parse(EXCLUDED_FILENAME)
EXCLUDE_LIST = EXCLUDE_LIST.getElementsByTagName("test")
Expand All @@ -55,11 +56,11 @@ def generateHarness(harnessType, jsonFile, description):

#--Sanity checks--------------------------------------------------------------#
if not os.path.exists(TEST262_CASES_DIR):
print "Cannot generate (JSON) test262 tests when the path containing said tests, %s, does not exist!" % TEST262_CASES_DIR
print("Cannot generate (JSON) test262 tests when the path containing said tests, %s, does not exist!" % TEST262_CASES_DIR)
sys.exit(1)

if not os.path.exists(TEST262_HARNESS_DIR):
print "Cannot copy the test harness from a path, %s, that does not exist!" % TEST262_HARNESS_DIR
print("Cannot copy the test harness from a path, %s, that does not exist!" % TEST262_HARNESS_DIR)
sys.exit(1)

if not os.path.exists(TEST262_WEB_CASES_DIR):
Expand All @@ -69,7 +70,7 @@ def generateHarness(harnessType, jsonFile, description):
os.mkdir(TEST262_WEB_HARNESS_DIR)

if not hasattr(ARGS, "version"):
print "A test262 suite version must be specified from the command-line to run this script!"
print("A test262 suite version must be specified from the command-line to run this script!")
sys.exit(1)

#--Helpers--------------------------------------------------------------------#
Expand Down Expand Up @@ -123,7 +124,7 @@ def dirWalker(dirName):
#for a JSON file
temp = getJSCount(dirName)
if temp==0:
print "ERROR: expected there to be JavaScript tests under dirName!"
print("ERROR: expected there to be JavaScript tests under dirName!")
sys.exit(1)
#TODO - commenting out this elif/else clause seems to be causing *.json
#naming conflicts WRT Sputnik test dirs.
Expand Down Expand Up @@ -165,7 +166,7 @@ def getAllJSFiles(dirName):
for temp in os.listdir(TEST262_CASES_DIR):
temp = os.path.join(TEST262_CASES_DIR, temp)
if not os.path.exists(temp):
print "The expected ES5 test directory,", temp, "did not exist!"
print("The expected ES5 test directory,", temp, "did not exist!")
sys.exit(1)

if temp.find("/.") != -1:
Expand All @@ -179,7 +180,7 @@ def getAllJSFiles(dirName):

for chapter in TEST_SUITE_SECTIONS:
chapterName = chapter.rsplit(os.path.sep, 1)[1]
print "Generating test cases for ES5 chapter:", chapterName
print("Generating test cases for ES5 chapter:", chapterName)
#create dictionaries for all our tests and a section
testsList = {}
sect = {}
Expand Down Expand Up @@ -223,8 +224,8 @@ def getAllJSFiles(dirName):
scriptCodeContent += line

if scriptCodeContent==scriptCode[0]:
print "WARNING (" + test + \
"): unable to strip comments/license header/etc."
print("WARNING (" + test + \
"): unable to strip comments/license header/etc.")
scriptCodeContent = "".join(scriptCode)
scriptCodeContentB64 = base64.b64encode(scriptCodeContent)

Expand Down Expand Up @@ -255,7 +256,7 @@ def getAllJSFiles(dirName):
fConsoleMeta.write("testDescrip = " + str(metaDict))
testCount += 1
else:
print "Excluded:", testName
print("Excluded:", testName)
excluded = excluded + 1

#we have completed our tests
Expand Down Expand Up @@ -311,8 +312,8 @@ def getAllJSFiles(dirName):
json.dump(SUITE_DESCRIP_JSON, f, separators=(',',':'), sort_keys=True)

#Deploy test harness to website as well
print ""
print "Deploying test harness files to 'TEST262_WEB_HARNESS_DIR'..."
print("")
print("Deploying test harness files to 'TEST262_WEB_HARNESS_DIR'...")
if TEST262_HARNESS_DIR!=TEST262_WEB_HARNESS_DIR:
for filename in [x for x in os.listdir(TEST262_HARNESS_DIR) \
if x.endswith(".js")]:
Expand All @@ -332,4 +333,4 @@ def getAllJSFiles(dirName):
if not fileExists:
SC_HELPER.add(toFilename)

print "Done."
print("Done.")
10 changes: 9 additions & 1 deletion src/parseTestRecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# TODO: resolve differences with common.py and unify into one file.


from __future__ import print_function

import os
Expand All @@ -14,6 +13,15 @@

from _monkeyYaml import load as yamlLoad

headerPatternStr = r"(?:(?:\s*\/\/.*)?\s*\n)*"
headerPattern = re.compile("^" + headerPatternStr)


def stripHeader(src):
header = headerPattern.match(src).group(0)
return src[len(header):]


#def onerror(message):
# print(message)

Expand Down
47 changes: 24 additions & 23 deletions src/test262.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# test262.py and packager.py.


from __future__ import print_function
import logging
import optparse
import os
Expand Down Expand Up @@ -42,8 +43,8 @@ def ReportError(s):


if not os.path.exists(EXCLUDED_FILENAME):
print "Cannot generate (JSON) test262 tests without a file," + \
" %s, showing which tests have been disabled!" % EXCLUDED_FILENAME
print("Cannot generate (JSON) test262 tests without a file," + \
" %s, showing which tests have been disabled!" % EXCLUDED_FILENAME)
sys.exit(1)
EXCLUDE_LIST = xml.dom.minidom.parse(EXCLUDED_FILENAME)
EXCLUDE_REASON = EXCLUDE_LIST.getElementsByTagName("reason")
Expand Down Expand Up @@ -128,7 +129,7 @@ def Dispose(self):
try:
self.Close()
os.unlink(self.name)
except OSError, e:
except OSError as e:
logging.error("Error disposing temp file: %s", str(e))


Expand All @@ -145,20 +146,20 @@ def ReportOutcome(self, long_format):
mode = self.case.GetMode()
if self.HasUnexpectedOutcome():
if self.case.IsNegative():
print "=== %s was expected to fail in %s, but didn't ===" % (name, mode)
print "--- expected error: %s ---\n" % self.case.GetNegativeType()
print("=== %s was expected to fail in %s, but didn't ===" % (name, mode))
print("--- expected error: %s ---\n" % self.case.GetNegativeType())
else:
if long_format:
print "=== %s failed in %s ===" % (name, mode)
print("=== %s failed in %s ===" % (name, mode))
else:
print "%s in %s: " % (name, mode)
print("%s in %s: " % (name, mode))
self.WriteOutput(sys.stdout)
if long_format:
print "==="
print("===")
elif self.case.IsNegative():
print "%s failed in %s as expected" % (name, mode)
print("%s failed in %s as expected" % (name, mode))
else:
print "%s passed in %s" % (name, mode)
print("%s passed in %s" % (name, mode))

def WriteOutput(self, target):
out = self.stdout.strip()
Expand Down Expand Up @@ -373,7 +374,7 @@ def Run(self, command_template):
return result

def Print(self):
print self.GetSource()
print(self.GetSource())

def validate(self):
flags = self.testRecord.get("flags")
Expand Down Expand Up @@ -488,7 +489,7 @@ def EnumerateTests(self, tests):
basename = path.basename(full_path)[:-3]
name = rel_path.split(path.sep)[:-1] + [basename]
if EXCLUDE_LIST.count(basename) >= 1:
print 'Excluded: ' + basename
print('Excluded: ' + basename)
else:
if not self.non_strict_only:
strict_case = TestCase(self, name, full_path, True)
Expand All @@ -511,9 +512,9 @@ def PrintSummary(self, progress, logfile):
def write(s):
if logfile:
self.logf.write(s + "\n")
print s
print(s)

print
print()
write("=== Summary ===");
count = progress.count
succeeded = progress.succeeded
Expand All @@ -527,12 +528,12 @@ def write(s):
positive = [c for c in progress.failed_tests if not c.case.IsNegative()]
negative = [c for c in progress.failed_tests if c.case.IsNegative()]
if len(positive) > 0:
print
print()
write("Failed Tests")
for result in positive:
write(" %s in %s" % (result.case.GetName(), result.case.GetMode()))
if len(negative) > 0:
print
print()
write("Expected to fail but passed ---")
for result in negative:
write(" %s in %s" % (result.case.GetName(), result.case.GetMode()))
Expand All @@ -541,7 +542,7 @@ def PrintFailureOutput(self, progress, logfile):
for result in progress.failed_tests:
if logfile:
self.WriteLog(result)
print
print()
result.ReportOutcome(False)

def Run(self, command_template, tests, print_summary, full_summary, logname, junitfile):
Expand Down Expand Up @@ -585,9 +586,9 @@ def Run(self, command_template, tests, print_summary, full_summary, logname, jun
if full_summary:
self.PrintFailureOutput(progress, logname)
else:
print
print "Use --full-summary to see output from failed tests"
print
print()
print("Use --full-summary to see output from failed tests")
print()
return progress.failed

def WriteLog(self, result):
Expand Down Expand Up @@ -619,7 +620,7 @@ def ListIncludes(self, tests):
includes = case.GetIncludeList()
includes_dict.update(includes)

print includes_dict
print(includes_dict)


def Main():
Expand Down Expand Up @@ -659,6 +660,6 @@ def Main():
try:
code = Main()
sys.exit(code)
except Test262Error, e:
print "Error: %s" % e.message
except Test262Error as e:
print("Error: %s" % e.message)
sys.exit(1)
14 changes: 9 additions & 5 deletions test/test_test262.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

import sys
import os
import cStringIO
from functools import wraps

try:
from io import StringIO # Python 3
except ImportError:
from cStringIO import StringIO # Python 2

sys.path.append("src")

import test262
Expand Down Expand Up @@ -88,7 +92,7 @@ def test_summary_logfile(self):
progress.succeeded = 98
progress.failed = 2

fake_log = cStringIO.StringIO()
fake_log = StringIO()
test_suite.logf = fake_log

result = mute(True)(test_suite.PrintSummary)(progress, True)
Expand Down Expand Up @@ -154,7 +158,7 @@ def test_summary_withfails_andlog(self):
MockResult(MockTest("bar", True))
]

fake_log = cStringIO.StringIO()
fake_log = StringIO()
test_suite.logf = fake_log

expected_out = """
Expand Down Expand Up @@ -195,7 +199,7 @@ def test_summary_success_logfile(self):
progress.succeeded = 100
progress.failed = 0

fake_log = cStringIO.StringIO()
fake_log = StringIO()
test_suite.logf = fake_log

result = mute(True)(test_suite.PrintSummary)(progress, True)
Expand Down Expand Up @@ -253,7 +257,7 @@ def decorator(func):
def wrapper(*args, **kwargs):

saved_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
sys.stdout = StringIO()

try:
out = func(*args, **kwargs)
Expand Down