mesa_test 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mesa_test +34 -16
  3. data/lib/mesa_test.rb +199 -174
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6bc6d6b90192e1bfd95d973de84b1ad786cbbe6
4
- data.tar.gz: e5a9666a5fe7fd43f075e0b997f8d8896c202061
3
+ metadata.gz: 1b5dbc4e6e9d398d2025a0e33f1d4af8b2307d10
4
+ data.tar.gz: 3d2f461671275b93fac84f42b0480f9384da1737
5
5
  SHA512:
6
- metadata.gz: 6aa98742c529c1ac14b2565083da3598f7a91173300a3b08b9e621ea0ef32f6dfc4918227dc5e25feeadfaaf8dc0b0b15180f99ccfa22592324731902a65869e
7
- data.tar.gz: 7658a4c416bf42afb70ca55d70ed97b53d3379eec2557b6e9edd216ff99296e712ae21fe10014b8053debb9545e4d1a9c8f154aa063119b0e30e103e58ce7e7b
6
+ metadata.gz: 8d1e7371f07c36e6426f59bb2f24fca0fc43ea6d161bccad0b3bbd5decbebe3d721348a78c616e04776df083e8e07d6be7023a84a141cdea0da08acb18076a32
7
+ data.tar.gz: 0247ae3320af6c6a4b07c9528d3e1dd0a075f55018ece0d8f899bfcd120365986977281820235ab2dbb73c39df346aeaecaf4b6021ef61b8859088fbb4584abd
data/bin/mesa_test CHANGED
@@ -16,30 +16,37 @@ class MesaTest < Thor
16
16
  MesaTestSubmitter.new_from_config(config_file: config_file).setup
17
17
  end
18
18
 
19
- desc "test_one MESA_DIR TEST_CASE", "run, check, and submit one test case"
19
+ desc 'test_one MESA_DIR TEST_CASE', "run, check, and submit one test case"
20
20
  long_desc <<-LONGDESC
21
- Run and check TEST_CASE, which resides in MESA_DIR/star/test_suite. Then
22
- report results to MesaTestHub.
21
+ Run and check TEST_CASE, which resides in MESA_DIR/star/test_suite. Then
22
+ report results to MesaTestHub. TEST_CASE can also be an integer corresponding
23
+ to the line number of the test name in its do1_test_source file (or a
24
+ concatenated version of that file if no module is specified). Modules are
25
+ searched/concatenated in this order:
26
+
27
+ #{MesaTestCase.modules.map { |mod| ' ' + mod.to_s }.join(', ')}
23
28
 
24
29
  With --force option, skip confirmation of computer details, assuming values
25
30
  in ~/.mesa_test.yml are correct.
26
31
 
32
+ With --module option, select which module to search through, with the default
33
+ being "all" (search all modules in order). Example: --module=star.
34
+
27
35
  With --log option, save yml file of test results in test directory, on
28
36
  by default. Shut off with --no-log.
29
37
 
30
38
  With --submit option, upload results to MESATestHub. By default, this is on.
31
- To run without submission, use --no-submit.
39
+ To run without submission, use --no-submit.
32
40
  LONGDESC
33
- option :force, type: :boolean
41
+ option :force, type: :boolean, aliases: '-f'
34
42
  option :log, type: :boolean, default: true
43
+ option :module, type: :string, default: :all
35
44
  option :submit, type: :boolean, default: true
36
45
  def test_one(mesa_dir, test_case_name)
37
46
  if options[:submit]
38
47
  s = MesaTestSubmitter.new_from_config
39
48
  unless options[:force]
40
- unless s.confirm_computer_data
41
- s.setup
42
- end
49
+ s.setup unless s.confirm_computer_data
43
50
  end
44
51
 
45
52
  check_user_and_computer s
@@ -55,7 +62,8 @@ class MesaTest < Thor
55
62
  m.load_test_source_data
56
63
 
57
64
  # make sure the test case is valid
58
- t = m.find_test_case test_case_name: test_case_name
65
+ t = m.find_test_case(test_case_name: test_case_name,
66
+ mod: options[:module].downcase.to_sym)
59
67
  if t.nil?
60
68
  msg = "No such test case, #{test_case_name} found in any of "
61
69
  msg << MesaTestCase.modules.map do |mod|
@@ -84,7 +92,7 @@ class MesaTest < Thor
84
92
 
85
93
  desc "test_all MESA_DIR", "run, check, and submit all test cases"
86
94
  long_desc <<-LONGDESC
87
- Run and check all test cases residing in MESA_DIR/star/test_suite. Then
95
+ Run and check all test cases residing in MESA_DIR/star/test_suite. Then
88
96
  report results to MesaTestHub. Specifically, runs and checks all tests
