Mercurial > treepkg
comparison test/test_status.py @ 12:f9f15ee39ed7
New Status class that handles several fields
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 09 Mar 2007 18:23:09 +0100 |
parents | |
children | b1235080e694 |
comparison
equal
deleted
inserted
replaced
11:6efe0bd3d8c1 | 12:f9f15ee39ed7 |
---|---|
1 # Copyright (C) 2007 by Intevation GmbH | |
2 # Authors: | |
3 # Bernhard Herzog <bh@intevation.de> | |
4 # | |
5 # This program is free software under the GPL (>=v2) | |
6 # Read the file COPYING coming with the software for details. | |
7 | |
8 """Tests for the Status class""" | |
9 | |
10 import os | |
11 import unittest | |
12 from datetime import datetime | |
13 | |
14 from treepkg.status import Status | |
15 from treepkg.util import ensure_directory, writefile | |
16 | |
17 | |
18 | |
19 class TestStatus(unittest.TestCase): | |
20 | |
21 def tempfilename(self): | |
22 tempdir = os.path.join(os.path.dirname(__file__), "temp") | |
23 ensure_directory(tempdir) | |
24 return os.path.join(tempdir, self.id()) | |
25 | |
26 def setUp(self): | |
27 self.filename = self.tempfilename() | |
28 if os.path.exists(self.filename): | |
29 os.remove(self.filename) | |
30 | |
31 def test_status(self): | |
32 status = Status(self.filename) | |
33 status.status = "testing" | |
34 | |
35 otherstatus = Status(self.filename) | |
36 self.assertEquals(otherstatus.status, "testing") | |
37 | |
38 def test_getting_unknown_fields(self): | |
39 status = Status(self.filename) | |
40 self.assertRaises(AttributeError, getattr, status, "unknown_field") | |
41 | |
42 def test_setting_unknown_fields(self): | |
43 status = Status(self.filename) | |
44 self.assertRaises(AttributeError, | |
45 setattr, status, "unknown_field", "some value") | |
46 | |
47 def test_default_value(self): | |
48 status = Status(self.filename) | |
49 self.assertEquals(status.start, None) | |
50 | |
51 def test_date(self): | |
52 timestamp = datetime(2007, 3, 9, 17, 32, 55) | |
53 status = Status(self.filename) | |
54 status.start = timestamp | |
55 | |
56 otherstatus = Status(self.filename) | |
57 self.assertEquals(otherstatus.start, timestamp) | |
58 | |
59 def test_magic(self): | |
60 writefile(self.filename, | |
61 "Some other magic\nstart: 2007-03-09 17:32:55\n") | |
62 self.assertRaises(ValueError, Status, self.filename) |