openstudio_measure_tester 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,270 @@
1
+ module OpenStudioMeasureTester
2
+ # The runner is the workhorse that executes the tests. This class does not invoke Rake and can be run
3
+ # as a library method or as a CLI call
4
+ class Runner
5
+ # Initialize the runner
6
+ #
7
+ # @param base_dir [string] Base dir, measures will be recursively tested from this location. Results will be here too.
8
+ def initialize(base_dir)
9
+ @base_dir = base_dir
10
+
11
+ puts "Base dir is #{base_dir}"
12
+ end
13
+
14
+ # Create and return the location where the tests results need to be stored
15
+ def test_results_dir
16
+ dir = "#{@base_dir}/test_results"
17
+ FileUtils.mkdir_p dir unless Dir.exist? dir
18
+
19
+ return dir
20
+ end
21
+
22
+ # Run ERB to create the dashboard
23
+ def dashboard
24
+ template = OpenStudioMeasureTester::Dashboard.new(test_results_dir)
25
+ template.render
26
+ end
27
+
28
+ # Prepare the current directory and the root directory to remove old test results before running
29
+ # the new tests
30
+ #
31
+ # @param orig_results_dir [string] Location on where there results of minitest/coverage will be stored.
32
+ def pre_process_minitest(orig_results_dir)
33
+ puts "Current directory is #{@base_dir}"
34
+ puts "Pre-processed tests run data in #{orig_results_dir}"
35
+ puts "Test results will be stored in: #{test_results_dir}"
36
+
37
+ # There is a bunch of moving that needs to happen with coverage/minitest...
38
+ FileUtils.rm_rf "#{orig_results_dir}/coverage" if Dir.exist? "#{orig_results_dir}/coverage"
39
+ FileUtils.rm_rf "#{@base_dir}/coverage" if Dir.exist? "#{@base_dir}/coverage"
40
+ FileUtils.rm_rf "#{test_results_dir}/coverage" if Dir.exist? "#{test_results_dir}/coverage"
41
+
42
+ FileUtils.rm_rf "#{orig_results_dir}/minitest" if Dir.exist? "#{orig_results_dir}/minitest"
43
+ FileUtils.rm_rf "#{@base_dir}/minitest" if Dir.exist? "#{@base_dir}/minitest"
44
+ FileUtils.rm_rf "#{test_results_dir}/minitest" if Dir.exist? "#{test_results_dir}/minitest"
45
+
46
+ FileUtils.rm_rf "#{orig_results_dir}/test" if Dir.exist? "#{orig_results_dir}/test"
47
+ FileUtils.rm_rf "#{@base_dir}/test" if Dir.exist? "#{@base_dir}/test"
48
+ # remove the test directory if it is empty (size == 2 for . and ..)
49
+ if Dir.exist?("#{test_results_dir}/test") && Dir.entries("#{test_results_dir}/test").size == 2
50
+ FileUtils.rm_rf "#{test_results_dir}/test"
51
+ end
52
+ FileUtils.rm_rf "#{test_results_dir}/minitest" if Dir.exist? "#{test_results_dir}/minitest"
53
+
54
+ # Create the test_results directory to store all the results
55
+ return test_results_dir
56
+ end
57
+
58
+ # Rubocop stores the results (for now) in the test_results directory
59
+ def pre_process_rubocop
60
+ # copy over the .rubocop.yml file into the root directory of where this is running.
61
+ shared_rubocop_file = File.expand_path('../../.rubocop.yml', File.dirname(__FILE__))
62
+ dest_file = "#{File.expand_path(@base_dir)}/.rubocop.yml"
63
+ if shared_rubocop_file != dest_file
64
+ FileUtils.copy(shared_rubocop_file, dest_file)
65
+ end
66
+
67
+ puts "Current directory is #{@base_dir}"
68
+ # puts "Pre-processing tests run in #{@base_dir}"
69
+ puts "Test results will be stored in: #{test_results_dir}"
70
+
71
+ FileUtils.rm_rf "#{test_results_dir}/rubocop" if Dir.exist? "#{test_results_dir}/rubocop"
72
+ FileUtils.rm_rf "#{@base_dir}/rubocop" if Dir.exist? "#{@base_dir}/rubocop"
73
+
74
+ # Call the test_results dir to create the directory and return it as a string.
75
+ return test_results_dir
76
+ end
77
+
78
+ # Post process the various results and save them into the base_dir
79
+ #
80
+ # @param original_results_directory [string] Location of the results from coverag and minitest
81
+ def post_process_results(original_results_directory = nil)
82
+ puts " ========================= Starting Results Post Process ================================"
83
+ puts "Current directory: #{@base_dir}"
84
+ puts "Test results will be stored in: #{test_results_dir}"
85
+
86
+ results = OpenStudioMeasureTester::OpenStudioTestingResult.new(@base_dir, test_results_dir, original_results_directory)
87
+ results.save_results # one single file for dashboard
88
+
89
+ # call the create dashboard command now that we have results
90
+ dashboard
91
+
92
+ # return the results exit code
93
+ return results.exit_code
94
+ end
95
+
96
+ # OpenStudio style check preparation
97
+ #
98
+ # @param base_dir [string] Base directory where results will be stored. If called from rake it is the location of the Rakefile.
99
+ # @param measures_dir [string] The current working directory. If called from Rake it is the active directory.
100
+ def pre_process_style
101
+ puts "Current directory is #{@base_dir}"
102
+ puts "Test results will be stored in: #{test_results_dir}"
103
+
104
+ FileUtils.rm_rf "#{test_results_dir}/openstudio_style" if Dir.exist? "#{test_results_dir}/openstudio_style"
105
+ FileUtils.rm_rf "#{@base_dir}/openstudio_style" if Dir.exist? "#{@base_dir}/openstudio_style"
106
+
107
+ # Call the test_results dir to create the directory and return it as a string.
108
+ return test_results_dir
109
+ end
110
+
111
+ def run_style(skip_post_process)
112
+ puts " ========================= Starting Run for OpenStudio Style ================================"
113
+ pre_process_style
114
+
115
+ # Run the style tests
116
+ style = OpenStudioMeasureTester::OpenStudioStyle.new(test_results_dir, "#{@base_dir}/**/measure.rb")
117
+ style.save_results
118
+
119
+ if skip_post_process
120
+ return true
121
+ else
122
+ return post_process_results
123
+ end
124
+ end
125
+
126
+ def run_rubocop(skip_post_process, auto_correct = false)
127
+ puts " ========================= Starting Run for Rubocop ================================"
128
+ pre_process_rubocop
129
+
130
+ rubocop_results_file = "#{test_results_dir}/rubocop/rubocop-results.xml"
131
+ # The documentation on running RuboCop from the Ruby source is not really helpful. I reversed engineered this
132
+ # by putting in puts statements in my local install rubocop gem to see how options were passed.
133
+ #
134
+ # https://github.com/bbatsov/rubocop/blob/9bdbaba9dcaa3dedad5e857b440d0d8988b806f5/lib/rubocop/runner.rb#L25
135
+ require 'rubocop/formatter/checkstyle_formatter'
136
+ options = {
137
+ # out and output_path do not actually save the results, has to be appended after the formatter.
138
+ # out: 'junk.xml',
139
+ # output_path: 'junk.xml',
140
+ auto_correct: auto_correct,
141
+ color: false,
142
+ formatters: ['simple', ['RuboCop::Formatter::CheckstyleFormatter', rubocop_results_file]]
143
+ }
144
+
145
+ # Load in the ruby config from the root directory
146
+ config_store = RuboCop::ConfigStore.new
147
+ # puts "Searching for .rubocop.yml recursively from #{@base_dir}"
148
+ config_store.for(@base_dir)
149
+
150
+ rc_runner = RuboCop::Runner.new(options, config_store)
151
+ rc_runner.run(["#{File.expand_path(@base_dir)}/**/*.rb"])
152
+
153
+ if skip_post_process
154
+ return true
155
+ else
156
+ return post_process_results
157
+ end
158
+ end
159
+
160
+ # The results of the coverage and minitest are stored in the root of the directory structure (if Rake)
161
+ def run_test(skip_post_process, original_results_directory, run_coverage = true)
162
+ puts " ========================= Starting Run for Minitest (and coverage) ============================"
163
+ # not sure what @base_dir has to be right now
164
+ pre_process_minitest(original_results_directory)
165
+
166
+ # Specify the minitest reporters
167
+ require 'minitest/reporters'
168
+ Minitest::Reporters.use! [
169
+ Minitest::Reporters::HtmlReporter.new,
170
+ Minitest::Reporters::JUnitReporter.new
171
+ ]
172
+
173
+ if run_coverage
174
+ # Load in the coverage before loading the test files
175
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
176
+ [
177
+ SimpleCov::Formatter::HTMLFormatter
178
+ ]
179
+ )
180
+
181
+ SimpleCov.start do
182
+ # Track all files inside of @base_dir
183
+ track_files "#{@base_dir}/**/*.rb"
184
+
185
+ use_merging false
186
+
187
+ # Exclude all files outside of @base_dir
188
+ root_filter = nil
189
+ add_filter do |src|
190
+ root_filter ||= /\A#{Regexp.escape(@base_dir + File::SEPARATOR)}/io
191
+ src.filename !~ root_filter
192
+ end
193
+ end
194
+ end
195
+
196
+ num_tests = 0
197
+ Dir["#{@base_dir}/**/*_Test.rb", "#{@base_dir}/**/*_test.rb"].uniq.each do |file|
198
+ puts "Loading file for testing: #{file}"
199
+ load File.expand_path(file)
200
+ num_tests += 1
201
+ end
202
+
203
+ if num_tests < 1
204
+ puts 'No tests found'
205
+
206
+ if run_coverage
207
+ # This doesn't seem to be working, it doesn't save off the .resultset.json.
208
+ begin
209
+ simplecov_exit_status = SimpleCov.end_now
210
+ rescue NoMethodError
211
+ # in case using some other version of SimpleCov
212
+ SimpleCov.set_exit_exception
213
+ exit_status = SimpleCov.exit_status_from_exception
214
+ SimpleCov.result.format!
215
+ simplecov_exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
216
+ end
217
+ end
218
+
219
+ if skip_post_process
220
+ return true
221
+ else
222
+ return post_process_results(original_results_directory)
223
+ end
224
+ else
225
+ puts "Inspected #{num_tests} tests"
226
+ end
227
+
228
+ # Now call run on the loaded files. Note that the Minitest.autorun method has been nulled out in the
229
+ # openstudio_measure_tester.rb file, so it will not run.
230
+ begin
231
+ Minitest.run ['--verbose']
232
+ rescue StandardError => exception
233
+ puts
234
+ puts '!!!!!!!!!!!!!!!!!!!!! Minitest Error Occurred !!!!!!!!!!!!!!!!!!!!!'
235
+ puts exception.message
236
+ puts exception.backtrace
237
+ puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
238
+ puts
239
+ end
240
+
241
+ # Shutdown SimpleCov and collect results
242
+ # This will set SimpleCov.running to false which will prevent from running again at_exit
243
+ if run_coverage
244
+ begin
245
+ simplecov_exit_status = SimpleCov.end_now
246
+ rescue NoMethodError
247
+ # in case using some other version of SimpleCov
248
+ SimpleCov.set_exit_exception
249
+ exit_status = SimpleCov.exit_status_from_exception
250
+ SimpleCov.result.format!
251
+ simplecov_exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
252
+ end
253
+ end
254
+
255
+ if skip_post_process
256
+ return true
257
+ else
258
+ return post_process_results(original_results_directory)
259
+ end
260
+ end
261
+
262
+ def run_all(original_results_directory)
263
+ # do not run coverage now since the at_exit is causing exceptions when running (GC?)
264
+ run_rubocop(true)
265
+ run_style(true)
266
+ run_test(true, original_results_directory, false)
267
+ post_process_results(original_results_directory)
268
+ end
269
+ end
270
+ end
@@ -27,5 +27,5 @@
27
27
  ########################################################################################################################
