-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy patheasyblock.py
2948 lines (2529 loc) · 134 KB
/
easyblock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##
# Copyright 2012-2025 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
Unit tests for easyblock.py
@author: Jens Timmerman (Ghent University)
@author: Kenneth Hoste (Ghent University)
@author: Maxime Boissonneault (Compute Canada)
@author: Jan Andre Reuter (Juelich Supercomputing Centre)
"""
import os
import re
import shutil
import sys
import tempfile
from inspect import cleandoc
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, init_config
from unittest import TextTestRunner
import easybuild.tools.systemtools as st
from easybuild.base import fancylogger
from easybuild.framework.easyblock import EasyBlock, get_easyblock_instance
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.easyconfig.easyconfig import EasyConfig
from easybuild.framework.easyconfig.tools import avail_easyblocks, process_easyconfig
from easybuild.framework.extensioneasyblock import ExtensionEasyBlock
from easybuild.tools import LooseVersion, config
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import get_module_syntax, update_build_option
from easybuild.tools.filetools import change_dir, copy_dir, copy_file, mkdir, read_file, remove_dir, remove_file
from easybuild.tools.filetools import verify_checksum, write_file
from easybuild.tools.module_generator import module_generator
from easybuild.tools.modules import EnvironmentModules, Lmod, reset_module_caches
from easybuild.tools.version import get_git_revision, this_is_easybuild
from easybuild.tools.py2vs3 import string_type
class EasyBlockTest(EnhancedTestCase):
""" Baseclass for easyblock testcases """
def writeEC(self):
""" create temporary easyconfig file """
write_file(self.eb_file, self.contents)
def setUp(self):
""" setup """
super(EasyBlockTest, self).setUp()
fd, self.eb_file = tempfile.mkstemp(prefix='easyblock_test_file_', suffix='.eb')
os.close(fd)
self.test_tmp_logdir = tempfile.mkdtemp()
os.environ['EASYBUILD_TMP_LOGDIR'] = self.test_tmp_logdir
def test_empty(self):
self.contents = "# empty"
self.writeEC()
""" empty files should not parse! """
self.assertRaises(EasyBuildError, EasyConfig, self.eb_file)
self.assertErrorRegex(EasyBuildError, "Value of incorrect type passed", EasyBlock, "")
def test_easyblock(self):
""" make sure easyconfigs defining extensions work"""
def check_extra_options_format(extra_options):
"""Make sure extra_options value is of correct format."""
# EasyBuild v2.0: dict with <string> keys and <list> values
# (breaks backward compatibility compared to v1.x)
self.assertIsInstance(extra_options, dict) # conversion to a dict works
extra_options.items()
extra_options.keys()
extra_options.values()
for key in extra_options.keys():
self.assertIsInstance(extra_options[key], list)
self.assertEqual(len(extra_options[key]), 3)
name = "pi"
version = "3.14"
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "%s"' % name,
'version = "%s"' % version,
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
'exts_list = ["ext1"]',
])
self.writeEC()
stdoutorig = sys.stdout
sys.stdout = open("/dev/null", 'w')
ec = EasyConfig(self.eb_file)
eb = EasyBlock(ec)
self.assertEqual(eb.cfg['name'], name)
self.assertEqual(eb.cfg['version'], version)
self.assertRaises(NotImplementedError, eb.run_all_steps, True)
check_extra_options_format(eb.extra_options())
sys.stdout.close()
sys.stdout = stdoutorig
# check whether 'This is easyblock' log message is there
tup = ('EasyBlock', 'easybuild.framework.easyblock', '.*easybuild/framework/easyblock.pyc*')
eb_log_msg_re = re.compile(r"INFO This is easyblock %s from module %s (%s)" % tup, re.M)
logtxt = read_file(eb.logfile)
self.assertTrue(eb_log_msg_re.search(logtxt), "Pattern '%s' found in: %s" % (eb_log_msg_re.pattern, logtxt))
# test extensioneasyblock, as extension
exeb1 = ExtensionEasyBlock(eb, {'name': 'foo', 'version': '0.0'})
self.assertEqual(exeb1.cfg['name'], 'foo')
extra_options = exeb1.extra_options()
check_extra_options_format(extra_options)
self.assertIn('options', extra_options)
# Reporting test failure should work also for the extension EB
self.assertRaises(EasyBuildError, exeb1.report_test_failure, "Fails")
# test extensioneasyblock, as easyblock
exeb2 = ExtensionEasyBlock(ec)
self.assertEqual(exeb2.cfg['name'], 'pi')
self.assertEqual(exeb2.cfg['version'], '3.14')
extra_options = exeb2.extra_options()
check_extra_options_format(extra_options)
self.assertIn('options', extra_options)
# Reporting test failure should work also for the extension EB
self.assertRaises(EasyBuildError, exeb2.report_test_failure, "Fails")
class TestExtension(ExtensionEasyBlock):
@staticmethod
def extra_options():
return ExtensionEasyBlock.extra_options({'extra_param': [None, "help", CUSTOM]})
texeb = TestExtension(eb, {'name': 'bar'})
self.assertEqual(texeb.cfg['name'], 'bar')
extra_options = texeb.extra_options()
check_extra_options_format(extra_options)
self.assertIn('options', extra_options)
self.assertEqual(extra_options['extra_param'], [None, "help", CUSTOM])
# cleanup
eb.close_log()
os.remove(eb.logfile)
def test_load_module(self):
"""Test load_module method."""
# copy OpenMPI module used in gompi/2018a to fiddle with it, i.e. to fake bump OpenMPI version used in it
tmp_modules = os.path.join(self.test_prefix, 'modules')
mkdir(tmp_modules)
test_dir = os.path.abspath(os.path.dirname(__file__))
copy_dir(os.path.join(test_dir, 'modules', 'OpenMPI'), os.path.join(tmp_modules, 'OpenMPI'))
openmpi_module = os.path.join(tmp_modules, 'OpenMPI', '2.1.2-GCC-6.4.0-2.28')
ompi_mod_txt = read_file(openmpi_module)
write_file(openmpi_module, ompi_mod_txt.replace('2.1.2', '2.0.2'))
self.modtool.use(tmp_modules)
orig_tmpdir = os.path.join(self.test_prefix, 'verylongdirectorythatmaycauseproblemswithopenmpi2')
os.environ['TMPDIR'] = orig_tmpdir
self.contents = '\n'.join([
"easyblock = 'ConfigureMake'",
"name = 'pi'",
"version = '3.14'",
"homepage = 'http://example.com'",
"description = 'test easyconfig'",
"toolchain = {'name': 'gompi', 'version': '2018a'}",
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = config.build_path()
# $TMPDIR is not touched yet at this point
self.assertEqual(os.environ.get('TMPDIR'), orig_tmpdir)
self.mock_stderr(True)
self.mock_stdout(True)
eb.prepare_step(start_dir=False)
stderr = self.get_stderr()
stdout = self.get_stdout()
self.mock_stderr(False)
self.mock_stdout(False)
self.assertFalse(stdout)
self.assertTrue(stderr.strip().startswith("WARNING: Long $TMPDIR path may cause problems with OpenMPI 2.x"))
# we expect $TMPDIR to be tweaked by the prepare step (OpenMPI 2.x doesn't like long $TMPDIR values)
tweaked_tmpdir = os.environ.get('TMPDIR')
self.assertNotEqual(tweaked_tmpdir, orig_tmpdir)
eb.make_module_step()
eb.load_module()
# $TMPDIR does *not* get reset to original value after loading of module
# (which involves resetting the environment before loading the module)
self.assertEqual(os.environ.get('TMPDIR'), tweaked_tmpdir)
# cleanup
eb.close_log()
os.remove(eb.logfile)
def test_fake_module_load(self):
"""Testcase for fake module load"""
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = config.build_path()
fake_mod_data = eb.load_fake_module()
pi_modfile = os.path.join(fake_mod_data[0], 'pi', '3.14')
if get_module_syntax() == 'Lua':
pi_modfile += '.lua'
self.assertExists(pi_modfile)
# check whether temporary module file is marked as default
if get_module_syntax() == 'Lua':
default_symlink = os.path.join(fake_mod_data[0], 'pi', 'default')
self.assertTrue(os.path.samefile(default_symlink, pi_modfile))
else:
dot_version_txt = read_file(os.path.join(fake_mod_data[0], 'pi', '.version'))
self.assertIn("set ModulesVersion 3.14", dot_version_txt)
eb.clean_up_fake_module(fake_mod_data)
# cleanup
eb.close_log()
os.remove(eb.logfile)
def test_make_module_extend_modpath(self):
"""Test for make_module_extend_modpath"""
module_syntax = get_module_syntax()
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
'moduleclass = "compiler"',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = config.install_path()
# no $MODULEPATH extensions for default module naming scheme (EasyBuildMNS)
self.assertEqual(eb.make_module_extend_modpath(), '')
usermodsdir = 'my_own_modules'
modclasses = ['compiler', 'tools']
os.environ['EASYBUILD_MODULE_NAMING_SCHEME'] = 'CategorizedHMNS'
build_options = {
'subdir_user_modules': usermodsdir,
'valid_module_classes': modclasses,
'suffix_modules_path': 'funky',
}
init_config(build_options=build_options)
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = config.install_path()
txt = eb.make_module_extend_modpath()
if module_syntax == 'Tcl':
regexs = [r'^module use ".*/modules/funky/Compiler/pi/3.14/%s"$' % c for c in modclasses]
home = r'\[if { \[info exists ::env\(HOME\)\] } { concat \$::env\(HOME\) } '
home += r'else { concat "HOME_NOT_DEFINED" } \]'
fj_usermodsdir = 'file join "%s" "funky" "Compiler/pi/3.14"' % usermodsdir
regexs.extend([
# extension for user modules is guarded
r'if { \[ file isdirectory \[ file join %s \[ %s \] \] \] } {$' % (home, fj_usermodsdir),
# no per-moduleclass extension for user modules
r'^\s+module use \[ file join %s \[ %s \] \]$' % (home, fj_usermodsdir),
])
elif module_syntax == 'Lua':
regexs = [r'^prepend_path\("MODULEPATH", ".*/modules/funky/Compiler/pi/3.14/%s"\)$' % c for c in modclasses]
home = r'os.getenv\("HOME"\) or "HOME_NOT_DEFINED"'
pj_usermodsdir = r'pathJoin\("%s", "funky", "Compiler/pi/3.14"\)' % usermodsdir
regexs.extend([
# extension for user modules is guarded
r'if isDir\(pathJoin\(%s, %s\)\) then' % (home, pj_usermodsdir),
# no per-moduleclass extension for user modules
r'\s+prepend_path\("MODULEPATH", pathJoin\(%s, %s\)\)' % (home, pj_usermodsdir),
])
else:
self.fail("Unknown module syntax: %s" % module_syntax)
for regex in regexs:
regex = re.compile(regex, re.M)
self.assertTrue(regex.search(txt), "Pattern '%s' found in: %s" % (regex.pattern, txt))
# Repeat this but using an alternate envvars (instead of $HOME)
list_of_envvars = ['SITE_INSTALLS', 'USER_INSTALLS']
build_options = {
'envvars_user_modules': list_of_envvars,
'subdir_user_modules': usermodsdir,
'valid_module_classes': modclasses,
'suffix_modules_path': 'funky',
}
init_config(build_options=build_options)
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = config.install_path()
txt = eb.make_module_extend_modpath()
for envvar in list_of_envvars:
if module_syntax == 'Tcl':
regexs = [r'^module use ".*/modules/funky/Compiler/pi/3.14/%s"$' % c for c in modclasses]
module_envvar = r'\[if \{ \[info exists ::env\(%s\)\] \} ' % envvar
module_envvar += r'\{ concat \$::env\(%s\) \} ' % envvar
module_envvar += r'else { concat "%s" } \]' % (envvar + '_NOT_DEFINED')
fj_usermodsdir = 'file join "%s" "funky" "Compiler/pi/3.14"' % usermodsdir
regexs.extend([
# extension for user modules is guarded
r'if { \[ file isdirectory \[ file join %s \[ %s \] \] \] } {$' % (module_envvar, fj_usermodsdir),
# no per-moduleclass extension for user modules
r'^\s+module use \[ file join %s \[ %s \] \]$' % (module_envvar, fj_usermodsdir),
])
elif module_syntax == 'Lua':
regexs = [r'^prepend_path\("MODULEPATH", ".*/modules/funky/Compiler/pi/3.14/%s"\)$' % c
for c in modclasses]
module_envvar = r'os.getenv\("%s"\) or "%s"' % (envvar, envvar + "_NOT_DEFINED")
pj_usermodsdir = r'pathJoin\("%s", "funky", "Compiler/pi/3.14"\)' % usermodsdir
regexs.extend([
# extension for user modules is guarded
r'if isDir\(pathJoin\(%s, %s\)\) then' % (module_envvar, pj_usermodsdir),
# no per-moduleclass extension for user modules
r'\s+prepend_path\("MODULEPATH", pathJoin\(%s, %s\)\)' % (module_envvar, pj_usermodsdir),
])
else:
self.fail("Unknown module syntax: %s" % module_syntax)
for regex in regexs:
regex = re.compile(regex, re.M)
self.assertTrue(regex.search(txt), "Pattern '%s' found in: %s" % (regex.pattern, txt))
os.unsetenv(envvar)
# Check behaviour when directories do and do not exist
usermodsdir_extension = os.path.join(usermodsdir, "funky", "Compiler/pi/3.14")
site_install_path = os.path.join(config.install_path(), 'site')
site_modules = os.path.join(site_install_path, usermodsdir_extension)
user_install_path = os.path.join(config.install_path(), 'user')
user_modules = os.path.join(user_install_path, usermodsdir_extension)
# make a modules directory so that we can create our module files
temp_module_file_dir = os.path.join(site_install_path, usermodsdir, "temp_module_files")
mkdir(temp_module_file_dir, parents=True)
# write out a module file
if module_syntax == 'Tcl':
module_file = os.path.join(temp_module_file_dir, "mytest")
module_txt = "#%Module\n" + txt
elif module_syntax == 'Lua':
module_file = os.path.join(temp_module_file_dir, "mytest.lua")
module_txt = txt
write_file(module_file, module_txt)
# Set MODULEPATH and check the effect of `module load`
os.environ['MODULEPATH'] = temp_module_file_dir
# Let's switch to a dir where the paths we will use exist to make sure they can
# not be accidentally picked up if the variable is not defined but the paths exist
# relative to the current directory
cwd = os.getcwd()
mkdir(os.path.join(config.install_path(), "existing_dir", usermodsdir_extension), parents=True)
change_dir(os.path.join(config.install_path(), "existing_dir"))
self.modtool.run_module('load', 'mytest')
self.assertNotIn(usermodsdir_extension, os.environ['MODULEPATH'])
self.modtool.run_module('unload', 'mytest')
change_dir(cwd)
# Now define our environment variables
os.environ['SITE_INSTALLS'] = site_install_path
os.environ['USER_INSTALLS'] = user_install_path
# Check MODULEPATH when neither directories exist
self.modtool.run_module('load', 'mytest')
self.assertNotIn(site_modules, os.environ['MODULEPATH'])
self.assertNotIn(user_modules, os.environ['MODULEPATH'])
self.modtool.run_module('unload', 'mytest')
# Now create the directory for site modules
mkdir(site_modules, parents=True)
self.modtool.run_module('load', 'mytest')
self.assertTrue(os.environ['MODULEPATH'].startswith(site_modules))
self.assertNotIn(user_modules, os.environ['MODULEPATH'])
self.modtool.run_module('unload', 'mytest')
# Now create the directory for user modules
mkdir(user_modules, parents=True)
self.modtool.run_module('load', 'mytest')
self.assertTrue(os.environ['MODULEPATH'].startswith(user_modules + ":" + site_modules))
self.modtool.run_module('unload', 'mytest')
def test_make_module_req(self):
"""Testcase for make_module_req"""
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = config.install_path()
# create fake directories and files that should be guessed
os.makedirs(eb.installdir)
write_file(os.path.join(eb.installdir, 'foo.jar'), 'foo.jar')
write_file(os.path.join(eb.installdir, 'bla.jar'), 'bla.jar')
for path in ('bin', ('bin', 'testdir'), 'sbin', 'share', ('share', 'man'), 'lib', 'lib64'):
if isinstance(path, string_type):
path = (path, )
os.mkdir(os.path.join(eb.installdir, *path))
# this is not a path that should be picked up
os.mkdir(os.path.join(eb.installdir, 'CPATH'))
with eb.module_generator.start_module_creation():
guess = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r"^prepend-path\s+CLASSPATH\s+\$root/bla.jar$", guess, re.M))
self.assertTrue(re.search(r"^prepend-path\s+CLASSPATH\s+\$root/foo.jar$", guess, re.M))
self.assertTrue(re.search(r"^prepend-path\s+MANPATH\s+\$root/share/man$", guess, re.M))
self.assertTrue(re.search(r"^prepend-path\s+CMAKE_PREFIX_PATH\s+\$root$", guess, re.M))
# bin/ is not added to $PATH if it doesn't include files
self.assertFalse(re.search(r"^prepend-path\s+PATH\s+\$root/bin$", guess, re.M))
self.assertFalse(re.search(r"^prepend-path\s+PATH\s+\$root/sbin$", guess, re.M))
# no include/ subdirectory, so no $CPATH update statement
self.assertFalse(re.search(r"^prepend-path\s+CPATH\s+.*$", guess, re.M))
elif get_module_syntax() == 'Lua':
self.assertTrue(re.search(r'^prepend_path\("CLASSPATH", pathJoin\(root, "bla.jar"\)\)$', guess, re.M))
self.assertTrue(re.search(r'^prepend_path\("CLASSPATH", pathJoin\(root, "foo.jar"\)\)$', guess, re.M))
self.assertTrue(re.search(r'^prepend_path\("MANPATH", pathJoin\(root, "share/man"\)\)$', guess, re.M))
self.assertIn('prepend_path("CMAKE_PREFIX_PATH", root)', guess)
# bin/ is not added to $PATH if it doesn't include files
self.assertFalse(re.search(r'^prepend_path\("PATH", pathJoin\(root, "bin"\)\)$', guess, re.M))
self.assertFalse(re.search(r'^prepend_path\("PATH", pathJoin\(root, "sbin"\)\)$', guess, re.M))
# no include/ subdirectory, so no $CPATH update statement
self.assertFalse(re.search(r'^prepend_path\("CPATH", .*\)$', guess, re.M))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
# check that bin is only added to PATH if there are files in there
write_file(os.path.join(eb.installdir, 'bin', 'test'), 'test')
with eb.module_generator.start_module_creation():
guess = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r"^prepend-path\s+PATH\s+\$root/bin$", guess, re.M))
self.assertFalse(re.search(r"^prepend-path\s+PATH\s+\$root/sbin$", guess, re.M))
elif get_module_syntax() == 'Lua':
self.assertTrue(re.search(r'^prepend_path\("PATH", pathJoin\(root, "bin"\)\)$', guess, re.M))
self.assertFalse(re.search(r'^prepend_path\("PATH", pathJoin\(root, "sbin"\)\)$', guess, re.M))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
# Check that lib64 is only added to CMAKE_LIBRARY_PATH if there are files in there
# but only if it is not a symlink to lib
# -- No Files
if get_module_syntax() == 'Tcl':
self.assertFalse(re.search(r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$", guess, re.M))
elif get_module_syntax() == 'Lua':
self.assertNotIn('prepend_path("CMAKE_LIBRARY_PATH", pathJoin(root, "lib64"))', guess)
# -- With files
write_file(os.path.join(eb.installdir, 'lib64', 'libfoo.so'), 'test')
with eb.module_generator.start_module_creation():
guess = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$", guess, re.M))
elif get_module_syntax() == 'Lua':
self.assertIn('prepend_path("CMAKE_LIBRARY_PATH", pathJoin(root, "lib64"))', guess)
# -- With files in lib and lib64 symlinks to lib
write_file(os.path.join(eb.installdir, 'lib', 'libfoo.so'), 'test')
shutil.rmtree(os.path.join(eb.installdir, 'lib64'))
os.symlink('lib', os.path.join(eb.installdir, 'lib64'))
with eb.module_generator.start_module_creation():
guess = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertFalse(re.search(r"^prepend-path\s+CMAKE_LIBRARY_PATH\s+\$root/lib64$", guess, re.M))
elif get_module_syntax() == 'Lua':
self.assertNotIn('prepend_path("CMAKE_LIBRARY_PATH", pathJoin(root, "lib64"))', guess)
# With files in /lib and /lib64 symlinked to /lib there should be exactly 1 entry for (LD_)LIBRARY_PATH
# pointing to /lib
for var in ('LIBRARY_PATH', 'LD_LIBRARY_PATH'):
if get_module_syntax() == 'Tcl':
self.assertFalse(re.search(r"^prepend-path\s+%s\s+\$root/lib64$" % var, guess, re.M))
self.assertEqual(len(re.findall(r"^prepend-path\s+%s\s+\$root/lib$" % var, guess, re.M)), 1)
elif get_module_syntax() == 'Lua':
self.assertFalse(re.search(r'^prepend_path\("%s", pathJoin\(root, "lib64"\)\)$' % var, guess, re.M))
self.assertEqual(len(re.findall(r'^prepend_path\("%s", pathJoin\(root, "lib"\)\)$' % var,
guess, re.M)), 1)
# check for behavior when a string value is used as dict value by make_module_req_guesses
eb.make_module_req_guess = lambda: {'PATH': 'bin'}
with eb.module_generator.start_module_creation():
txt = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertTrue(re.match(r"^\nprepend-path\s+PATH\s+\$root/bin\n$", txt, re.M))
elif get_module_syntax() == 'Lua':
self.assertTrue(re.match(r'^\nprepend_path\("PATH", pathJoin\(root, "bin"\)\)\n$', txt, re.M))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
# check for correct behaviour if empty string is specified as one of the values
# prepend-path statements should be included for both the 'bin' subdir and the install root
eb.make_module_req_guess = lambda: {'PATH': ['bin', '']}
with eb.module_generator.start_module_creation():
txt = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r"\nprepend-path\s+PATH\s+\$root/bin\n", txt, re.M))
self.assertTrue(re.search(r"\nprepend-path\s+PATH\s+\$root\n", txt, re.M))
elif get_module_syntax() == 'Lua':
self.assertTrue(re.search(r'\nprepend_path\("PATH", pathJoin\(root, "bin"\)\)\n', txt, re.M))
self.assertTrue(re.search(r'\nprepend_path\("PATH", root\)\n', txt, re.M))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
# check for correct order of prepend statements when providing a list (and that no duplicates are allowed)
eb.make_module_req_guess = lambda: {'LD_LIBRARY_PATH': ['lib/pathC', 'lib/pathA', 'lib/pathB', 'lib/pathA']}
for path in ['pathA', 'pathB', 'pathC']:
os.mkdir(os.path.join(eb.installdir, 'lib', path))
write_file(os.path.join(eb.installdir, 'lib', path, 'libfoo.so'), 'test')
with eb.module_generator.start_module_creation():
txt = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathC\n" +
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n" +
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathB\n",
txt, re.M))
self.assertFalse(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathB\n" +
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n",
txt, re.M))
elif get_module_syntax() == 'Lua':
self.assertTrue(re.search(r'\nprepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathC"\)\)\n' +
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathA"\)\)\n' +
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathB"\)\)\n',
txt, re.M))
self.assertFalse(re.search(r'\nprepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathB"\)\)\n' +
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathA"\)\)\n',
txt, re.M))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
# If PATH or LD_LIBRARY_PATH contain only folders, do not add an entry
sub_lib_path = os.path.join('lib', 'path_folders')
sub_path_path = os.path.join('bin', 'path_folders')
eb.make_module_req_guess = lambda: {'LD_LIBRARY_PATH': sub_lib_path, 'PATH': sub_path_path}
for path in (sub_lib_path, sub_path_path):
full_path = os.path.join(eb.installdir, path, 'subpath')
os.makedirs(full_path)
write_file(os.path.join(full_path, 'any.file'), 'test')
txt = eb.make_module_req()
if get_module_syntax() == 'Tcl':
self.assertFalse(re.search(r"prepend-path\s+LD_LIBRARY_PATH\s+\$%s\n" % sub_lib_path,
txt, re.M))
self.assertFalse(re.search(r"prepend-path\s+PATH\s+\$%s\n" % sub_path_path, txt, re.M))
else:
assert get_module_syntax() == 'Lua'
self.assertFalse(re.search(r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "%s"\)\)\n' % sub_lib_path,
txt, re.M))
self.assertFalse(re.search(r'prepend_path\("PATH", pathJoin\(root, "%s"\)\)\n' % sub_path_path, txt, re.M))
# cleanup
eb.close_log()
os.remove(eb.logfile)
def test_make_module_extra(self):
"""Test for make_module_extra."""
init_config(build_options={'silent': True})
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'gompi', 'version': '2018a'}",
'dependencies = [',
" ('FFTW', '3.3.7'),",
" ('OpenBLAS', '0.2.20'),",
']',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
if get_module_syntax() == 'Tcl':
expected_default = re.compile(r'\n'.join([
r'setenv\s+EBROOTPI\s+\"\$root"',
r'setenv\s+EBVERSIONPI\s+"3.14"',
r'setenv\s+EBDEVELPI\s+"\$root/easybuild/pi-3.14-gompi-2018a-easybuild-devel"',
]))
expected_alt = re.compile(r'\n'.join([
r'setenv\s+EBROOTPI\s+"/opt/software/tau/6.28"',
r'setenv\s+EBVERSIONPI\s+"6.28"',
r'setenv\s+EBDEVELPI\s+"\$root/easybuild/pi-3.14-gompi-2018a-easybuild-devel"',
]))
elif get_module_syntax() == 'Lua':
expected_default = re.compile(r'\n'.join([
r'setenv\("EBROOTPI", root\)',
r'setenv\("EBVERSIONPI", "3.14"\)',
r'setenv\("EBDEVELPI", pathJoin\(root, "easybuild/pi-3.14-gompi-2018a-easybuild-devel"\)\)',
]))
expected_alt = re.compile(r'\n'.join([
r'setenv\("EBROOTPI", "/opt/software/tau/6.28"\)',
r'setenv\("EBVERSIONPI", "6.28"\)',
r'setenv\("EBDEVELPI", pathJoin\(root, "easybuild/pi-3.14-gompi-2018a-easybuild-devel"\)\)',
]))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
defaulttxt = eb.make_module_extra().strip()
self.assertTrue(expected_default.match(defaulttxt),
"Pattern %s found in %s" % (expected_default.pattern, defaulttxt))
alttxt = eb.make_module_extra(altroot='/opt/software/tau/6.28', altversion='6.28').strip()
self.assertTrue(expected_alt.match(alttxt),
"Pattern %s found in %s" % (expected_alt.pattern, alttxt))
installver = '3.14-gompi-2018a'
# also check how absolute paths specified in modexself.contents = '\n'.join([
self.contents += "\nmodextrapaths = {'TEST_PATH_VAR': ['foo', '/test/absolute/path', 'bar']}"
self.contents += "\nmodextrapaths_append = {'TEST_PATH_VAR_APPEND': ['foo', '/test/absolute/path', 'bar']}"
self.writeEC()
ec = EasyConfig(self.eb_file)
eb = EasyBlock(ec)
eb.installdir = os.path.join(config.install_path(), 'pi', installver)
eb.check_readiness_step()
# absolute paths are not allowed by default
error_pattern = "Absolute path .* passed to update_paths which only expects relative paths"
self.assertErrorRegex(EasyBuildError, error_pattern, eb.make_module_step)
# allow use of absolute paths, and verify contents of module
self.contents += "\nallow_prepend_abs_path = True"
self.contents += "\nallow_append_abs_path = True"
self.writeEC()
ec = EasyConfig(self.eb_file)
eb = EasyBlock(ec)
eb.installdir = os.path.join(config.install_path(), 'pi', installver)
eb.check_readiness_step()
modrootpath = eb.make_module_step()
modpath = os.path.join(modrootpath, 'pi', installver)
if get_module_syntax() == 'Lua':
modpath += '.lua'
self.assertExists(modpath)
txt = read_file(modpath)
patterns = [
r"^prepend[-_]path.*TEST_PATH_VAR.*root.*foo",
r"^prepend[-_]path.*TEST_PATH_VAR.*/test/absolute/path",
r"^prepend[-_]path.*TEST_PATH_VAR.*root.*bar",
r"^append[-_]path.*TEST_PATH_VAR_APPEND.*root.*foo",
r"^append[-_]path.*TEST_PATH_VAR_APPEND.*/test/absolute/path",
r"^append[-_]path.*TEST_PATH_VAR_APPEND.*root.*bar",
]
for pattern in patterns:
self.assertTrue(re.search(pattern, txt, re.M), "Pattern '%s' found in: %s" % (pattern, txt))
def test_make_module_deppaths(self):
"""Test for make_module_deppaths"""
init_config(build_options={'silent': True})
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'gompi', 'version': '2018a'}",
'moddependpaths = "/path/to/mods"',
'dependencies = [',
" ('FFTW', '3.3.7'),",
']',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
eb.check_readiness_step()
eb.make_builddir()
eb.prepare_step()
if get_module_syntax() == 'Tcl':
use_load = '\n'.join([
'if { [ file isdirectory "/path/to/mods" ] } {',
' module use "/path/to/mods"',
'}',
])
elif get_module_syntax() == 'Lua':
use_load = '\n'.join([
'if isDir("/path/to/mods") then',
' prepend_path("MODULEPATH", "/path/to/mods")',
'end',
])
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
expected = use_load
self.assertEqual(eb.make_module_deppaths().strip(), expected)
def test_make_module_dep(self):
"""Test for make_module_dep"""
init_config(build_options={'silent': True})
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'gompi', 'version': '2018a'}",
'dependencies = [',
" ('FFTW', '3.3.7'),",
" ('OpenBLAS', '0.2.20', '', ('GCC', '6.4.0-2.28')),",
']',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
eb.check_readiness_step()
eb.make_builddir()
eb.prepare_step()
if get_module_syntax() == 'Tcl':
tc_load = '\n'.join([
"if { ![ is-loaded gompi/2018a ] } {",
" module load gompi/2018a",
"}",
])
fftw_load = '\n'.join([
"if { ![ is-loaded FFTW/3.3.7-gompi-2018a ] } {",
" module load FFTW/3.3.7-gompi-2018a",
"}",
])
lapack_load = '\n'.join([
"if { ![ is-loaded OpenBLAS/0.2.20-GCC-6.4.0-2.28 ] } {",
" module load OpenBLAS/0.2.20-GCC-6.4.0-2.28",
"}",
])
elif get_module_syntax() == 'Lua':
tc_load = '\n'.join([
'if not ( isloaded("gompi/2018a") ) then',
' load("gompi/2018a")',
'end',
])
fftw_load = '\n'.join([
'if not ( isloaded("FFTW/3.3.7-gompi-2018a") ) then',
' load("FFTW/3.3.7-gompi-2018a")',
'end',
])
lapack_load = '\n'.join([
'if not ( isloaded("OpenBLAS/0.2.20-GCC-6.4.0-2.28") ) then',
' load("OpenBLAS/0.2.20-GCC-6.4.0-2.28")',
'end',
])
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
expected = tc_load + '\n\n' + fftw_load + '\n\n' + lapack_load
self.assertEqual(eb.make_module_dep().strip(), expected)
# provide swap info for FFTW to trigger an extra 'unload FFTW'
unload_info = {
'FFTW/3.3.7-gompi-2018a': 'FFTW',
}
if get_module_syntax() == 'Tcl':
fftw_load = '\n'.join([
"if { ![ is-loaded FFTW/3.3.7-gompi-2018a ] } {",
" module unload FFTW",
" module load FFTW/3.3.7-gompi-2018a",
"}",
])
elif get_module_syntax() == 'Lua':
fftw_load = '\n'.join([
'if not ( isloaded("FFTW/3.3.7-gompi-2018a") ) then',
' unload("FFTW")',
' load("FFTW/3.3.7-gompi-2018a")',
'end',
])
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
expected = tc_load + '\n\n' + fftw_load + '\n\n' + lapack_load
self.assertEqual(eb.make_module_dep(unload_info=unload_info).strip(), expected)
def test_make_module_dep_hmns(self):
"""Test for make_module_dep under HMNS"""
test_ecs_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
all_stops = [x[0] for x in EasyBlock.get_steps()]
build_options = {
'check_osdeps': False,
'robot_path': [test_ecs_path],
'silent': True,
'valid_stops': all_stops,
'validate': False,
}
os.environ['EASYBUILD_MODULE_NAMING_SCHEME'] = 'HierarchicalMNS'
init_config(build_options=build_options)
self.setup_hierarchical_modules()
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'gompi', 'version': '2018a'}",
'dependencies = [',
" ('FFTW', '3.3.7'),",
']',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
eb.check_readiness_step()
eb.make_builddir()
eb.prepare_step()
# GCC, OpenMPI and hwloc modules should *not* be included in loads for dependencies
mod_dep_txt = eb.make_module_dep()
for mod in ['GCC/6.4.0-2.28', 'OpenMPI/2.1.2']:
regex = re.compile('load.*%s' % mod)
self.assertFalse(regex.search(mod_dep_txt), "Pattern '%s' found in: %s" % (regex.pattern, mod_dep_txt))
regex = re.compile('load.*FFTW/3.3.7')
self.assertTrue(regex.search(mod_dep_txt), "Pattern '%s' found in: %s" % (regex.pattern, mod_dep_txt))
def test_make_module_dep_of_dep_hmns(self):
"""Test for make_module_dep under HMNS with dependencies of dependencies"""
test_ecs_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
all_stops = [x[0] for x in EasyBlock.get_steps()]
build_options = {
'check_osdeps': False,
'robot_path': [test_ecs_path],
'valid_stops': all_stops,
'validate': False,
}
os.environ['EASYBUILD_MODULE_NAMING_SCHEME'] = 'HierarchicalMNS'
init_config(build_options=build_options)
self.setup_hierarchical_modules()
# GCC and OpenMPI extend $MODULEPATH; hwloc is a dependency of OpenMPI.
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'foss', 'version': '2018a'}",
'dependencies = [',
" ('GCC', '6.4.0-2.28', '', SYSTEM),"
" ('hwloc', '1.11.8', '', ('GCC', '6.4.0-2.28')),",
" ('OpenMPI', '2.1.2', '', ('GCC', '6.4.0-2.28')),"
']',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
eb.check_readiness_step()
# toolchain must be loaded such that dependencies are accessible
self.modtool.load(['foss/2018a'])
# GCC, OpenMPI and hwloc modules should *not* be included in loads for dependencies
mod_dep_txt = eb.make_module_dep()
for mod in ['GCC/6.4.0-2.28', 'OpenMPI/2.1.2', 'hwloc/1.11.8']:
regex = re.compile('load.*%s' % mod)
self.assertFalse(regex.search(mod_dep_txt), "Pattern '%s' found in: %s" % (regex.pattern, mod_dep_txt))
def test_det_iter_cnt(self):
"""Test det_iter_cnt method."""
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
# default value should be 1
self.assertEqual(eb.det_iter_cnt(), 1)
# adding a list of build deps shouldn't affect the default
self.contents += "\nbuilddependencies = [('one', '1.0'), ('two', '2.0'), ('three', '3.0')]"
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
self.assertEqual(eb.det_iter_cnt(), 1)
# list of configure options to iterate over affects iteration count
self.contents += "\nconfigopts = ['--one', '--two', '--three', '--four']"
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
self.assertEqual(eb.det_iter_cnt(), 4)
# different lengths for iterative easyconfig parameters mean trouble during validation of iterative parameters
self.contents += "\nbuildopts = ['FOO=one', 'FOO=two']"
self.writeEC()
error_pattern = "lists for iterated build should have same length"
self.assertErrorRegex(EasyBuildError, error_pattern, EasyConfig, self.eb_file)
def test_handle_iterate_opts(self):
"""Test for handle_iterate_opts method."""
testdir = os.path.abspath(os.path.dirname(__file__))
toy_ec = os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
test_ec = os.path.join(self.test_prefix, 'test.eb')
write_file(test_ec, read_file(toy_ec) + "\nconfigopts = ['--opt1 --anotheropt', '--opt2', '--opt3 --optbis']")
ec = process_easyconfig(test_ec)[0]
eb = get_easyblock_instance(ec)
# check initial state
self.assertEqual(eb.iter_idx, 0)
self.assertEqual(eb.iter_opts, {})
self.assertEqual(eb.cfg.iterating, False)
self.assertEqual(eb.cfg.iterate_options, [])
self.assertEqual(eb.cfg['configopts'], ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"])
expected_iter_opts = {'configopts': ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"]}
# once iteration mode is set, we're still in iteration #0
self.mock_stdout(True)
eb.handle_iterate_opts()
stdout = self.get_stdout()
self.mock_stdout(False)
self.assertEqual(eb.iter_idx, 0)
self.assertEqual(stdout, "== starting iteration #0 ...\n")
self.assertEqual(eb.cfg.iterating, True)
self.assertEqual(eb.cfg.iterate_options, ['configopts'])
self.assertEqual(eb.cfg['configopts'], "--opt1 --anotheropt")
self.assertEqual(eb.iter_opts, expected_iter_opts)
# when next iteration is start, iteration index gets bumped
self.mock_stdout(True)
eb.handle_iterate_opts()
stdout = self.get_stdout()
self.mock_stdout(False)
self.assertEqual(eb.iter_idx, 1)
self.assertEqual(stdout, "== starting iteration #1 ...\n")
self.assertEqual(eb.cfg.iterating, True)
self.assertEqual(eb.cfg.iterate_options, ['configopts'])
self.assertEqual(eb.cfg['configopts'], "--opt2")
self.assertEqual(eb.iter_opts, expected_iter_opts)
self.mock_stdout(True)
eb.handle_iterate_opts()
stdout = self.get_stdout()
self.mock_stdout(False)
self.assertEqual(eb.iter_idx, 2)
self.assertEqual(stdout, "== starting iteration #2 ...\n")
self.assertEqual(eb.cfg.iterating, True)
self.assertEqual(eb.cfg.iterate_options, ['configopts'])
self.assertEqual(eb.cfg['configopts'], "--opt3 --optbis")
self.assertEqual(eb.iter_opts, expected_iter_opts)
eb.post_iter_step()
self.assertEqual(eb.cfg.iterating, False)
self.assertEqual(eb.cfg['configopts'], ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"])
def test_extensions_step(self):
"""Test the extensions_step"""
init_config(build_options={'silent': True})