89
97
  detailed in MESA_DIR/star/test_suite/do1_test_source.
90
98
 
@@ -98,7 +106,7 @@ class MesaTest < Thor
98
106
  With --submit option, upload results to MESATestHub. By default, this is on.
99
107
  To run without submission, use --no-submit.
100
108
  LONGDESC
101
- option :force, type: :boolean
109
+ option :force, type: :boolean, aliases: '-f'
102
110
  option :log, type: :boolean, default: true
103
111
  option :submit, type: :boolean, default: true
104
112
  def test_all(mesa_dir)
@@ -131,12 +139,21 @@ class MesaTest < Thor
131
139
 
132
140
  desc 'submit_one MESA_DIR TEST_CASE', 'submit one completed test case'
133
141
  long_desc <<-LONGDESC
134
- Load complete test case data from existing YAML file and submit to MESA
142
+ Load complete test case data from existing YAML file and submit to MESA.
143
+ TEST_CASE can also be an integer corresponding to the line number of the test
144
+ name in its do1_test_source file (or a concatenated version of that file if
145
+ no module is specified). Modules are searched/concatenated in this order:
146
+
147
+ #{MesaTestCase.modules.map { |mod| ' ' + mod.to_s }.join(", ") }
135
148
 
136
149
  With --force option, skip confirmation of computer details, assuming values
137
150
  in ~/.mesa_test.yml are correct.
151
+
152
+ With --module option, select which module to search through, with the default
153
+ being "all". Example: --module=star.
138
154
  LONGDESC
139
- option :force, type: :boolean
155
+ option :force, type: :boolean, aliases: '-f'
156
+ option :module, type: :string, aliases: '-m', default: 'all'
140
157
  def submit_one(mesa_dir, test_case_name)
141
158
  s = MesaTestSubmitter.new_from_config
142
159
  unless options[:force]
@@ -156,7 +173,8 @@ class MesaTest < Thor
156
173
  m.load_test_source_data
157
174
 
158
175
  # make sure the test case is valid
159
- t = m.find_test_case test_case_name: test_case_name
176
+ t = m.find_test_case(test_case_name: test_case_name,
177
+ mod: options[:module].downcase.to_sym)
160
178
  if t.nil?
161
179
  msg = "No such test case, #{test_case_name} found in any of "
162
180
  msg << MesaTestCase.modules.map do |mod|
@@ -184,7 +202,7 @@ class MesaTest < Thor
184
202
  With --force option, skip confirmation of computer details, assuming values
185
203
  in ~/.mesa_test.yml are correct.
186
204
  LONGDESC
187
- option :force, type: :boolean
205
+ option :force, type: :boolean, aliases: '-f'
188
206
  def submit_all(mesa_dir)
189
207
  s = MesaTestSubmitter.new_from_config
190
208
  unless options[:force]
@@ -249,7 +267,7 @@ class MesaTest < Thor
249
267
  read from ~/.mesa_test.yml.
250
268
  LONGDESC
251
269
  option :destroy, type: :boolean
252
- option :force, type: :boolean
270
+ option :force, type: :boolean, aliase: '-f'
253
271
  def install_and_test_all(version, mesa_dir)
254
272
  s = MesaTestSubmitter.new_from_config
255
273
  unless options[:force]
data/lib/mesa_test.rb CHANGED
@@ -8,9 +8,9 @@ require 'net/https'
8
8
  require 'thor'
9
9
  require 'json'
10
10
 
11
- class MesaDirError < StandardError; end
12
- class TestCaseDirError < StandardError; end
13
- class InvalidDataType < StandardError; end
11
+ MesaDirError = Class.new(StandardError)
12
+ TestCaseDirError = Class.new(StandardError)
13
+ InvalidDataType = Class.new(StandardError)
14
14
 
15
15
  class MesaTestSubmitter
16
16
  # set up config file for computer
@@ -379,16 +379,15 @@ class Mesa
379
379
  ## TEST SUITE METHODS
380
380
 
381
381
  def check_mod(mod)
382
- unless MesaTestCase.modules.include? mod
383
- raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " +
384
- MesaTestCase.modules.join(', ')
385
- end
382
+ return if MesaTestCase.modules.include? mod
383
+ raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " +
384
+ MesaTestCase.modules.join(', ')
386
385
  end
387
386
 
388
387
  def test_suite_dir(mod: nil)
389
388
  check_mod mod
390
389
  File.join(mesa_dir, mod.to_s, 'test_suite')
391
- end
390
+ end
392
391
 
393
392
  # load data from the `do1_test_source` file that gets used in a lot of
394
393
  # testing
