annotate test/test_status.py @ 185:e1c7cd896310

Rework test/filesupport.py so that test cases always use their own temporary directory. Before, the test cases had to ensure this themselves. Adapt the test cases.
author Bernhard Herzog <bh@intevation.de>
date Thu, 26 Jun 2008 16:23:26 +0000
parents 39b2deea8481
children b19bf5895a55
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
58
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
11 import stat
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
12 import unittest
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
13 from datetime import datetime
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
14
40
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
15 from treepkg.status import RevisionStatus, Status, EnumFieldDesc
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16 from treepkg.util import ensure_directory, writefile
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
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20 class TestStatus(unittest.TestCase):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
21
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
22 def tempfilename(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
23 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
24 ensure_directory(tempdir)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
25 return os.path.join(tempdir, self.id())
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
26
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
27 def setUp(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
28 self.filename = self.tempfilename()
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
29 if os.path.exists(self.filename):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
30 os.remove(self.filename)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
31
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
32 def test_status(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
33 status = RevisionStatus(self.filename)
43
3c5ab7a65384 adapt status test cases to the enum fields
Bernhard Herzog <bh@intevation.de>
parents: 40
diff changeset
34 status.error()
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
35
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
36 otherstatus = RevisionStatus(self.filename)
43
3c5ab7a65384 adapt status test cases to the enum fields
Bernhard Herzog <bh@intevation.de>
parents: 40
diff changeset
37 self.assertEquals(otherstatus.status.name, "error")
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
38
58
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
39 def test_status_file_permissions(self):
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
40 status = RevisionStatus(self.filename)
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
41 status.error()
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
42
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
43 mode = os.stat(self.filename).st_mode
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
44 self.assertEquals(stat.S_IMODE(mode) & 0444, 0444)
39b2deea8481 make the status files are world readable
Bernhard Herzog <bh@intevation.de>
parents: 43
diff changeset
45
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
46 def test_getting_unknown_fields(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
47 status = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
48 self.assertRaises(AttributeError, getattr, status, "unknown_field")
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
49
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
50 def test_setting_unknown_fields(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
51 status = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
52 self.assertRaises(AttributeError,
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
53 setattr, status, "unknown_field", "some value")
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
54
32
b1235080e694 add more tests for status defaults
Bernhard Herzog <bh@intevation.de>
parents: 12
diff changeset
55 def test_default_values(self):
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
56 status = RevisionStatus(self.filename)
43
3c5ab7a65384 adapt status test cases to the enum fields
Bernhard Herzog <bh@intevation.de>
parents: 40
diff changeset
57 self.assertEquals(status.status.name, "unknown")
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
58 self.assertEquals(status.start, None)
32
b1235080e694 add more tests for status defaults
Bernhard Herzog <bh@intevation.de>
parents: 12
diff changeset
59 self.assertEquals(status.stop, None)
12
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_date(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
62 timestamp = datetime(2007, 3, 9, 17, 32, 55)
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
63 status = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
64 status.start = timestamp
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
65
36
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 32
diff changeset
66 otherstatus = RevisionStatus(self.filename)
12
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
67 self.assertEquals(otherstatus.start, timestamp)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
68
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
69 def test_magic(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70 writefile(self.filename,
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
71 "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
72 self.assertRaises(ValueError, RevisionStatus, self.filename)
40
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
73
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
74 def test_status_enum(self):
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
75
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
76 class TestStatus(Status):
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
77 status = EnumFieldDesc()
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
78 status.add("not_running", "Process is not running",
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
79 default=True)
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
80 status.add("running", "Process is running")
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
81 status.add("error", "An error occurred")
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
82
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
83 status = TestStatus(self.filename)
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
84 status.running()
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
85
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
86 otherstatus = TestStatus(self.filename)
c544903eeced Add real enums for status information
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
87 self.assertEquals(otherstatus.status.name, "running")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)