Skip to content

Commit 5f76976

Browse files
committed
Add utilities_test.py
1 parent 987599c commit 5f76976

File tree

2 files changed

+89
-30
lines changed

2 files changed

+89
-30
lines changed

test/framework/easyblock.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import sys
3535
import tempfile
3636
from inspect import cleandoc
37-
from datetime import datetime
3837
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, init_config
3938
from unittest import TextTestRunner
4039

@@ -50,7 +49,6 @@
5049
from easybuild.tools.filetools import verify_checksum, write_file
5150
from easybuild.tools.module_generator import module_generator
5251
from easybuild.tools.modules import reset_module_caches
53-
from easybuild.tools.utilities import time2str
5452
from easybuild.tools.version import get_git_revision, this_is_easybuild
5553
from easybuild.tools.py2vs3 import string_type
5654

@@ -2108,34 +2106,6 @@ def test_avail_easyblocks(self):
21082106
self.assertEqual(hpl['class'], 'EB_HPL')
21092107
self.assertTrue(hpl['loc'].endswith('sandbox/easybuild/easyblocks/h/hpl.py'))
21102108

2111-
def test_time2str(self):
2112-
"""Test time2str function."""
2113-
2114-
start = datetime(2019, 7, 30, 5, 14, 23)
2115-
2116-
test_cases = [
2117-
(start, "0 sec"),
2118-
(datetime(2019, 7, 30, 5, 14, 37), "14 sec"),
2119-
(datetime(2019, 7, 30, 5, 15, 22), "59 sec"),
2120-
(datetime(2019, 7, 30, 5, 15, 23), "1 min 0 sec"),
2121-
(datetime(2019, 7, 30, 5, 16, 22), "1 min 59 sec"),
2122-
(datetime(2019, 7, 30, 5, 37, 26), "23 min 3 sec"),
2123-
(datetime(2019, 7, 30, 6, 14, 22), "59 min 59 sec"),
2124-
(datetime(2019, 7, 30, 6, 14, 23), "1 hour 0 min 0 sec"),
2125-
(datetime(2019, 7, 30, 6, 49, 14), "1 hour 34 min 51 sec"),
2126-
(datetime(2019, 7, 30, 7, 14, 23), "2 hours 0 min 0 sec"),
2127-
(datetime(2019, 7, 30, 8, 35, 59), "3 hours 21 min 36 sec"),
2128-
(datetime(2019, 7, 30, 16, 29, 24), "11 hours 15 min 1 sec"),
2129-
(datetime(2019, 7, 31, 5, 14, 22), "23 hours 59 min 59 sec"),
2130-
(datetime(2019, 7, 31, 5, 14, 23), "24 hours 0 min 0 sec"),
2131-
(datetime(2019, 8, 5, 20, 39, 44), "159 hours 25 min 21 sec"),
2132-
]
2133-
for end, expected in test_cases:
2134-
self.assertEqual(time2str(end - start), expected)
2135-
2136-
error_pattern = "Incorrect value type provided to time2str, should be datetime.timedelta: <.* 'int'>"
2137-
self.assertErrorRegex(EasyBuildError, error_pattern, time2str, 123)
2138-
21392109
def test_sanity_check_paths_verification(self):
21402110
"""Test verification of sanity_check_paths w.r.t. keys & values."""
21412111

test/framework/utilities_test.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
##
2+
# Copyright 2012-2021 Ghent University
3+
#
4+
# This file is part of EasyBuild,
5+
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
6+
# with support of Ghent University (http://ugent.be/hpc),
7+
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
8+
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
9+
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
10+
#
11+
# https://github.com/easybuilders/easybuild
12+
#
13+
# EasyBuild is free software: you can redistribute it and/or modify
14+
# it under the terms of the GNU General Public License as published by
15+
# the Free Software Foundation v2.
16+
#
17+
# EasyBuild is distributed in the hope that it will be useful,
18+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
# GNU General Public License for more details.
21+
#
22+
# You should have received a copy of the GNU General Public License
23+
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
24+
##
25+
"""
26+
Unit tests for utilities.py
27+
28+
@author: Jens Timmerman (Ghent University)
29+
@author: Kenneth Hoste (Ghent University)
30+
@author: Alexander Grund (TU Dresden)
31+
"""
32+
import os
33+
import sys
34+
import tempfile
35+
from datetime import datetime
36+
from unittest import TextTestRunner
37+
38+
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered
39+
from easybuild.tools.build_log import EasyBuildError
40+
from easybuild.tools.utilities import time2str
41+
42+
43+
class UtilitiesTest(EnhancedTestCase):
44+
"""Class for utilities testcases """
45+
46+
def setUp(self):
47+
""" setup """
48+
super(UtilitiesTest, self).setUp()
49+
50+
self.test_tmp_logdir = tempfile.mkdtemp()
51+
os.environ['EASYBUILD_TMP_LOGDIR'] = self.test_tmp_logdir
52+
53+
def test_time2str(self):
54+
"""Test time2str function."""
55+
56+
start = datetime(2019, 7, 30, 5, 14, 23)
57+
58+
test_cases = [
59+
(start, "0 sec"),
60+
(datetime(2019, 7, 30, 5, 14, 37), "14 sec"),
61+
(datetime(2019, 7, 30, 5, 15, 22), "59 sec"),
62+
(datetime(2019, 7, 30, 5, 15, 23), "1 min 0 sec"),
63+
(datetime(2019, 7, 30, 5, 16, 22), "1 min 59 sec"),
64+
(datetime(2019, 7, 30, 5, 37, 26), "23 min 3 sec"),
65+
(datetime(2019, 7, 30, 6, 14, 22), "59 min 59 sec"),
66+
(datetime(2019, 7, 30, 6, 14, 23), "1 hour 0 min 0 sec"),
67+
(datetime(2019, 7, 30, 6, 49, 14), "1 hour 34 min 51 sec"),
68+
(datetime(2019, 7, 30, 7, 14, 23), "2 hours 0 min 0 sec"),
69+
(datetime(2019, 7, 30, 8, 35, 59), "3 hours 21 min 36 sec"),
70+
(datetime(2019, 7, 30, 16, 29, 24), "11 hours 15 min 1 sec"),
71+
(datetime(2019, 7, 31, 5, 14, 22), "23 hours 59 min 59 sec"),
72+
(datetime(2019, 7, 31, 5, 14, 23), "24 hours 0 min 0 sec"),
73+
(datetime(2019, 8, 5, 20, 39, 44), "159 hours 25 min 21 sec"),
74+
]
75+
for end, expected in test_cases:
76+
self.assertEqual(time2str(end - start), expected)
77+
78+
error_pattern = "Incorrect value type provided to time2str, should be datetime.timedelta: <.* 'int'>"
79+
self.assertErrorRegex(EasyBuildError, error_pattern, time2str, 123)
80+
81+
82+
def suite():
83+
""" return all the tests in this file """
84+
return TestLoaderFiltered().loadTestsFromTestCase(UtilitiesTest, sys.argv[1:])
85+
86+
87+
if __name__ == '__main__':
88+
res = TextTestRunner(verbosity=1).run(suite())
89+
sys.exit(len(res.failures))

0 commit comments

Comments
 (0)