summaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 0000000..6f582bb
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2010 Michael Vogt <michael.vogt@ubuntu.com>
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+import datetime
+import os
+import unittest
+
+import testcommon
+
+from apt.utils import get_maintenance_end_date, get_release_date_from_release_file
+
+
+class TestUtils(testcommon.TestCase):
+ def test_get_release_date_from_release_file(self):
+ path = os.path.join(os.path.dirname(__file__), "data", "misc", "foo_Release")
+ t = get_release_date_from_release_file(path)
+ self.assertEqual(
+ str(datetime.datetime.fromtimestamp(t, datetime.UTC)),
+ "2012-04-25 22:49:23+00:00",
+ )
+
+ def test_maintenance_time(self):
+ months_of_support = 18
+ # test historic releases, jaunty
+ release_date = datetime.datetime(2009, 4, 23)
+ (end_year, end_month) = get_maintenance_end_date(
+ release_date, months_of_support
+ )
+ self.assertEqual(end_year, 2010)
+ self.assertEqual(end_month, 10)
+ # test historic releases, karmic
+ release_date = datetime.datetime(2009, 10, 29)
+ (end_year, end_month) = get_maintenance_end_date(
+ release_date, months_of_support
+ )
+ self.assertEqual(end_year, 2011)
+ self.assertEqual(end_month, 4)
+ # test maverick
+ release_date = datetime.datetime(2010, 10, 10)
+ (end_year, end_month) = get_maintenance_end_date(
+ release_date, months_of_support
+ )
+ self.assertEqual(end_year, 2012)
+ self.assertEqual(end_month, 4)
+
+ # test with modulo zero
+ release_date = datetime.datetime(2010, 6, 10)
+ (end_year, end_month) = get_maintenance_end_date(
+ release_date, months_of_support
+ )
+ self.assertEqual(end_year, 2011)
+ self.assertEqual(end_month, 12)
+
+ # test dapper
+ months_of_support = 60
+ release_date = datetime.datetime(2008, 4, 24)
+ (end_year, end_month) = get_maintenance_end_date(
+ release_date, months_of_support
+ )
+ self.assertEqual(end_year, 2013)
+ self.assertEqual(end_month, 4)
+
+ # what datetime says
+ # d = datetime.timedelta(18*30)
+ # print "end date: ", release_date + d
+
+
+if __name__ == "__main__":
+ unittest.main()