@@ -401,8 +400,9 @@ class Mesa
401
400
  else
402
401
  check_mod mod
403
402
  # load data from the source file
404
- source_lines = IO.readlines(File.join(test_suite_dir(mod: mod),
405
- 'do1_test_source'))
403
+ source_lines = IO.readlines(
404
+ File.join(test_suite_dir(mod: mod), 'do1_test_source')
405
+ )
406
406
 
407
407
  # initialize data hash to empty hash and name array to empty array
408
408
  @test_data[mod] = {}
@@ -412,22 +412,22 @@ class Mesa
412
412
  # read through each line and find four data, name, success string, final
413
413
  # model name, and photo. Either of model name and photo can be "skip"
414
414
  source_lines.each do |line|
415
- no_skip = /^do_one (.+) "([^"]*)" "([^"]+)" (x?\d+)/
416
- one_skip = /^do_one (.+) "([^"]*)" "([^"]+)" skip/
417
- two_skip = /^do_one (.+) "([^"]*)" skip skip/
415
+ no_skip = /^do_one (.+)\s+"([^"]*)"\s+"([^"]+)"\s+(x?\d+)/
416
+ one_skip = /^do_one (.+)\s+"([^"]*)"\s+"([^"]+)"\s+skip/
417
+ two_skip = /^do_one (.+)\s+"([^"]*)"\s+skip\s+skip/
418
418
  found_test = false
419
419
  if line =~ no_skip
420
420
  found_test = true
421
- @test_data[mod][$1] = {success_string: $2, final_model: $3,
422
- photo: $4}
421
+ @test_data[mod][$1] = { success_string: $2, final_model: $3,
422
+ photo: $4}
423
423
  elsif line =~ one_skip
424
424
  found_test = true
425
- @test_data[mod][$1] = {success_string: $2, final_model: $3,
426
- photo: nil}
425
+ @test_data[mod][$1] = { success_string: $2, final_model: $3,
426
+ photo: nil }
427
427
  elsif line =~ two_skip
428
428
  found_test = true
429
- @test_data[mod][$1] = {success_string: $2, final_model: nil,
430
- photo: nil}
429
+ @test_data[mod][$1] = { success_string: $2, final_model: nil,
430
+ photo: nil }
431
431
  end
432
432
 
433
433
  if found_test
@@ -445,22 +445,12 @@ class Mesa
445
445
  end
446
446
  end
447
447
 
448
+ # can accept a number (in string form) as a name for indexed access
448
449
  def find_test_case(test_case_name: nil, mod: :all)
449
- if mod == :all
450
- # look through all loaded modules for desired test case name, return
451
- # FIRST found (assuming no name duplication across modules)
452
- @test_names.each do |this_mod, mod_names|
453
- if mod_names.include? test_case_name
454
- return @test_cases[this_mod][test_case_name]
455
- end
456
- end
457
- # didn't find any matches, return nil
458
- return nil
450
+ if /\A[0-9]+\z/ =~ test_case_name
451
+ find_test_case_by_number(test_number: test_case_name.to_i, mod: mod)
459
452
  else
460
- # module specified; check it and return the proper test case (may be nil
461
- # if the test case doesn't exist)
462
- check_mod mod
463
- @test_cases[mod][test_case_name]
453
+ find_test_case_by_name(test_case_name: test_case_name, mod: mod)
464
454
  end
465
455
  end
466
456
 
@@ -505,12 +495,6 @@ class Mesa
505
495
  end
506
496
  end
507
497
 
508
- # note that this only changes MESA_DIR for subprocesses launched from ruby
509
- # the old value of MESA_DIR will persist after the ruby process ends
510
- def set_mesa_dir
511
- ENV['MESA_DIR'] = mesa_dir
512
- end
513
-
514
498
  def installed?
515
499
  check_mesa_dir
516
500
  end
@@ -538,13 +522,13 @@ class Mesa
538
522
  test_names[mod].each do |test_name|
539
523
  test_case = test_cases[mod][test_name]
540
524
  res << {
541
- test_name: test_case.test_name,
542
- outcome: test_case.outcome,
543
- failure_type: test_case.failure_type,
544
- success_type: test_case.success_type,
545
- runtime_seconds: test_case.runtime_seconds,
546
- omp_num_threads: test_case.test_omp_num_threads,
547
- mesa_version: test_case.mesa_version
525
+ 'test_name' => test_case.test_name,
526
+ 'outcome' => test_case.outcome,
527
+ 'failure_type' => test_case.failure_type,
528
+ 'success_type' => test_case.success_type,
529
+ 'runtime_seconds' => test_case.runtime_seconds,
530
+ 'omp_num_threads' => test_case.test_omp_num_threads,
531
+ 'mesa_version' => test_case.mesa_version
548
532
  }
