Mercurial > treepkg
annotate test/test_status.py @ 32:b1235080e694
add more tests for status defaults
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 15 Mar 2007 11:48:13 +0100 |
parents | f9f15ee39ed7 |
children | 086c68ca51d2 |
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 |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
8 """Tests for the Status class""" |
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 |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
14 from treepkg.status import Status |
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): |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
32 status = Status(self.filename) |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
33 status.status = "testing" |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
34 |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
35 otherstatus = Status(self.filename) |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
36 self.assertEquals(otherstatus.status, "testing") |
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): |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
39 status = Status(self.filename) |
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): |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
43 status = Status(self.filename) |
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): |
12
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
48 status = Status(self.filename) |
32
b1235080e694
add more tests for status defaults
Bernhard Herzog <bh@intevation.de>
parents:
12
diff
changeset
|
49 self.assertEquals(status.status, "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) |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
55 status = Status(self.filename) |
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 |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
58 otherstatus = Status(self.filename) |
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") |
f9f15ee39ed7
New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
64 self.assertRaises(ValueError, Status, self.filename) |