File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 3030@author: Alexander Grund (TU Dresden)
3131"""
3232import os
33+ import random
3334import sys
3435import tempfile
3536from datetime import datetime
3637from unittest import TextTestRunner
3738
3839from test .framework .utilities import EnhancedTestCase , TestLoaderFiltered
3940from easybuild .tools .build_log import EasyBuildError
40- from easybuild .tools .utilities import time2str
41+ from easybuild .tools .utilities import time2str , natural_keys
4142
4243
4344class 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
82102def suite ():
83103 """ return all the tests in this file """
You can’t perform that action at this time.
0 commit comments