diff options
| author | Christian Walther <cwalther@gmx.ch> | 2023-07-30 17:26:04 +0200 |
|---|---|---|
| committer | Christian Walther <cwalther@gmx.ch> | 2023-10-19 16:21:08 +0200 |
| commit | 5f7065f57a1ce445266a566685ad451edecc58c3 (patch) | |
| tree | eb954d8f743f44c7ea158d8bdef0ba90a09bffac | |
| parent | e3ba6f952bda153cfc3389eb48c7645d71b2b094 (diff) | |
extmod/vfs_posix: Fix accidentally passing tests.
These tests test an unrealistic situation and only pass by accident due
to a bug. The upcoming fix for the bug would make them fail.
The unrealistic situation is that VfsPosix methods are called with
relative paths while the current working directory is somewhere outside
of the root of the VFS. In the intended use of VFS objects via
os.mount() (as opposed to calling methods directly as the tests do),
this never happens, as mp_vfs_lookup_path() directs incoming calls to
the VFS that contains the CWD.
Make the testing situation realistic by changing the working directory
to the root of the VFS before calling methods on it, as the subsequent
relative path accesses expect.
Thanks to the preceding commit, the tests still pass, but still for the
wrong reason. The following commit "Fix relative paths on non-root VFS"
will make them pass for the correct reason.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
| -rw-r--r-- | tests/extmod/vfs_posix.py | 6 | ||||
| -rw-r--r-- | tests/extmod/vfs_posix_ilistdir_del.py | 9 | ||||
| -rw-r--r-- | tests/extmod/vfs_posix_ilistdir_filter.py | 7 |
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/extmod/vfs_posix.py b/tests/extmod/vfs_posix.py index ebbd08a4a..bc4c7c201 100644 --- a/tests/extmod/vfs_posix.py +++ b/tests/extmod/vfs_posix.py @@ -88,6 +88,9 @@ print(os.listdir(temp_dir)) # construct new VfsPosix with path argument vfs = os.VfsPosix(temp_dir) +# when VfsPosix is used the intended way via os.mount(), it can only be called +# with relative paths when the CWD is inside or at its root, so simulate that +os.chdir(temp_dir) print(list(i[0] for i in vfs.ilistdir("."))) # stat, statvfs (statvfs may not exist) @@ -112,6 +115,9 @@ vfs.remove("/subdir/micropy_test_dir/test2") vfs.rmdir("/subdir/micropy_test_dir") vfs.rmdir("/subdir") +# done with vfs, restore CWD +os.chdir(curdir) + # remove os.remove(temp_dir + "/test2") print(os.listdir(temp_dir)) diff --git a/tests/extmod/vfs_posix_ilistdir_del.py b/tests/extmod/vfs_posix_ilistdir_del.py index edb50dfd6..8c8e6978b 100644 --- a/tests/extmod/vfs_posix_ilistdir_del.py +++ b/tests/extmod/vfs_posix_ilistdir_del.py @@ -11,7 +11,13 @@ except (ImportError, AttributeError): def test(testdir): + curdir = os.getcwd() vfs = os.VfsPosix(testdir) + # When VfsPosix is used the intended way via os.mount(), it can only be called + # with relative paths when the CWD is inside or at its root, so simulate that. + # (Although perhaps calling with a relative path was an oversight in this case + # and the respective line below was meant to read `vfs.rmdir("/" + dname)`.) + os.chdir(testdir) vfs.mkdir("/test_d1") vfs.mkdir("/test_d2") vfs.mkdir("/test_d3") @@ -48,6 +54,9 @@ def test(testdir): vfs.open("/test", "w").close() vfs.remove("/test") + # Done with vfs, restore CWD. + os.chdir(curdir) + # We need an empty directory for testing. # Skip the test if it already exists. diff --git a/tests/extmod/vfs_posix_ilistdir_filter.py b/tests/extmod/vfs_posix_ilistdir_filter.py index c32d12497..540127460 100644 --- a/tests/extmod/vfs_posix_ilistdir_filter.py +++ b/tests/extmod/vfs_posix_ilistdir_filter.py @@ -10,7 +10,11 @@ except (ImportError, AttributeError): def test(testdir): + curdir = os.getcwd() vfs = os.VfsPosix(testdir) + # When VfsPosix is used the intended way via os.mount(), it can only be called + # with relative paths when the CWD is inside or at its root, so simulate that. + os.chdir(testdir) dirs = [".a", "..a", "...a", "a.b", "a..b"] @@ -24,6 +28,9 @@ def test(testdir): print(dirs) + # Done with vfs, restore CWD. + os.chdir(curdir) + # We need an empty directory for testing. # Skip the test if it already exists. |
