/
test.py
66 lines (46 loc) · 1.9 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
#!/usr/bin/python
import unittest
import os
import os.path as path
from checkpoint import Checkpoint
class TestCheckpoint(unittest.TestCase):
TEST_DIR = "/tmp/checkpoint_test"
TEST_KEY = "test_key"
TEST_KEY2 = "test_key2"
def setUp(self):
os.mkdir(TestCheckpoint.TEST_DIR)
def tearDown(self):
os.system("rm -rf " + TestCheckpoint.TEST_DIR)
def testCreation(self):
x = Checkpoint(TestCheckpoint.TEST_DIR)
self.assertTrue(path.exists(TestCheckpoint.TEST_DIR + "/.checkpoint"))
def testCheckLogCreation(self):
x = Checkpoint(TestCheckpoint.TEST_DIR)
x.createCheckpointLog(TestCheckpoint.TEST_KEY)
self.assertTrue(TestCheckpoint.TEST_KEY in x.getCheckpointLogKeys())
x.releaseCheckpointLog(TestCheckpoint.TEST_KEY)
self.assertFalse(TestCheckpoint.TEST_KEY in x.getCheckpointLogKeys())
def testCheckpointWrite(self):
x = Checkpoint(TestCheckpoint.TEST_DIR)
x.createCheckpointLog(TestCheckpoint.TEST_KEY)
x.writeCheckpoint(TestCheckpoint.TEST_KEY, "a", 1)
x.writeCheckpoint(TestCheckpoint.TEST_KEY, "a", 2)
x.writeCheckpoint(TestCheckpoint.TEST_KEY, "b", 3)
x.releaseCheckpointLog(TestCheckpoint.TEST_KEY)
self.assertEqual(sorted(x.getCheckpointKeys()), ["a", "b"])
self.assertEqual(x.getCheckpoints("b"), [3])
self.assertEqual(x.getCheckpoints("a"), [1, 2])
def testCheckpointRestart(self):
x = Checkpoint(TestCheckpoint.TEST_DIR)
x.createCheckpointLog(TestCheckpoint.TEST_KEY)
x.createCheckpointLog(TestCheckpoint.TEST_KEY2)
x.writeCheckpoint(TestCheckpoint.TEST_KEY, "a", 1)
x.writeCheckpoint(TestCheckpoint.TEST_KEY, "a", 2)
x.writeCheckpoint(TestCheckpoint.TEST_KEY2, "b", 3)
x.releaseCheckpointLog(TestCheckpoint.TEST_KEY)
x.releaseCheckpointLog(TestCheckpoint.TEST_KEY2)
y = Checkpoint(TestCheckpoint.TEST_DIR)
self.assertEqual(y.getCheckpoints("b"), [3])
self.assertEqual(y.getCheckpoints("a"), [1, 2])
if __name__ == "__main__":
unittest.main()