Skip to content

tests/run-tests.py: Ensure correct cwd for mpy tests. #11468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2023
Merged
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: 10 additions & 10 deletions tests/io/file1.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
f = open("io/data/file1")
f = open("data/file1")
print(f.read(5))
print(f.readline())
print(f.read())
f = open("io/data/file1")
f = open("data/file1")
print(f.readlines())
f = open("io/data/file1", "r")
f = open("data/file1", "r")
print(f.readlines())
f = open("io/data/file1", "rb")
f = open("data/file1", "rb")
print(f.readlines())
f = open("io/data/file1", mode="r")
f = open("data/file1", mode="r")
print(f.readlines())
f = open("io/data/file1", mode="rb")
f = open("data/file1", mode="rb")
print(f.readlines())

# write() error
f = open("io/data/file1", "r")
f = open("data/file1", "r")
try:
f.write("x")
except OSError:
print("OSError")
f.close()

# read(n) error on binary file
f = open("io/data/file1", "ab")
f = open("data/file1", "ab")
try:
f.read(1)
except OSError:
print("OSError")
f.close()

# read(n) error on text file
f = open("io/data/file1", "at")
f = open("data/file1", "at")
try:
f.read(1)
except OSError:
print("OSError")
f.close()

# read() w/o args error
f = open("io/data/file1", "ab")
f = open("data/file1", "ab")
try:
f.read()
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion tests/io/file_iter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
f = open("io/data/file1")
f = open("data/file1")
for l in f:
print(l)
2 changes: 1 addition & 1 deletion tests/io/file_long_read.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
f = open("io/data/file1")
f = open("data/file1")
b = f.read(100)
print(len(b))
2 changes: 1 addition & 1 deletion tests/io/file_long_read2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
f = open("io/data/bigfile1")
f = open("data/bigfile1")
b = f.read()
print(len(b))
print(b)
2 changes: 1 addition & 1 deletion tests/io/file_long_read3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
f = open("io/data/bigfile1", "rb")
f = open("data/bigfile1", "rb")
b = f.read(512)
print(len(b))
print(b)
6 changes: 3 additions & 3 deletions tests/io/file_readinto.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
b = bytearray(30)
f = open("io/data/file1", "rb")
f = open("data/file1", "rb")
print(f.readinto(b))
print(b)
f = open("io/data/file2", "rb")
f = open("data/file2", "rb")
print(f.readinto(b))
print(b)

# readinto() on writable file
f = open("io/data/file1", "ab")
f = open("data/file1", "ab")
try:
f.readinto(bytearray(4))
except OSError:
Expand Down
4 changes: 2 additions & 2 deletions tests/io/file_readinto_len.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
b = bytearray(30)
f = open("io/data/file1", "rb")
f = open("data/file1", "rb")
# 2nd arg (length to read) is extension to CPython
print(f.readinto(b, 8))
print(b)

b = bytearray(4)
f = open("io/data/file1", "rb")
f = open("data/file1", "rb")
print(f.readinto(b, 8))
print(b)
4 changes: 2 additions & 2 deletions tests/io/file_readline.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
f = open("io/data/file1")
f = open("data/file1")
print(f.readline())
print(f.readline(3))
print(f.readline(4))
print(f.readline(5))
print(f.readline())

# readline() on writable file
f = open("io/data/file1", "ab")
f = open("data/file1", "ab")
try:
f.readline()
except OSError:
Expand Down
6 changes: 3 additions & 3 deletions tests/io/file_seek.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
f = open("io/data/file1", "rb")
f = open("data/file1", "rb")
print(f.seek(6))
print(f.read(5))
print(f.tell())
Expand All @@ -18,14 +18,14 @@
f.close()

# test text mode
f = open("io/data/file1", "rt")
f = open("data/file1", "rt")
print(f.seek(6))
print(f.read(5))
print(f.tell())
f.close()

# seek closed file
f = open("io/data/file1", "r")
f = open("data/file1", "r")
f.close()
try:
f.seek(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/io/file_with.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
f = open("io/data/file1")
f = open("data/file1")

with f as f2:
print(f2.read())
Expand Down
16 changes: 10 additions & 6 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,29 +261,31 @@ def send_get(what):
# a standard test run on PC

# create system command
cmdlist = [MICROPYTHON, "-X", "emit=" + args.emit]
cmdlist = [os.path.abspath(MICROPYTHON), "-X", "emit=" + args.emit]
if args.heapsize is not None:
cmdlist.extend(["-X", "heapsize=" + args.heapsize])
if sys.platform == "darwin":
cmdlist.extend(["-X", "realtime"])

cwd = os.path.dirname(test_file)

# if running via .mpy, first compile the .py file
if args.via_mpy:
mpy_modname = tempfile.mktemp(dir="")
mpy_filename = mpy_modname + ".mpy"
mpy_filename = tempfile.mktemp(dir=cwd, suffix=".mpy")
subprocess.check_output(
[MPYCROSS]
+ args.mpy_cross_flags.split()
+ ["-o", mpy_filename, "-X", "emit=" + args.emit, test_file]
)
mpy_modname = os.path.splitext(os.path.basename(mpy_filename))[0]
cmdlist.extend(["-m", mpy_modname])
else:
cmdlist.append(test_file)
cmdlist.append(os.path.abspath(test_file))

# run the actual test
try:
output_mupy = subprocess.check_output(
cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT
cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT, cwd=cwd
)
except subprocess.CalledProcessError as er:
had_crash = True
Expand Down Expand Up @@ -707,7 +709,9 @@ def run_one_test(test_file):
else:
# run CPython to work out expected output
try:
output_expected = subprocess.check_output(CPYTHON3_CMD + [test_file])
output_expected = subprocess.check_output(
CPYTHON3_CMD + [os.path.abspath(test_file)], cwd=os.path.dirname(test_file)
)
if args.write_exp:
with open(test_file_expected, "wb") as f:
f.write(output_expected)
Expand Down
2 changes: 1 addition & 1 deletion tests/unicode/file1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
f = open("unicode/data/utf-8_1.txt", encoding="utf-8")
f = open("data/utf-8_1.txt", encoding="utf-8")
l = f.readline()
print(l)
print(len(l))
2 changes: 1 addition & 1 deletion tests/unicode/file2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def do(mode):
enc = None
else:
enc = "utf-8"
f = open("unicode/data/utf-8_2.txt", mode=mode, encoding=enc)
f = open("data/utf-8_2.txt", mode=mode, encoding=enc)
print(f.read(1))
print(f.read(1))
print(f.read(2))
Expand Down
2 changes: 1 addition & 1 deletion tests/unicode/file_invalid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try:
f = open("unicode/data/utf-8_invalid.txt", encoding="utf-8")
f = open("data/utf-8_invalid.txt", encoding="utf-8")
f.read()
except UnicodeError:
print("UnicodeError")