-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupDemo.py
More file actions
37 lines (31 loc) · 977 Bytes
/
setupDemo.py
File metadata and controls
37 lines (31 loc) · 977 Bytes
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
"""
Demonstration of setUp and tearDown.
The tests do not actually test anything -- this is a demo.
"""
import unittest
import tempfile
import shutil
import glob
import os
class FileTest(unittest.TestCase):
def setUp(self):
self.origdir = os.getcwd()
self.dirname = tempfile.mkdtemp("testdir")
print("Created", self.dirname)
os.chdir(self.dirname)
def test_1(self):
"Verify creation of files is possible"
for filename in ("this.txt", "that.txt", "the_other.txt"):
f = open(filename, "w")
f.write("Some text\n")
f.close()
self.assertTrue(f.closed)
def test_2(self):
"Verify that the current directory is empty"
self.assertEqual(glob.glob("*"), [], "Directory not empty")
def tearDown(self):
os.chdir(self.origdir)
shutil.rmtree(self.dirname)
print("Deleted", self.dirname)
if __name__ == "__main__":
unittest.main()