summaryrefslogtreecommitdiff
path: root/tests/extmod/vfs_posix.py
blob: aea447e182e075a680456c351e0059e2c08a52ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Test for VfsPosix

try:
    import uos

    uos.VfsPosix
except (ImportError, AttributeError):
    print("SKIP")
    raise SystemExit

# We need a file for testing that doesn't already exist.
# Skip the test if it does exist.
temp_file = "micropy_test_file.txt"
try:
    uos.stat(temp_file)
    print("SKIP")
    raise SystemExit
except OSError:
    pass

# getcwd and chdir
curdir = uos.getcwd()
uos.chdir("/")
print(uos.getcwd())
uos.chdir(curdir)
print(uos.getcwd() == curdir)

# stat
print(type(uos.stat("/")))

# listdir and ilistdir
print(type(uos.listdir("/")))

# file create
f = open(temp_file, "w")
f.write("hello")
f.close()

# close on a closed file should succeed
f.close()

# file read
f = open(temp_file, "r")
print(f.read())
f.close()

# remove
uos.remove(temp_file)