28
28
 
29
29
  module OpenStudioMeasureTester
30
- VERSION = '0.1.4'.freeze
30
+ VERSION = '0.1.5'.freeze
31
31
  end
@@ -6,7 +6,7 @@ require 'openstudio_measure_tester/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'openstudio_measure_tester'
8
8
  spec.version = OpenStudioMeasureTester::VERSION
9
- spec.authors = ['Nicholas Long']
9
+ spec.authors = ['Nicholas Long', 'Katherine Fleming', 'Daniel Macumber', 'Robert Guglielmetti']
10
10
  spec.email = ['nicholas.long@nrel.gov']
11
11
 
12
12
  spec.summary = 'Testing framework for OpenStudio measures'
@@ -20,11 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency 'bundler', '1.16.1'
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
24
  spec.add_development_dependency 'rspec', '3.7.0'
25
25
 
26
- spec.add_dependency 'activesupport', '5.1.6'
27
- spec.add_dependency 'ci_reporter_minitest', '1.0.0'
28
26
  spec.add_dependency 'git', '1.3.0'
29
27
  spec.add_dependency 'minitest', '5.4.3'
30
28
  spec.add_dependency 'minitest-reporters', '1.2.0'
metadata CHANGED
@@ -1,29 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstudio_measure_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Long
8
+ - Katherine Fleming
9
+ - Daniel Macumber
10
+ - Robert Guglielmetti
8
11
  autorequire:
