-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathtest.py
More file actions
110 lines (93 loc) · 3.51 KB
/
test.py
File metadata and controls
110 lines (93 loc) · 3.51 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2022 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import tempfile
import os
print("test tempfile")
if not tempfile.tempdir is None:
print("tempfile.tempdir is not None: %s" % (tempfile.tempdir,))
else:
print("tempfile.tempdir is None [OK]")
v = tempfile.gettempdir()
if type(v) != type(""):
print("tempfile.gettempdir() returned %s (type=%s)" % (v, type(v)))
v = tempfile.gettempdirb()
if type(v) != type(b""):
print("tempfile.gettempdirb() returned %s (type=%s)" % (v, type(v)))
## mkdtemp
try:
tmp = tempfile.mkdtemp()
os.rmdir(tmp)
print("mkdtemp() [OK]")
except Exception as e:
print("could not create tmp dir w/ mkdtemp(): %s" % e)
try:
tmp = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix")
os.rmdir(tmp)
print("mkdtemp(prefix='prefix-', suffix='-suffix') [OK]")
except Exception as e:
print("could not create tmp dir w/ mkdtemp(prefix='prefix-', suffix='-suffix'): %s" % e)
try:
top = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix")
tmp = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix", dir=top)
os.rmdir(tmp)
os.rmdir(top)
print("mkdtemp(prefix='prefix-', suffix='-suffix', dir=top) [OK]")
except Exception as e:
print("could not create tmp dir w/ mkdtemp(prefix='prefix-', suffix='-suffix', dir=top): %s" % e)
try:
top = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix")
tmp = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix", dir=top)
os.removedirs(top)
print("mkdtemp(prefix='prefix-', suffix='-suffix', dir=top) [OK]")
except Exception as e:
print("could not create tmp dir w/ mkdtemp(prefix='prefix-', suffix='-suffix', dir=top): %s" % e)
try:
tmp = tempfile.mkdtemp(prefix=b"prefix-", suffix="-suffix")
print("missing exception!")
os.rmdir(tmp)
except TypeError as e:
print("caught: %s [OK]" % e)
except Exception as e:
print("INVALID error caught: %s" % e)
def remove(fd, name):
os.close(fd)
os.remove(name)
## mkstemp
try:
fd, tmp = tempfile.mkstemp()
remove(fd, tmp)
print("mkstemp() [OK]")
except Exception as e:
print("could not create tmp dir w/ mkstemp(): %s" % e)
try:
fd, tmp = tempfile.mkstemp(prefix="prefix-", suffix="-suffix")
remove(fd, tmp)
print("mkstemp(prefix='prefix-', suffix='-suffix') [OK]")
except Exception as e:
print("could not create tmp dir w/ mkstemp(prefix='prefix-', suffix='-suffix'): %s" % e)
try:
top = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix")
fd, tmp = tempfile.mkstemp(prefix="prefix-", suffix="-suffix", dir=top)
remove(fd, tmp)
os.remove(top)
print("mkstemp(prefix='prefix-', suffix='-suffix', dir=top) [OK]")
except Exception as e:
print("could not create tmp dir w/ mkstemp(prefix='prefix-', suffix='-suffix', dir=top): %s" % e)
try:
top = tempfile.mkdtemp(prefix="prefix-", suffix="-suffix")
fd, tmp = tempfile.mkstemp(prefix="prefix-", suffix="-suffix", dir=top)
os.fdopen(fd).close() ## needed on Windows.
os.removedirs(top)
print("mkstemp(prefix='prefix-', suffix='-suffix', dir=top) [OK]")
except Exception as e:
print("could not create tmp dir w/ mkstemp(prefix='prefix-', suffix='-suffix', dir=top): %s" % e)
try:
fd, tmp = tempfile.mkstemp(prefix=b"prefix-", suffix="-suffix")
print("missing exception!")
remove(fd, tmp)
except TypeError as e:
print("caught: %s [OK]" % e)
except Exception as e:
print("INVALID error caught: %s" % e)
print("OK")