summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test/run.py
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test/run.py')
-rwxr-xr-xjs/src/tests/test/run.py74
1 files changed, 46 insertions, 28 deletions
diff --git a/js/src/tests/test/run.py b/js/src/tests/test/run.py
index a6f7a94932..862045a083 100755
--- a/js/src/tests/test/run.py
+++ b/js/src/tests/test/run.py
@@ -1,19 +1,23 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Adapted from https://github.com/tc39/test262/blob/main/tools/generation/test/run.py
import contextlib
import os
import shutil
import subprocess
+import sys
import tempfile
import unittest
-testDir = os.path.dirname(os.path.relpath(__file__))
-OUT_DIR = os.path.join(testDir, "out")
+import pytest
+from mozunit import main
+
+testDir = os.path.dirname(os.path.abspath(__file__))
+OUT_DIR = os.path.abspath(os.path.join(testDir, "..", "out"))
EXPECTED_DIR = os.path.join(testDir, "expected")
ex = os.path.join(testDir, "..", "test262-export.py")
importExec = os.path.join(testDir, "..", "test262-update.py")
-test262Url = "git://github.com/tc39/test262.git"
+test262Url = "https://github.com/tc39/test262.git"
@contextlib.contextmanager
@@ -29,8 +33,12 @@ class TestExport(unittest.TestCase):
maxDiff = None
def exportScript(self):
- relpath = os.path.relpath(os.path.join(testDir, "fixtures", "export"))
- sp = subprocess.Popen([ex, relpath, "--out", OUT_DIR], stdout=subprocess.PIPE)
+ abspath = os.path.abspath(os.path.join(testDir, "fixtures", "export"))
+ sp = subprocess.Popen(
+ [sys.executable, os.path.abspath(ex), abspath, "--out", OUT_DIR],
+ stdout=subprocess.PIPE,
+ cwd=os.path.join(testDir, ".."),
+ )
stdout, stderr = sp.communicate()
return dict(stdout=stdout, stderr=stderr, returncode=sp.returncode)
@@ -67,56 +75,57 @@ class TestExport(unittest.TestCase):
)
# Run import script
- print("%s --local %s --out %s" % (importExec, cloneDir, OUT_DIR))
+ print(
+ "%s %s --local %s --out %s"
+ % (sys.executable, importExec, cloneDir, OUT_DIR)
+ )
sp = subprocess.Popen(
- [importExec, "--local", cloneDir, "--out", OUT_DIR],
+ [sys.executable, importExec, "--local", cloneDir, "--out", OUT_DIR],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
+ cwd=os.path.join(testDir, ".."),
)
- stdoutdata, _ = sp.communicate()
+ stdoutdata, stderrdata = sp.communicate()
- return stdoutdata, sp.returncode, cloneDir
+ return stdoutdata, stderrdata, sp.returncode, cloneDir
- def isTestFile(self, filename):
+ def isTestFile(self, filename: str):
return not (
filename.startswith(".")
or filename.startswith("#")
or filename.endswith("~")
)
- def getFiles(self, path):
- names = []
+ def getFiles(self, path: str):
+ names: list[str] = []
for root, _, fileNames in os.walk(path):
for fileName in filter(self.isTestFile, fileNames):
names.append(os.path.join(root, fileName))
names.sort()
return names
- def compareTrees(self, targetName):
- expectedPath = os.path.join(EXPECTED_DIR, targetName)
- actualPath = OUT_DIR
-
+ def compareTrees(self, expectedPath: str, actualPath: str):
expectedFiles = self.getFiles(expectedPath)
actualFiles = self.getFiles(actualPath)
self.assertListEqual(
- map(lambda x: os.path.relpath(x, expectedPath), expectedFiles),
- map(lambda x: os.path.relpath(x, actualPath), actualFiles),
+ [os.path.relpath(x, expectedPath) for x in expectedFiles],
+ [os.path.relpath(x, actualPath) for x in actualFiles],
)
for expectedFile, actualFile in zip(expectedFiles, actualFiles):
with open(expectedFile) as expectedHandle:
with open(actualFile) as actualHandle:
self.assertMultiLineEqual(
- expectedHandle.read(), actualHandle.read()
+ expectedHandle.read(), actualHandle.read(), expectedFile
)
- def compareContents(self, output, filePath, folder):
- with open(filePath, "rb") as file:
+ def compareContents(self, output: bytes, filePath: str, folder: str):
+ with open(filePath, "r") as file:
expected = file.read()
expected = expected.replace("{{folder}}", folder)
- self.assertMultiLineEqual(output, expected)
+ self.assertMultiLineEqual(output.decode("utf-8"), expected)
def tearDown(self):
shutil.rmtree(OUT_DIR, ignore_errors=True)
@@ -124,16 +133,25 @@ class TestExport(unittest.TestCase):
def test_export(self):
result = self.exportScript()
self.assertEqual(result["returncode"], 0)
- self.compareTrees("export")
+ expectedPath = os.path.join(EXPECTED_DIR, "export")
+ actualPath = os.path.join(OUT_DIR, "tests", "export")
+ self.compareTrees(expectedPath, actualPath)
+ @pytest.mark.skip(reason="test fetches from github")
def test_import_local(self):
- output, returncode, folder = self.importLocal()
+ stdoutdata, stderrdata, returncode, folder = self.importLocal()
+ self.assertEqual(stderrdata, b"")
self.assertEqual(returncode, 0)
- self.compareTrees(os.path.join("import", "files"))
+ self.compareTrees(
+ os.path.join(EXPECTED_DIR, "import", "files", "local"),
+ os.path.join(OUT_DIR, "local"),
+ )
self.compareContents(
- output, os.path.join(testDir, "expected", "import", "output.txt"), folder
+ stdoutdata,
+ os.path.join(testDir, "expected", "import", "output.txt"),
+ folder,
)
if __name__ == "__main__":
- unittest.main()
+ main()