blob: 707819727b736bfa91436d9ac12a850f23cb9bb2 [file] [log] [blame]
Mark Hammondef8b6542001-05-13 08:04:26 +00001# Test some Unicode file name semantics
2# We dont test many operations on files other than
3# that their names can be used with Unicode characters.
4import os
5
6from test_support import verify, TestSkipped, TESTFN_UNICODE
7try:
8 from test_support import TESTFN_ENCODING
9except ImportError:
10 raise TestSkipped("No Unicode filesystem semantics on this platform.")
11
12TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING)
13
14# Check with creation as Unicode string.
15f = open(TESTFN_UNICODE, 'wb')
16if not os.path.isfile(TESTFN_UNICODE):
17 print "File doesn't exist after creating it"
18
19if not os.path.isfile(TESTFN_ENCODED):
20 print "File doesn't exist (encoded string) after creating it"
21
22f.close()
23
24# Test stat and chmod
25if os.stat(TESTFN_ENCODED) != os.stat(TESTFN_UNICODE):
26 print "os.stat() did not agree on the 2 filenames"
27os.chmod(TESTFN_ENCODED, 0777)
28os.chmod(TESTFN_UNICODE, 0777)
29
30# Test rename
31os.rename(TESTFN_ENCODED, TESTFN_ENCODED + ".new")
32os.rename(TESTFN_UNICODE+".new", TESTFN_ENCODED)
33
34os.unlink(TESTFN_ENCODED)
35if os.path.isfile(TESTFN_ENCODED) or \
36 os.path.isfile(TESTFN_UNICODE):
37 print "File exists after deleting it"
38
39# Check with creation as encoded string.
40f = open(TESTFN_ENCODED, 'wb')
41if not os.path.isfile(TESTFN_UNICODE) or \
42 not os.path.isfile(TESTFN_ENCODED):
43 print "File doesn't exist after creating it"
44
45path, base = os.path.split(os.path.abspath(TESTFN_ENCODED))
46if base not in os.listdir(path):
47 print "Filename did not appear in os.listdir()"
48
49f.close()
50os.unlink(TESTFN_UNICODE)
51if os.path.isfile(TESTFN_ENCODED) or \
52 os.path.isfile(TESTFN_UNICODE):
53 print "File exists after deleting it"
54
55# test os.open
56f = os.open(TESTFN_ENCODED, os.O_CREAT)
57if not os.path.isfile(TESTFN_UNICODE) or \
58 not os.path.isfile(TESTFN_ENCODED):
59 print "File doesn't exist after creating it"
60os.close(f)
61os.unlink(TESTFN_UNICODE)
62
63# Test directories etc
64cwd = os.getcwd()
65abs_encoded = os.path.abspath(TESTFN_ENCODED) + ".dir"
66abs_unicode = os.path.abspath(TESTFN_UNICODE) + ".dir"
67os.mkdir(abs_encoded)
68try:
69 os.chdir(abs_encoded)
70 os.chdir(abs_unicode)
71finally:
72 os.chdir(cwd)
73 os.rmdir(abs_unicode)
74os.mkdir(abs_unicode)
75try:
76 os.chdir(abs_encoded)
77 os.chdir(abs_unicode)
78finally:
79 os.chdir(cwd)
80 os.rmdir(abs_encoded)
81print "All the Unicode tests appeared to work"