-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_CachedFile.py
More file actions
44 lines (34 loc) · 1.3 KB
/
Copy pathtest_CachedFile.py
File metadata and controls
44 lines (34 loc) · 1.3 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
from unittest import TestCase
from docker_compose_templer.template import CachedFile
class TestFile(TestCase):
def test_exists(self):
self.assertTrue(CachedFile('./vars/vars1.yml').exists())
self.assertFalse(CachedFile('./foo').exists())
def test_read(self):
fp = './files/read.txt'
f = CachedFile(fp)
fcontent = 'foobar'
self.assertEqual(f.read(), fcontent)
self.assertEqual(f.cache['content'], fcontent)
# read cached content
self.assertEqual(f.read(), fcontent)
# file does not exist
self.assertRaises(FileNotFoundError, CachedFile('./foo').read)
# not a file
self.assertRaises(IOError, CachedFile('./vars').read)
def test_write(self):
# path is not a file
self.assertRaises(OSError, CachedFile.write, '', './vars', False)
# file already exists
self.assertRaises(OSError, CachedFile.write, '', './files/read.txt', False)
# write
fp = './files/write.txt'
import os
if os.path.exists(fp):
os.remove(fp)
write_content = 'foo'
CachedFile.write(write_content, fp, False)
with open(fp, 'r') as f:
self.assertEqual(f.read(), write_content)
if os.path.exists(fp):
os.remove(fp)