549
533
  end
550
534
  summary_file = File.join(test_suite_dir(mod: mod), 'test_summary.yml')
@@ -553,21 +537,81 @@ class Mesa
553
537
  end
554
538
  end
555
539
  end
540
+
541
+ def find_test_case_by_name(test_case_name: nil, mod: :all)
542
+ if mod == :all
543
+ # look through all loaded modules for desired test case name, return
544
+ # FIRST found (assuming no name duplication across modules)
545
+ @test_names.each do |this_mod, mod_names|
546
+ if mod_names.include? test_case_name
547
+ return @test_cases[this_mod][test_case_name]
548
+ end
549
+ end
550
+ # didn't find any matches, return nil
551
+ nil
552
+ else
553
+ # module specified; check it and return the proper test case (may be nil
554
+ # if the test case doesn't exist)
555
+ check_mod mod
556
+ @test_cases[mod][test_case_name]
557
+ end
558
+ end
559
+
560
+ def find_test_case_by_number(test_number: nil, mod: :all)
561
+ # this will be the index in the name array of the proper module of
562
+ # the desired test case
563
+ # input numbers are 1-indexed, but we'll fix that later
564
+ return nil if test_number < 1
565
+ i = test_number
566
+
567
+ if mod == :all
568
+ # search through each module in order
569
+ MesaTestCase.modules.each do |this_mod|
570
+ # if i is a valid index for names of this module, extract the proper
571
+ # test case taking into account that the given i is 1-indexed
572
+ if i <= @test_names[this_mod].length
573
+ # puts "i = #{i} <= #{@test_names[this_mod].length}"
574
+ # @test_names[this_mod].each_with_index do |test_name, i|
575
+ # puts sprintf("%-4d", i + 1) + test_name
576
+ # end
577
+ return find_test_case_by_name(
578
+ test_case_name: @test_names[this_mod][i - 1],
579
+ mod: this_mod
580
+ )
581
+ end
582
+ # index lies outside possible range for this module, move on to
583
+ # next module and decrement index by the number of test cases in this
584
+ # module
585
+ i -= @test_names[this_mod].length
586
+ end
587
+ # return nil if we never broke out of the loop
588
+ nil
589
+ else
590
+ # module was specified, so just hope things work out for the number
591
+ # should probably add a check that the index is actually in the array,
592
+ # but if you're using this feature, you probably know what you're doing,
593
+ # right? Right?
594
+ return find_test_case_by_name(
595
+ test_case_name: @test_names[mod][i - 1],
596
+ mod: mod
597
+ )
598
+ end
599
+ end
556
600
  end
557
601
 
558
602
  class MesaTestCase
559
603
  attr_reader :test_name, :mesa_dir, :mesa, :success_string, :final_model,
560
- :failure_msg, :success_msg, :photo, :runtime_seconds,
561
- :test_omp_num_threads, :mesa_version, :shell
604
+ :failure_msg, :success_msg, :photo, :runtime_seconds,
605
+ :test_omp_num_threads, :mesa_version, :shell
562
606
  attr_accessor :data_names, :data_types, :failure_type, :success_type,
563
- :outcome
607
+ :outcome
564
608
 
565
609
  def self.modules
566
- [:star, :binary]
610
+ %i[star binary]
567
611
  end
568
612
 
569
- def initialize(test: nil, mesa: nil, success_string: '',
570
- final_model: 'final.mod', photo: nil, mod: nil)
613
+ def initialize(test: nil, mesa: nil, success_string: '',
614
+ final_model: 'final.mod', photo: nil, mod: nil)
571
615
  @test_name = test
572
616
  @mesa_dir = mesa.mesa_dir
573
617
  @mesa = mesa
@@ -582,31 +626,30 @@ class MesaTestCase
582
626
  @test_omp_num_threads = 1
583
627
  unless MesaTestCase.modules.include? mod
584
628
  raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " +
585
- MesaTestCase.modules.join(', ')
586
- end
629
+ MesaTestCase.modules.join(', ')
630
+ end
587
631
  @mod = mod
