annotate test/test_status.py @ 50:225206553bba

update README part about pbuilder config
author Bernhard Herzog <bh@intevation.de>
date Tue, 03 Apr 2007 11:24:48 +0200
parents 3c5ab7a65384
children 39b2deea8481
rev   line source
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2007 by Intevation GmbH
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
8 """Tests for the Status classes"""
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
10 import os
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
11 import unittest
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
12 from datetime import datetime
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
13
40
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
14 from treepkg.status import RevisionStatus, Status, EnumFieldDesc
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
15 from treepkg.util import ensure_directory, writefile
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
18
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
19 class TestStatus(unittest.TestCase):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
21 def tempfilename(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
22 tempdir = os.path.join(os.path.dirname(__file__), "temp")
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
23 ensure_directory(tempdir)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
24 return os.path.join(tempdir, self.id())
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
25
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
26 def setUp(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
27 self.filename = self.tempfilename()
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
28 if os.path.exists(self.filename):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
29 os.remove(self.filename)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
30
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
31 def test_status(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
32 status = RevisionStatus(self.filename)
43
3c5ab7a65384 adapt status test cases to the enum fields
Bernhard Herzog <bh@intevation.de>
parents: 40
diff changeset
33 status.error()
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
34
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
35 otherstatus = RevisionStatus(self.filename)
43
3c5ab7a65384 adapt status test cases to the enum fields
Bernhard Herzog <bh@intevation.de>
parents: 40
diff changeset
36 self.assertEquals(otherstatus.status.name, "error")
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
37
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
38 def test_getting_unknown_fields(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
39 status = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
40 self.assertRaises(AttributeError, getattr, status, "unknown_field")
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
41
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
42 def test_setting_unknown_fields(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
43 status = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
44 self.assertRaises(AttributeError,
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
45 setattr, status, "unknown_field", "some value")
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
46
32
b1235080e694 add more tests for status defaults
Bernhard Herzog <bh@intevation.de>
parents: 12
diff changeset
47 def test_default_values(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
48 status = RevisionStatus(self.filename)
43
3c5ab7a65384 adapt status test cases to the enum fields
Bernhard Herzog <bh@intevation.de>
parents: 40
diff changeset
49 self.assertEquals(status.status.name, "unknown")
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
50 self.assertEquals(status.start, None)
32
b1235080e694 add more tests for status defaults
Bernhard Herzog <bh@intevation.de>
parents: 12
diff changeset
51 self.assertEquals(status.stop, None)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
52
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
53 def test_date(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
54 timestamp = datetime(2007, 3, 9, 17, 32, 55)
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
55 status = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
56 status.start = timestamp
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
57
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
58 otherstatus = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59 self.assertEquals(otherstatus.start, timestamp)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
60
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
61 def test_magic(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
62 writefile(self.filename,
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
63 "Some other magic\nstart: 2007-03-09 17:32:55\n")
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
64 self.assertRaises(ValueError, RevisionStatus, self.filename)
40
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
65
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
66 def test_status_enum(self):
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
67
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
68 class TestStatus(Status):
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
69 status = EnumFieldDesc()
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
70 status.add("not_running", "Process is not running",
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
71 default=True)
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
72 status.add("running", "Process is running")
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
73 status.add("error", "An error occurred")
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
74
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
75 status = TestStatus(self.filename)
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
76 status.running()
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
77
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
78 otherstatus = TestStatus(self.filename)
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
79 self.assertEquals(otherstatus.status.name, "running")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)