-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtest_tempfile.py
More file actions
50 lines (40 loc) · 1.33 KB
/
test_tempfile.py
File metadata and controls
50 lines (40 loc) · 1.33 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
import os
import tempfile
import unittest
class Base(unittest.TestCase):
def assertExists(self, fn):
os.stat(fn)
def assertNotExists(self, fn):
with self.assertRaises(OSError):
os.stat(fn)
class TestMkdtemp(Base):
def test_no_args(self):
fn = tempfile.mkdtemp()
self.assertTrue(fn.startswith("/tmp"))
self.assertExists(fn)
os.rmdir(fn)
def test_prefix(self):
fn = tempfile.mkdtemp(prefix="foo")
self.assertTrue(fn.startswith("/tmp"))
self.assertTrue("foo" in fn)
self.assertFalse(fn.endswith("foo"))
self.assertExists(fn)
os.rmdir(fn)
def test_suffix(self):
fn = tempfile.mkdtemp(suffix="foo")
self.assertTrue(fn.startswith("/tmp"))
self.assertTrue(fn.endswith("foo"))
self.assertExists(fn)
os.rmdir(fn)
def test_dir(self):
fn = tempfile.mkdtemp(dir="tmp_micropython")
self.assertTrue(fn.startswith("tmp_micropython"))
self.assertExists(fn)
os.rmdir(fn)
class TestTemporaryDirectory(Base):
def test_context_manager_no_args(self):
with tempfile.TemporaryDirectory() as fn:
self.assertTrue(isinstance(fn, str))
self.assertTrue(fn.startswith("/tmp"))
self.assertExists(fn)
self.assertNotExists(fn)