Mercurial > treepkg > treepkg
comparison test/test_status.py @ 49:38d66dc6a1e5
merge
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Mon, 02 Apr 2007 20:48:25 +0200 |
parents | 3c5ab7a65384 |
children | 39b2deea8481 |
comparison
equal
deleted
inserted
replaced
48:aed3869ac04a | 49:38d66dc6a1e5 |
---|---|
3 # Bernhard Herzog <bh@intevation.de> | 3 # Bernhard Herzog <bh@intevation.de> |
4 # | 4 # |
5 # This program is free software under the GPL (>=v2) | 5 # This program is free software under the GPL (>=v2) |
6 # Read the file COPYING coming with the software for details. | 6 # Read the file COPYING coming with the software for details. |
7 | 7 |
8 """Tests for the Status class""" | 8 """Tests for the Status classes""" |
9 | 9 |
10 import os | 10 import os |
11 import unittest | 11 import unittest |
12 from datetime import datetime | 12 from datetime import datetime |
13 | 13 |
14 from treepkg.status import Status | 14 from treepkg.status import RevisionStatus, Status, EnumFieldDesc |
15 from treepkg.util import ensure_directory, writefile | 15 from treepkg.util import ensure_directory, writefile |
16 | 16 |
17 | 17 |
18 | 18 |
19 class TestStatus(unittest.TestCase): | 19 class TestStatus(unittest.TestCase): |
27 self.filename = self.tempfilename() | 27 self.filename = self.tempfilename() |
28 if os.path.exists(self.filename): | 28 if os.path.exists(self.filename): |
29 os.remove(self.filename) | 29 os.remove(self.filename) |
30 | 30 |
31 def test_status(self): | 31 def test_status(self): |
32 status = Status(self.filename) | 32 status = RevisionStatus(self.filename) |
33 status.status = "testing" | 33 status.error() |
34 | 34 |
35 otherstatus = Status(self.filename) | 35 otherstatus = RevisionStatus(self.filename) |
36 self.assertEquals(otherstatus.status, "testing") | 36 self.assertEquals(otherstatus.status.name, "error") |
37 | 37 |
38 def test_getting_unknown_fields(self): | 38 def test_getting_unknown_fields(self): |
39 status = Status(self.filename) | 39 status = RevisionStatus(self.filename) |
40 self.assertRaises(AttributeError, getattr, status, "unknown_field") | 40 self.assertRaises(AttributeError, getattr, status, "unknown_field") |
41 | 41 |
42 def test_setting_unknown_fields(self): | 42 def test_setting_unknown_fields(self): |
43 status = Status(self.filename) | 43 status = RevisionStatus(self.filename) |
44 self.assertRaises(AttributeError, | 44 self.assertRaises(AttributeError, |
45 setattr, status, "unknown_field", "some value") | 45 setattr, status, "unknown_field", "some value") |
46 | 46 |
47 def test_default_value(self): | 47 def test_default_values(self): |
48 status = Status(self.filename) | 48 status = RevisionStatus(self.filename) |
49 self.assertEquals(status.status.name, "unknown") | |
49 self.assertEquals(status.start, None) | 50 self.assertEquals(status.start, None) |
51 self.assertEquals(status.stop, None) | |
50 | 52 |
51 def test_date(self): | 53 def test_date(self): |
52 timestamp = datetime(2007, 3, 9, 17, 32, 55) | 54 timestamp = datetime(2007, 3, 9, 17, 32, 55) |
53 status = Status(self.filename) | 55 status = RevisionStatus(self.filename) |
54 status.start = timestamp | 56 status.start = timestamp |
55 | 57 |
56 otherstatus = Status(self.filename) | 58 otherstatus = RevisionStatus(self.filename) |
57 self.assertEquals(otherstatus.start, timestamp) | 59 self.assertEquals(otherstatus.start, timestamp) |
58 | 60 |
59 def test_magic(self): | 61 def test_magic(self): |
60 writefile(self.filename, | 62 writefile(self.filename, |
61 "Some other magic\nstart: 2007-03-09 17:32:55\n") | 63 "Some other magic\nstart: 2007-03-09 17:32:55\n") |
62 self.assertRaises(ValueError, Status, self.filename) | 64 self.assertRaises(ValueError, RevisionStatus, self.filename) |
65 | |
66 def test_status_enum(self): | |
67 | |
68 class TestStatus(Status): | |
69 status = EnumFieldDesc() | |
70 status.add("not_running", "Process is not running", | |
71 default=True) | |
72 status.add("running", "Process is running") | |
73 status.add("error", "An error occurred") | |
74 | |
75 status = TestStatus(self.filename) | |
76 status.running() | |
77 | |
78 otherstatus = TestStatus(self.filename) | |
79 self.assertEquals(otherstatus.status.name, "running") |