diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /taskcluster/taskgraph/test/test_util_time.py | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'taskcluster/taskgraph/test/test_util_time.py')
-rwxr-xr-x | taskcluster/taskgraph/test/test_util_time.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/taskcluster/taskgraph/test/test_util_time.py b/taskcluster/taskgraph/test/test_util_time.py new file mode 100755 index 000000000..f001c9d9c --- /dev/null +++ b/taskcluster/taskgraph/test/test_util_time.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import unittest +import mozunit +from datetime import datetime +from taskgraph.util.time import ( + InvalidString, + UnknownTimeMeasurement, + value_of, + json_time_from_now +) + + +class FromNowTest(unittest.TestCase): + + def test_invalid_str(self): + with self.assertRaises(InvalidString): + value_of('wtfs') + + def test_missing_unit(self): + with self.assertRaises(InvalidString): + value_of('1') + + def test_missing_unknown_unit(self): + with self.assertRaises(UnknownTimeMeasurement): + value_of('1z') + + def test_value_of(self): + self.assertEqual(value_of('1s').total_seconds(), 1) + self.assertEqual(value_of('1 second').total_seconds(), 1) + self.assertEqual(value_of('1min').total_seconds(), 60) + self.assertEqual(value_of('1h').total_seconds(), 3600) + self.assertEqual(value_of('1d').total_seconds(), 86400) + self.assertEqual(value_of('1mo').total_seconds(), 2592000) + self.assertEqual(value_of('1 month').total_seconds(), 2592000) + self.assertEqual(value_of('1y').total_seconds(), 31536000) + + with self.assertRaises(UnknownTimeMeasurement): + value_of('1m').total_seconds() # ambiguous between minute and month + + def test_json_from_now_utc_now(self): + # Just here to ensure we don't raise. + json_time_from_now('1 years') + + def test_json_from_now(self): + now = datetime(2014, 1, 1) + self.assertEqual(json_time_from_now('1 years', now), + '2015-01-01T00:00:00Z') + self.assertEqual(json_time_from_now('6 days', now), + '2014-01-07T00:00:00Z') + +if __name__ == '__main__': + mozunit.main() |