comparison test/test_status.py @ 250:b3f9cc956acc

Make the Status class usable without a filename and provide methods to (de-)serialize to and from memory to make writing tests easier.
author Bernhard Herzog <bh@intevation.de>
date Thu, 09 Apr 2009 18:20:04 +0000
parents b19bf5895a55
children 27824d3add92
comparison
equal deleted inserted replaced
249:a3f106580525 250:b3f9cc956acc
1 # Copyright (C) 2007, 2008 by Intevation GmbH 1 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
2 # Authors: 2 # Authors:
3 # Bernhard Herzog <bh@intevation.de> 3 # Bernhard Herzog <bh@intevation.de>
4 # 4 #
5 # This program is free software under the GPL (>=v2) 5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details. 6 # Read the file COPYING coming with the software for details.
10 import os 10 import os
11 import stat 11 import stat
12 import unittest 12 import unittest
13 from datetime import datetime 13 from datetime import datetime
14 14
15 from treepkg.status import RevisionStatus, Status, EnumFieldDesc 15 from treepkg.status import RevisionStatus, Status, EnumFieldDesc, \
16 from treepkg.util import ensure_directory, writefile 16 StringFieldDesc, DateFieldDesc
17 from treepkg.util import writefile
17 18
18 from filesupport import FileTestMixin 19 from filesupport import FileTestMixin
19 20
20 21
21 22
80 status = TestStatus(self.filename) 81 status = TestStatus(self.filename)
81 status.running() 82 status.running()
82 83
83 otherstatus = TestStatus(self.filename) 84 otherstatus = TestStatus(self.filename)
84 self.assertEquals(otherstatus.status.name, "running") 85 self.assertEquals(otherstatus.status.name, "running")
86
87 def test_serialize(self):
88 class TestStatus(Status):
89 _magic = "TestStatus 1.0\n"
90
91 status = EnumFieldDesc()
92 status.add("not_running", "Process is not running",
93 default=True)
94 status.add("running", "Process is running")
95 status.add("error", "An error occurred")
96
97 start = DateFieldDesc(default=None)
98
99 name = StringFieldDesc(default="fred")
100
101 status = TestStatus(None)
102 status.running()
103 status.start = datetime(2007, 3, 9, 17, 32, 55)
104 status.name = "Dave"
105
106 self.assertEquals(sorted(status.serialize()),
107 ["TestStatus 1.0\n",
108 "name: Dave\n",
109 "start: 2007-03-09 17:32:55\n",
110 "status: running\n"])
111
112 def test_deserialize(self):
113 class TestStatus(Status):
114 _magic = "TestStatus 1.0\n"
115
116 status = EnumFieldDesc()
117 status.add("not_running", "Process is not running",
118 default=True)
119 status.add("running", "Process is running")
120 status.add("error", "An error occurred")
121
122 start = DateFieldDesc(default=None)
123
124 name = StringFieldDesc(default="fred")
125
126 status = TestStatus(None)
127 status.deserialize(iter(["TestStatus 1.0\n",
128 "name: Dave\n",
129 "start: 2007-03-09 17:32:55\n",
130 "status: running\n"]))
131 self.assertEquals(status.status.name, "running")
132 self.assertEquals(status.start, datetime(2007, 3, 9, 17, 32, 55))
133 self.assertEquals(status.name, "Dave")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)