9
12
  bindir: exe
10
13
  cert_chain: []
11
- date: 2018-04-19 00:00:00.000000000 Z
14
+ date: 2018-06-13 00:00:00.000000000 Z
12
15
  dependencies:
13
16
  - !ruby/object:Gem::Dependency
14
17
  name: bundler
15
18
  requirement: !ruby/object:Gem::Requirement
16
19
  requirements:
17
- - - '='
20
+ - - "~>"
18
21
  - !ruby/object:Gem::Version
19
- version: 1.16.1
22
+ version: '1.16'
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '='
27
+ - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: 1.16.1
29
+ version: '1.16'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
@@ -38,34 +41,6 @@ dependencies:
38
41
  - - '='
39
42
  - !ruby/object:Gem::Version
40
43
  version: 3.7.0
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 5.1.6
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 5.1.6
55
- - !ruby/object:Gem::Dependency
56
- name: ci_reporter_minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: 1.0.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 1.0.0
69
44
  - !ruby/object:Gem::Dependency
70
45
  name: git
71
46
  requirement: !ruby/object:Gem::Requirement
@@ -173,6 +148,7 @@ extra_rdoc_files: []
173
148
  files:
174
149
  - ".gitignore"
175
150
  - ".rspec"
151
+ - ".rubocop-http---s3-amazonaws-com-openstudio-resources-styles-rubocop-yml"
176
152
  - ".rubocop.yml"