588
632
  @failure_msg = {
589
633
  run_test_string: "#{test_name} failed: does not match test string",
590
- run_checksum: "#{test_name} run failed: checksum for #{final_model} " +
591
- "does not match after ./rn",
592
- run_diff: "#{test_name} run failed: diff #{final_model} " +
593
- "final_check.mod after ./rn",
634
+ run_checksum: "#{test_name} run failed: checksum for #{final_model} " \
635
+ 'does not match after ./rn',
636
+ run_diff: "#{test_name} run failed: diff #{final_model} " \
637
+ 'final_check.mod after ./rn',
594
638
  photo_file: "#{test_name} restart failed: #{photo} does not exist",
595
- photo_checksum: "#{test_name} restart failed: checksum for " +
639
+ photo_checksum: "#{test_name} restart failed: checksum for " \
596
640
  "#{final_model} does not match after ./re",
597
- photo_diff: "#{test_name} restart failed: diff #{final_model} " +
598
- "final_check.mod after ./re"
641
+ photo_diff: "#{test_name} restart failed: diff #{final_model} " \
642
+ 'final_check.mod after ./re'
599
643
  }
600
644
  @success_msg = {
601
- run_test_string: "#{test_name} run: found test string: " +
645
+ run_test_string: "#{test_name} run: found test string: " \
602
646
  "'#{success_string}'",
603
- run_checksum: "#{test_name} run: checksum for #{final_model} matches " +
604
- "after ./rn",
605
- photo_checksum: "#{test_name} restart: checksum for #{final_model} " +
606
- "matches after ./re #{photo}"
647
+ run_checksum: "#{test_name} run: checksum for #{final_model} matches " \
648
+ 'after ./rn',
649
+ photo_checksum: "#{test_name} restart: checksum for #{final_model} " \
650
+ 'matches after ./re #{photo}'
607
651
  }
608
652
 
609
-
610
653
  # validate stuff
611
654
  check_mesa_dir
612
655
  check_test_case
@@ -624,8 +667,8 @@ class MesaTestCase
624
667
  elsif @outcome == :fail
625
668
  false
626
669
  else
627
- raise TestCaseDirError, "Cannot determine pass/fail status of " +
628
- "#{test_name} yet."
670
+ raise TestCaseDirError, 'Cannot determine pass/fail status of ' \
671
+ '#{test_name} yet.'
629
672
  end
630
673
  end
631
674
 
@@ -640,14 +683,14 @@ class MesaTestCase
640
683
  def add_datum(datum_name, datum_type)
641
684
  unless data_types.include? datum_type.to_sym
642
685
  raise InvalidDataType, "Invalid data type: #{datum_type}. Must be one "\
643
- 'of ' + data_types.join(', ') + '.'
686
+ 'of ' + data_types.join(', ') + '.'
644
687
  end
645
688
  @data[datum_name] = datum_type
646
689
  @data_names << datum_name
647
690
  end
648
691
 
649
692
  def omp_num_threads
650
- return ENV['OMP_NUM_THREADS'].to_i || 1
693
+ ENV['OMP_NUM_THREADS'].to_i || 1
651
694
  end
652
695
 
653
696
  # based on $MESA_DIR/star/test_suite/each_test_clean, revision 10000
@@ -657,13 +700,13 @@ class MesaTestCase
657
700
  check_mesa_dir
658
701
  check_test_case
659
702
  in_dir do
660
- puts "./clean"
703
+ puts './clean'
661
704
  unless system('./clean')
662
- raise TestCaseDirError, "Encountered an error while running ./clean " +
705
+ raise TestCaseDirError, 'Encountered an error while running ./clean ' \
663
706
  "in #{Dir.getwd}."
664
707
  end
665
- shell.say "Removing all files from LOGS, LOGS1, LOGS2, photos, " +
666
- "photos1, and photos2", color = :blue
708
+ shell.say 'Removing all files from LOGS, LOGS1, LOGS2, photos, ' \
709
+ 'photos1, and photos2', color = :blue
667
710
  FileUtils.rm_f Dir.glob('LOGS/*')
668
711
  FileUtils.rm_f Dir.glob('LOGS1/*')
669
712
  FileUtils.rm_f Dir.glob('LOGS2/*')
@@ -671,21 +714,21 @@ class MesaTestCase
671
714
  FileUtils.rm_f Dir.glob('photos1/*')
672
715
  FileUtils.rm_f Dir.glob('photos2/*')
673
716
 
674
- shell.say "Removing files binary_history.data, out.txt, and " +
675
- "test_results.yml", color = :blue
717
+ shell.say 'Removing files binary_history.data, out.txt, and ' \
718
+ 'test_results.yml', color = :blue
676
719
  FileUtils.rm_f 'binary_history.data'
677
720
  FileUtils.rm_f 'out.txt'
678
- if File.directory? File.join('star_history','history_out')
721
+ if File.directory? File.join('star_history', 'history_out')
679
722
  shell.say 'Removing all files of the form history_out* from ' \
680
723
  'star_history', :blue
681
724
  FileUtils.rm_f Dir.glob(File.join('star_history', 'history_out', '*'))
682
725
  end
