annotate test/test_status.py @ 16:7c55f3879c4d

Use the new status class and report start/stop time too
author Bernhard Herzog <bh@intevation.de>
date Fri, 09 Mar 2007 19:39:13 +0100
parents f9f15ee39ed7
children b1235080e694
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
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
47 def test_default_value(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
48 status = Status(self.filename)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
49 self.assertEquals(status.start, None)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
50
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
51 def test_date(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
52 timestamp = datetime(2007, 3, 9, 17, 32, 55)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
53 status = Status(self.filename)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
54 status.start = timestamp
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
55
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
56 otherstatus = Status(self.filename)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
57 self.assertEquals(otherstatus.start, timestamp)
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
58
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59 def test_magic(self):
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
60 writefile(self.filename,
f9f15ee39ed7 New Status class that handles several fields
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
61 "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
62 self.assertRaises(ValueError, Status, self.filename)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)