8836c79b80f503a3c435925af3e079b0b4869fec
[nepi.git] / test / util / timefuncs.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
20
21 from test_utils import skipIfNotPythonVersion
22
23 import datetime
24 import unittest
25
26 def _get_total_seconds(td):
27     return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
28
29 class TimeFuncTestCase(unittest.TestCase):
30
31     @skipIfNotPythonVersion
32     def test_total_seconds(self):
33         date = datetime.timedelta(2, 468, 506260)
34         seconds1 = _get_total_seconds(date)
35         seconds2 = date.total_seconds()
36
37         self.assertEquals(seconds1, seconds2)
38
39
40 if __name__ == '__main__':
41     unittest.main()
42
43