683
726
  if File.directory? File.join('star_profile', 'profiles_out')
684
- shell.say "Removing all files of the form profiles_out* from " +
685
- "star_profile", color = :blue
727
+ shell.say 'Removing all files of the form profiles_out* from ' \
728
+ 'star_profile', color = :blue
686
729
  FileUtils.rm_f Dir.glob(File.join('star_profile', 'profiles_out', '*'))
687
730
  end
688
- shell.say "Removing .running", color = :blue
731
+ shell.say 'Removing .running', color = :blue
689
732
  FileUtils.rm_f '.running'
690
733
  end
691
734
  end
@@ -707,42 +750,39 @@ class MesaTestCase
707
750
  # gets all parameters that would be submitted as well as computer
708
751
  # information and dumps to a yml file in the test case directory
709
752
  save_file = File.join(test_case_dir, 'test_results.yml')
710
- shell.say "Logging test results to #{save_file}...", color = :blue
753
+ shell.say "Logging test results to #{save_file}...", :blue
711
754
  res = {
712
- test_case: test_name,
713
- runtime_seconds: runtime_seconds,
714
- mesa_version: mesa_version,
715
- outcome: outcome,
716
- omp_num_threads: test_omp_num_threads,
717
- success_type: success_type,
718
- failure_type: failure_type
755
+ 'test_case' => test_name,
756
+ 'runtime_seconds' => runtime_seconds,
757
+ 'mesa_version' => mesa_version,
758
+ 'outcome' => outcome,
759
+ 'omp_num_threads' => test_omp_num_threads,
760
+ 'success_type' => success_type,
761
+ 'failure_type' => failure_type
719
762
  }
720
- File.open(save_file, 'w') { |f| f.write(YAML::dump(res)) }
721
- shell.say "Successfully saved results to file #{save_file}.",
722
- color = :green
723
- puts ''
763
+ File.open(save_file, 'w') { |f| f.write(YAML.dump(res)) }
764
+ shell.say "Successfully saved results to file #{save_file}.\n", :green
724
765
  end
725
766
 
726
767
  def load_results
727
768
  # loads all parameters from a previous test run, likely for submission
728
769
  # purposes
729
770
  load_file = File.join(test_case_dir, 'test_results.yml')
730
- shell.say "Loading data from #{load_file}...", color = :blue
731
- data = YAML::load(File.read(load_file))
732
- @runtime_seconds = data[:runtime_seconds]
733
- @mesa_version = data[:mesa_version]
734
- @outcome = data[:outcome].to_sym
735
- @test_omp_num_threads = data[:omp_num_threads]
736
- @success_type = data[:success_type]
737
- @failure_type = data[:failure_type]
738
- shell.say "Done loading data from #{load_file}.", color = :green
739
- puts ''
771
+ shell.say "Loading data from #{load_file}...", :blue
772
+ data = YAML.safe_load(File.read(load_file), [Symbol])
773
+ @runtime_seconds = data['runtime_seconds']
774
+ @mesa_version = data['mesa_version']
775
+ @outcome = data['outcome'].to_sym
776
+ @test_omp_num_threads = data['omp_num_threads']
777
+ @success_type = data['success_type']
778
+ @failure_type = data['failure_type']
779
+ shell.say "Done loading data from #{load_file}.\n", :green
740
780
  end
741
781
 
742
782
  private
743
783
 
744
784
  def data_types
745
- return [:float, :integer, :string, :boolean]
785
+ %i[float integer string boolean]
746
786
  end
747
787
 
748
788
  # cd into the test case directory, do something in a block, then cd back
@@ -754,33 +794,32 @@ class MesaTestCase
754
794
  # make sure that we can get to the test case directory. Throw an exception
755
795
  # if we cannot
756
796
  def check_test_case
757
- unless File.directory? test_case_dir
758
- raise TestCaseDirError, "No such test case: #{test_case_dir}."
759
- end
797
+ return if File.directory? test_case_dir
798
+ raise TestCaseDirError, "No such test case: #{test_case_dir}."
760
799
  end
761
800
 
762
801
  # verify that mesa_dir is valid by checking for version number and test_suite
763
802
  # directory
764
803
  def check_mesa_dir
765
- is_valid = File.exist?(File.join(mesa_dir, 'data', 'version_number')) and
766
- File.directory?(test_suite_dir)
804
+ is_valid = File.exist?(File.join(mesa_dir, 'data', 'version_number')) &&
805
+ File.directory?(test_suite_dir)
767
806
  raise MesaDirError, "Invalid MESA dir: #{mesa_dir}" unless is_valid
768
807
  end
769
808
 
770
809
  # append message to log file
771
810
  def log_message(msg, color = nil, log_file = 'out.txt')
