Skip to content

Commit 9b23d0c

Browse files
committed
Add test for natural_keys
1 parent 5f76976 commit 9b23d0c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test/framework/utilities_test.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
@author: Alexander Grund (TU Dresden)
3131
"""
3232
import os
33+
import random
3334
import sys
3435
import tempfile
3536
from datetime import datetime
3637
from unittest import TextTestRunner
3738

3839
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered
3940
from easybuild.tools.build_log import EasyBuildError
40-
from easybuild.tools.utilities import time2str
41+
from easybuild.tools.utilities import time2str, natural_keys
4142

4243

4344
class UtilitiesTest(EnhancedTestCase):
@@ -78,6 +79,25 @@ def test_time2str(self):
7879
error_pattern = "Incorrect value type provided to time2str, should be datetime.timedelta: <.* 'int'>"
7980
self.assertErrorRegex(EasyBuildError, error_pattern, time2str, 123)
8081

82+
def test_natural_keys(self):
83+
"""Test the natural_keys function"""
84+
sorted_items = [
85+
'ACoolSw-1.0',
86+
'ACoolSw-2.1',
87+
'ACoolSw-11.0',
88+
'ACoolSw-23.0',
89+
'ACoolSw-30.0',
90+
'ACoolSw-30.1',
91+
'BigNumber-1234567890',
92+
'BigNumber-1234567891',
93+
'NoNumbers',
94+
'VeryLastEntry-10'
95+
]
96+
shuffled_items = sorted_items[:]
97+
random.shuffle(shuffled_items)
98+
shuffled_items.sort(key=natural_keys)
99+
self.assertEqual(shuffled_items, sorted_items)
100+
81101

82102
def suite():
83103
""" return all the tests in this file """

0 commit comments

Comments
 (0)