bh@12: # Copyright (C) 2007 by Intevation GmbH bh@12: # Authors: bh@12: # Bernhard Herzog bh@12: # bh@12: # This program is free software under the GPL (>=v2) bh@12: # Read the file COPYING coming with the software for details. bh@12: bh@12: """Tests for the Status class""" bh@12: bh@12: import os bh@12: import unittest bh@12: from datetime import datetime bh@12: bh@12: from treepkg.status import Status bh@12: from treepkg.util import ensure_directory, writefile bh@12: bh@12: bh@12: bh@12: class TestStatus(unittest.TestCase): bh@12: bh@12: def tempfilename(self): bh@12: tempdir = os.path.join(os.path.dirname(__file__), "temp") bh@12: ensure_directory(tempdir) bh@12: return os.path.join(tempdir, self.id()) bh@12: bh@12: def setUp(self): bh@12: self.filename = self.tempfilename() bh@12: if os.path.exists(self.filename): bh@12: os.remove(self.filename) bh@12: bh@12: def test_status(self): bh@12: status = Status(self.filename) bh@12: status.status = "testing" bh@12: bh@12: otherstatus = Status(self.filename) bh@12: self.assertEquals(otherstatus.status, "testing") bh@12: bh@12: def test_getting_unknown_fields(self): bh@12: status = Status(self.filename) bh@12: self.assertRaises(AttributeError, getattr, status, "unknown_field") bh@12: bh@12: def test_setting_unknown_fields(self): bh@12: status = Status(self.filename) bh@12: self.assertRaises(AttributeError, bh@12: setattr, status, "unknown_field", "some value") bh@12: bh@12: def test_default_value(self): bh@12: status = Status(self.filename) bh@12: self.assertEquals(status.start, None) bh@12: bh@12: def test_date(self): bh@12: timestamp = datetime(2007, 3, 9, 17, 32, 55) bh@12: status = Status(self.filename) bh@12: status.start = timestamp bh@12: bh@12: otherstatus = Status(self.filename) bh@12: self.assertEquals(otherstatus.start, timestamp) bh@12: bh@12: def test_magic(self): bh@12: writefile(self.filename, bh@12: "Some other magic\nstart: 2007-03-09 17:32:55\n") bh@12: self.assertRaises(ValueError, Status, self.filename)