772
811
  if color.nil?
773
- shell.say msg
812
+ shell.say(msg)
774
813
  else
775
- shell.say msg, color = color
814
+ shell.say(msg, color)
776
815
  end
777
- File.open('out.txt', 'a') { |f| f.puts(msg) }
816
+ File.open(log_file, 'a') { |f| f.puts(msg) }
778
817
  end
779
818
 
780
819
  # write failure message to log file
781
820
  def write_failure_message
782
- msg = "******************** #{failure_msg[@failure_type]} " +
783
- "********************"
821
+ msg = "******************** #{failure_msg[@failure_type]} " \
822
+ '********************'
784
823
  log_message(msg, :red)
785
824
  end
786
825
 
@@ -796,7 +835,7 @@ class MesaTestCase
796
835
  @failure_type = failure_type
797
836
  @outcome = :fail
798
837
  write_failure_message
799
- return false
838
+ false
800
839
  end
801
840
 
802
841
  # used as return value for run or photo test. Logs data to text file, and
@@ -805,7 +844,7 @@ class MesaTestCase
805
844
  @success_type = success_type
806
845
  @outcome = :pass
807
846
  write_success_msg(success_type)
808
- return true
847
+ true
809
848
  end
810
849
 
811
850
  def check_run
@@ -820,50 +859,41 @@ class MesaTestCase
820
859
  run_finish = Time.now
821
860
  @runtime_seconds = (run_finish - run_start).to_i
822
861
  shell.say("Finished with ./rn; runtime = #{@runtime_seconds} seconds.",
823
- :blue)
862
+ :blue)
824
863
  append_and_rm_err
825
864
 
826
-
827
865
  # look for success text
828
866
  success = true
829
867
  File.open('out.txt', 'r') do |f|
830
868
  success = !f.read.downcase.scan(success_string.downcase).empty?
831
869
  end
832
870
  # bail if there was no test string found
833
- unless success
834
- return fail_test(:run_test_string)
835
- end
871
+ return fail_test(:run_test_string) unless success
872
+
873
+ # no final model to check, and we already found the test string, so pass
874
+ return succeed(:run_test_string) unless final_model
836
875
 
837
876
  # additional checks for final model, if it is specified
838
- if final_model
839
- # update checks after new run (Bill W. doesn't know what this does)
840
- # (is this supposed to mark things as passed? The original function
841
- # just has a standard "return" statement, which I interpret as passing)
842
- if ENV.include? 'UPDATE_CHECKS'
843
- system("md5sum \"#{final_model}\" > checks.md5")
844
- puts "md5sum \"#{final_model}\" > checks.md5"
845
- FileUtils.cp final_model 'final_check.mod'
846
- return true
847
- end
877
+ # update checks after new run (Bill W. doesn't know what this does)
878
+ # (is this supposed to mark things as passed? The original function
879
+ # just has a standard "return" statement, which I interpret as passing)
880
+ if ENV.include? 'UPDATE_CHECKS'
881
+ system("md5sum \"#{final_model}\" > checks.md5")
882
+ puts "md5sum \"#{final_model}\" > checks.md5"
883
+ FileUtils.cp final_model 'final_check.mod'
884
+ return true
885
+ end
848
886
 
849
- # display runtime message
850
- puts IO.readlines('out.txt').select { |line| line.scan(/runtime/i) }[-1]
851
-
852
- # check that final model matches
853
- puts './ck >& final_check_diff.txt'
854
- if not system('./ck >& final_check_diff.txt')
855
- return fail_test(:run_checksum)
856
- elsif File.exist? 'final_check_diff.txt' and
857
- not File.read('final_check_diff.txt').empty?
858
- return fail_test(:run_diff)
859
- elsif File.exist? final_model
860
- return succeed(:run_checksum)
861
- end
887
+ # display runtime message
888
+ puts IO.readlines('out.txt').select { |line| line.scan(/runtime/i) }[-1]
862
889
 
863
- # no final model to check, and we already found the test string, so pass
864
- else
865
- return succeed(:run_test_string)
866
- end
890
+ # check that final model matches
891
+ puts './ck >& final_check_diff.txt'
892
+ return fail_test(:run_checksum) unless
893
+ system('./ck >& final_check_diff.txt')
894
+ return fail_test(:run_diff) if File.exist?('final_check_diff.txt') &&
895
+ !File.read('final_check_diff.txt').empty?
896
+ return succeed(:run_checksum) if File.exist? final_model
867
897
  end
868
898
 
869
899
  # prepare for and do restart, check results, and return pass/fail status
@@ -872,8 +902,8 @@ class MesaTestCase
872
902
  return unless photo
