9dfef1922bb9bdf68ba31a82231ed890643c5d9b
[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 version 2 as
8 #    published by the Free Software Foundation;
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
19
20 from test_utils import skipIfNotPythonVersion
21
22 import datetime
23 import unittest
24
25 def _get_total_seconds(td):
26     return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
27
28 class TimeFuncTestCase(unittest.TestCase):
29
30     @skipIfNotPythonVersion
31     def test_total_seconds(self):
32         date = datetime.timedelta(2, 468, 506260)
33         seconds1 = _get_total_seconds(date)
34         seconds2 = date.total_seconds()
35
36         self.assertEquals(seconds1, seconds2)
37
38
39 if __name__ == '__main__':
40     unittest.main()
41
42