forked from mjgiarlo/namaste
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
89 lines (76 loc) · 3.34 KB
/
test.py
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
import os
import shutil
import unittest
import namaste
TESTDIR = 'namaste-test'
class NamasteTests(unittest.TestCase):
def setUp(self):
if os.path.isdir(TESTDIR):
shutil.rmtree(TESTDIR)
shutil.copytree('docs', TESTDIR)
def tearDown(self):
if os.path.isdir(TESTDIR):
shutil.rmtree(TESTDIR)
def test_type(self):
self.assertFalse(os.path.isfile(os.path.join(TESTDIR, '0=bagit_0.1')))
namaste.dirtype(TESTDIR, 'bagit_0.1')
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, '0=bagit_0.1')))
f = open(os.path.join(TESTDIR, '0=bagit_0.1'))
self.assertEqual(f.read(), "bagit_0.1\n")
f.close()
def test_who(self):
self.assertFalse(os.path.isfile(os.path.join(TESTDIR, '1=Twain,M.')))
namaste.who(TESTDIR, "Twain,M.")
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, '1=Twain,M.')))
f = open(os.path.join(TESTDIR, '1=Twain,M.'))
self.assertEqual(f.read(), "Twain,M.\n")
f.close()
def test_what(self):
self.assertFalse(os.path.isfile(os.path.join(TESTDIR, '2=Hamlet')))
namaste.what(TESTDIR, "Hamlet")
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, '2=Hamlet')))
f = open(os.path.join(TESTDIR, '2=Hamlet'))
self.assertEqual(f.read(),"Hamlet\n")
f.close()
def test_when(self):
self.assertFalse(os.path.isfile(os.path.join(TESTDIR, '3=2005')))
namaste.when(TESTDIR, "2005")
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, '3=2005')))
f = open(os.path.join(TESTDIR, '3=2005'))
self.assertEqual(f.read(), "2005\n")
f.close()
def test_where(self):
self.assertFalse(os.path.isfile(os.path.join(TESTDIR, '4=Seattle')))
namaste.where(TESTDIR, "Seattle")
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, '4=Seattle')))
f = open(os.path.join(TESTDIR, '4=Seattle'))
self.assertEqual(f.read(), "Seattle\n")
f.close()
def test_get(self):
namaste.dirtype(TESTDIR, 'bagit_0.1')
namaste.who(TESTDIR, "Twain,M.")
namaste.what(TESTDIR, "Hamlet")
namaste.when(TESTDIR, "2005")
namaste.where(TESTDIR, "Seattle")
tags = namaste.get(TESTDIR)
tags.sort()
self.assertEqual(tags, [
os.path.join(TESTDIR, namaste._make_namaste(0, 'bagit_0.1')),
os.path.join(TESTDIR, namaste._make_namaste(1, 'Twain,M.')),
os.path.join(TESTDIR, namaste._make_namaste(2, 'Hamlet')),
os.path.join(TESTDIR, namaste._make_namaste(3, '2005')),
os.path.join(TESTDIR, namaste._make_namaste(4, 'Seattle')),
])
def test_gettypes(self):
namaste.dirtype(TESTDIR, 'bagit_2323.1')
namaste.dirtype(TESTDIR, 'redd_0.1333')
namaste.dirtype(TESTDIR, 'dflat_34.22')
types = namaste.get_types(TESTDIR)
self.assertTrue('bagit' in types)
self.assertTrue('redd' in types)
self.assertTrue('dflat' in types)
self.assertEqual(types['bagit'], {'name':'bagit', 'major':'2323', 'minor':'1'})
self.assertEqual(types['redd'], {'name':'redd', 'major':'0', 'minor':'1333'})
self.assertEqual(types['dflat'], {'name':'dflat', 'major':'34', 'minor':'22'})
if __name__ == "__main__":
unittest.main()