17127bbee5
Previously when using --via-mpy, the file was compiled to tests/<tmp>.mpy and then run using `micropython -m <tmp>` in the current cwd (usually tests/). This meant that an import in the test would be resolved relative to tests/. This is different to regular (non-via-mpy) tests, where we run (for example) `micropython basics/test.py` which means that an import would be resolved relative to basics/. Now --via-mpy matches the .py behavior. This is important because: a) It makes it so import tests do the right thing. b) There are directory names in tests/ that match built-in module names. Furthermore, it always ensures the cwd (for both micropython and cpython) is the test directory (e.g. basics/) rather than being left unset. This also makes it clearer inside the test that e.g. file access is relative to the Python file. Updated tests with file paths to match. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
50 lines
851 B
Python
50 lines
851 B
Python
f = open("data/file1")
|
|
print(f.read(5))
|
|
print(f.readline())
|
|
print(f.read())
|
|
f = open("data/file1")
|
|
print(f.readlines())
|
|
f = open("data/file1", "r")
|
|
print(f.readlines())
|
|
f = open("data/file1", "rb")
|
|
print(f.readlines())
|
|
f = open("data/file1", mode="r")
|
|
print(f.readlines())
|
|
f = open("data/file1", mode="rb")
|
|
print(f.readlines())
|
|
|
|
# write() error
|
|
f = open("data/file1", "r")
|
|
try:
|
|
f.write("x")
|
|
except OSError:
|
|
print("OSError")
|
|
f.close()
|
|
|
|
# read(n) error on binary file
|
|
f = open("data/file1", "ab")
|
|
try:
|
|
f.read(1)
|
|
except OSError:
|
|
print("OSError")
|
|
f.close()
|
|
|
|
# read(n) error on text file
|
|
f = open("data/file1", "at")
|
|
try:
|
|
f.read(1)
|
|
except OSError:
|
|
print("OSError")
|
|
f.close()
|
|
|
|
# read() w/o args error
|
|
f = open("data/file1", "ab")
|
|
try:
|
|
f.read()
|
|
except OSError:
|
|
print("OSError")
|
|
f.close()
|
|
|
|
# close() on a closed file
|
|
f.close()
|