1try:
2    import uos as os
3except ImportError:
4    import os
5
6if not hasattr(os, "remove"):
7    print("SKIP")
8    raise SystemExit
9
10# cleanup in case testfile exists
11try:
12    os.remove("testfile")
13except OSError:
14    pass
15
16try:
17    f = open("testfile", "r+b")
18    print("Unexpectedly opened non-existing file")
19except OSError:
20    print("Expected OSError")
21    pass
22
23f = open("testfile", "w+b")
24f.write(b"1234567890")
25f.seek(0)
26print(f.read())
27f.close()
28
29# Open with truncation
30f = open("testfile", "w+b")
31f.write(b"abcdefg")
32f.seek(0)
33print(f.read())
34f.close()
35
36# Open without truncation
37f = open("testfile", "r+b")
38f.write(b"1234")
39f.seek(0)
40print(f.read())
41f.close()
42
43# cleanup
44try:
45    os.remove("testfile")
46except OSError:
47    pass
48