873
903
 
874
904
  # check that photo file actually exists
875
- unless File.exist?(File.join('photos', photo)) or
876
- File.exist?(File.join('photos1', photo))
905
+ unless File.exist?(File.join('photos', photo)) ||
906
+ File.exist?(File.join('photos1', photo))
877
907
  return fail_test(:photo_file)
878
908
  end
879
909
 
@@ -886,15 +916,13 @@ class MesaTestCase
886
916
  append_and_rm_err
887
917
 
888
918
  # check that final model matches
889
- puts "./ck >& final_check_diff.txt"
890
- if not system("./ck >& final_check_diff.txt")
891
- return fail_test(:photo_checksum)
892
- elsif File.exist?('final_check_diff.txt') and not
893
- File.read('final_check_diff.txt').empty?
894
- return fail_test(:photo_diff)
895
- else
896
- return succeed(:photo_checksum)
897
- end
919
+ puts './ck >& final_check_diff.txt'
920
+ return fail_test(:photo_checksum) unless
921
+ system('./ck >& final_check_diff.txt')
922
+ return fail_test(:photo_diff) if
923
+ File.exist?('final_check_diff.txt') &&
924
+ !File.read('final_check_diff.txt').empty?
925
+ succeed(:photo_checksum)
898
926
  end
899
927
 
900
928
  def build_and_run
@@ -923,29 +951,29 @@ class MesaTestCase
923
951
  end
924
952
 
925
953
  def display_errors(err_contents)
926
- return unless err_contents.strip.empty?
954
+ return if err_contents.strip.empty?
927
955
  shell.say("\nERRORS", :red)
928
956
  puts err_contents
929
- shell.say("END OF ERRORS", :red)
957
+ shell.say('END OF ERRORS', :red)
930
958
  end
931
959
 
932
960
  def log_errors(err_contents, outfile)
961
+ return if err_contents.strip.empty?
933
962
  File.open(outfile, 'a') { |f_out| f_out.write(err_contents) }
934
- shell.say("appended to #{outfile})\n", :red)
963
+ shell.say("appended to #{outfile}\n", :red)
935
964
  end
936
965
 
937
966
  def simple_clean
938
967
  puts './clean'
939
- unless system('./clean')
940
- raise TestCaseDirError, 'Encountered an error when running `clean` in ' +
941
- "#{Dir.getwd} for test case #{test_name}."
942
- end
968
+ return if system('./clean')
969
+ raise TestCaseDirError, 'Encountered an error when running `clean` in ' \
970
+ "#{Dir.getwd} for test case #{test_name}."
943
971
  end
944
972
 
945
973
  def mk
946
974
  puts './mk > mk.txt'
947
975
  unless system('./mk > mk.txt')
948
- raise TestCaseDirError, 'Encountered an error when running `mk` in ' +
976
+ raise TestCaseDirError, 'Encountered an error when running `mk` in ' \
949
977
  "#{Dir.getwd} for test case #{test_name}."
950
978
  end
951
979
  FileUtils.rm 'mk.txt'
@@ -985,13 +1013,11 @@ end
985
1013
  # directory
986
1014
  def visit_dir(new_dir)
987
1015
  cwd = Dir.getwd
988
- shell.say "Leaving #{cwd}", :blue
989
- puts ""
1016
+ shell.say "Leaving #{cwd}\n", :blue
990
1017
  shell.say "Entering #{new_dir}.", :blue
991
1018
  Dir.chdir(new_dir)
992
1019
  yield if block_given?
993
- shell.say "Leaving #{new_dir}", :blue
994
- puts ""
1020
+ shell.say "Leaving #{new_dir}\n", :blue
995
1021
  shell.say "Entering #{cwd}.", :blue
996
1022
  Dir.chdir(cwd)
997
1023
  end
@@ -1004,18 +1030,17 @@ def generate_seeds_rb(mesa_dir, outfile)
1004
1030
  f.puts 'test_cases = TestCase.create!('
1005
1031
  f.puts ' ['
1006
1032
  m.test_names.each do |test_case_name|
1007
- f.puts " {"
1033
+ f.puts ' {'
1008
1034
  f.puts " name: '#{test_case_name}',"
1009
1035
  f.puts " version_added: #{m.version_number},"
1010
1036
  # no comma on last one
1011
1037
  if test_case_name == m.test_names[-1]
1012
1038
  f.puts(' }')
1013
1039
  else
1014
- f.puts(' }')
1040
+ f.puts(' },')
1015
1041
  end
1016
1042
  end
1017
1043
  f.puts ' ]'
1018
1044
  f.puts ')'
1019
1045
  end
1020
1046
  end
1021
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mesa_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Wolf