177
153
  - ".travis.yml"
178
154
  - CHANGELOG.md
@@ -181,6 +157,7 @@ files:
181
157
  - README.md
182
158
  - Rakefile
183
159
  - bin/console
160
+ - bin/run_measure_tests
184
161
  - bin/setup
185
162
  - dashboard/css/bootstrap-grid.css
186
163
  - dashboard/css/bootstrap-grid.min.css
@@ -201,8 +178,8 @@ files:
201
178
  - lib/openstudio_measure_tester/openstudio_testing_result.rb
202
179
  - lib/openstudio_measure_tester/rake_task.rb
203
180
  - lib/openstudio_measure_tester/rubocop_result.rb
181
+ - lib/openstudio_measure_tester/runner.rb
204
182
  - lib/openstudio_measure_tester/templates/dashboard.html.erb
205
- - lib/openstudio_measure_tester/test_helper.rb
206
183
  - lib/openstudio_measure_tester/version.rb
207
184
  - openstudio_measure_tester.gemspec
208
185
  homepage: https://openstudio.nrel.gov
@@ -1,43 +0,0 @@
1
- ########################################################################################################################
2
- # OpenStudio(R), Copyright (c) 2008-2018, Alliance for Sustainable Energy, LLC. All rights reserved.
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5
- # following conditions are met:
6
- #
7
- # (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8
- # disclaimer.
9
- #
10
- # (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11
- # following disclaimer in the documentation and/or other materials provided with the distribution.
12
- #
13
- # (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote
14
- # products derived from this software without specific prior written permission from the respective party.
15
- #
16
- # (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative
17
- # works may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without
18
- # specific prior written permission from Alliance for Sustainable Energy, LLC.
19
- #
20
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
- # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR
23
- # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
- # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- ########################################################################################################################
28
-
29
- $coverage_started = false
30
- unless $coverage_started
31
- require 'simplecov'
32
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
33
- [
34
- SimpleCov::Formatter::HTMLFormatter
35
- ]
36
- )
37
-
38
- SimpleCov.start
39
- $coverage_started = true
40
- end
41
-
42
- require 'minitest/reporters'
43
- Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new, Minitest::Reporters::HtmlReporter.new]