openstudio_measure_tester 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6d3ffe474ac0b1753ef5c49ef7ee7e959826291
4
- data.tar.gz: f611d397387097b16f4e972d2cdf6fa940e811be
3
+ metadata.gz: 3c701b7ee1c908a30adce739d1ef8e30a1b804b1
4
+ data.tar.gz: 2520f8964fdeb8ea55df34d743676c56732dca46
5
5
  SHA512:
6
- metadata.gz: 6cfb89cf542468159aedfeda87cd1814a33a87ab5ae91cb71147e1a474beb549e50b5250a9c2e0c24de775adbffe19a38f509258a977e31763d7ee50e2a5b02a
7
- data.tar.gz: 4cbac4111f187421793eebaae9c65599487991daa2e602009aa1f4a1bd23606f53989e237b4c0135e7253546dfda596ac3da6bc53cdceecd3e515b6b3b923ecd
6
+ metadata.gz: c419ccadea649d88baef183cb66780178dfb3b3a70be6077c08c7f1d7ca8a95657105f1a6a9ae4444e1ffc189df5c9d74ce0d3abc1f03f01783849476dde7369
7
+ data.tar.gz: 7ec95e37072d0f1af63b8435d1eb283a2a9eb387a02ba0b0e544fc9f460a1ad4c177e618754caedf12d89975966766f046eb3c299f38c21cb7ab1ca6a506db81
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /.idea/
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
@@ -15,10 +16,12 @@
15
16
  # rspec failure tracking
16
17
  .rspec_status
17
18
  rspec.html
18
- .idea/
19
19
  Gemfile.lock
20
- .rubocop-https*
20
+ **/.rubocop-http*
21
21
  rubocop-results.xml
22
+ !spec/files/rubocop-results.xml
23
+ spec/files/rubocop/rubocop.json
24
+ spec/**/.rubocop.yml
22
25
 
23
26
  # mac and rbenv stuff
24
27
  .DS_Store
data/.rubocop.yml CHANGED
@@ -2,4 +2,4 @@ AllCops:
2
2
  Exclude:
3
3
  - 'spec/test_measures/**/*'
4
4
  inherit_from:
5
- - https://raw.githubusercontent.com/NREL/OpenStudio-resources/develop/styles/rubocop.yml
5
+ - http://s3.amazonaws.com/openstudio-resources/styles/rubocop.yml
data/.travis.yml CHANGED
@@ -1,14 +1,21 @@
1
1
  sudo: true
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.4
4
+ - 2.2.4
5
5
  matrix:
6
6
  include:
7
- - env: OPENSTUDIO_VERSION=2.4.0 && OPENSTUDIO_SHA=f58a3e1808 && RUBYLIB=/usr/Ruby
8
- before_install: gem install bundler -v 1.16.1
7
+ - env: OPENSTUDIO_VERSION=2.4.0 && OPENSTUDIO_SHA=f58a3e1808 && RUBYLIB=/usr/Ruby
8
+ - env: OPENSTUDIO_VERSION=2.5.1 && OPENSTUDIO_SHA=4f268e2854 && RUBYLIB=/usr/Ruby
9
+ before_install: gem install bundler -v 1.16.2
9
10
  before_script:
10
- - curl -sLO https://raw.githubusercontent.com/NREL/OpenStudio-server/develop/docker/deployment/scripts/install_openstudio.sh
11
- - chmod +x install_openstudio.sh
12
- - sudo ./install_openstudio.sh $OPENSTUDIO_VERSION $OPENSTUDIO_SHA
11
+ - curl -sLO https://raw.githubusercontent.com/NREL/OpenStudio-server/develop/docker/deployment/scripts/install_openstudio.sh
12
+ - chmod +x install_openstudio.sh
13
+ - sudo ./install_openstudio.sh $OPENSTUDIO_VERSION $OPENSTUDIO_SHA
13
14
  script:
14
- - rake
15
+ - bundle exec rake
16
+ deploy:
17
+ - provider: rubygems
18
+ api_key:
19
+ secure: IOYqPDXgaX5tZgsaeuSs2Q5hUry0l2RHrXDmuEeu7SElLDQSXS2z8c43eHg6GphtIho9NZgonXeCe1QoXb/GdHsyv2Up1XfaTtPkf7LHJo/zYPF7Yjc1mjGpKRPfk1srH8nfb6w9w7zjFlhk73a/Vh26BvdRCXqAA8W72d0ur2p8OTlGSYjcgLihWI13sSKrfHjTRXhOpv6gkziaY2pmvNWeeYdqOD3CpvlMDAMkHY/KptksaqWdBAT9Jr4gIfAGeGbKzye0OmBBrwMV4n/4KZqNNDyjiGYGoSbOhVEsAOHbeJz6IOoC93ICQi/nLuWBw+T8do79X2/GBIj2/N7eaEo4CcYsxMS0JX+dE4yL+OzQOFkDenq0WAEB7JjtBVW3sBHAIRGO2o2Cma6Ga5+86oSD0f5lAvnhiCejA1Fy9X5pnIMsk1zWlPLydPX4TwIm10JBaRLut+MFq0tL5tJunyIwlZnMgVofVdKYZHS7fVOvqSTQhM+iA0Gx5l7bKZQjpO3m91j14pKqdJij0PJ4oxy7ozc38YSUL85NKXnbf2KwnYVxMGz4yBrSalzMjftu6WfCM8liDTb0ACHby56KbPrlVlixJrrJIefZCLqaHtqL2lLlyVV36EtRbNl3It7DrOQ21HK3raOEuSxht3uuTu9FIdTx0TKraJUyToE6gbw=
20
+ on:
21
+ tags: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # Version 0.1.5
2
+
3
+ * Run Minitest in foreground
4
+ * Remove ActiveSupport XML parsing and use REXML
5
+ * Enforce UTF-8 encoding on all files read by this package
6
+ * Garbage collection on each Minitest teardown
7
+ * Disable running coverage until access violations are resolved
8
+ * More logging
9
+
1
10
  # Version 0.1.4
2
11
 
3
12
  * Use simplecov from NREL's fork. Do not rely on JSON.
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
- source 'https://rubygems.org'
1
+ source 'http://rubygems.org'
2
2
 
3
3
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in openstudio_measure_tester.gemspec
6
6
  gemspec
7
7
 
8
- gem "simplecov", github: "NREL/simplecov"
8
+ gem 'simplecov', github: 'NREL/simplecov'
data/README.md CHANGED
@@ -5,7 +5,9 @@
5
5
 
6
6
  The OpenStudio Measure Tester is a rubygem that exposes rake tasks for testing OpenStudio measures.
7
7
 
8
- ## Installation
8
+ ## Installation and Running
9
+
10
+ ### Rake-based
9
11
 
10
12
  * Add the following code to the Gemfile and Rakefile of a measure repo you desire to test.
11
13
 
@@ -35,11 +37,36 @@ The OpenStudio Measure Tester is a rubygem that exposes rake tasks for testing O
35
37
 
36
38
  ```
37
39
  Open ./test_results/dashboard/index.html to view measure testing dashboard.
38
- ```
40
+ ```
39
41
 
40
- ## Disclaimer
42
+ ### Ruby-based
43
+
44
+ * Require the OpenStudio-measure-tester gem
45
+
46
+ ```ruby
47
+ require 'openstudio_measure_tester'
48
+ measures_dir = 'spec/test_measures/AddOverhangsByProjectionFactor'
49
+ # all measures (recursively) from measures_dir will be tested
50
+
51
+ runner = OpenStudioMeasureTester::Runner.new(measures_dir)
52
+
53
+ # base_dir is needed for coverage results as they are written to disk on the at_exit calls
54
+ base_dir = Dir.pwd
55
+
56
+ result = runner.run_all(base_dir)
57
+ puts result
58
+ # result will be 0 or 1, 0=success, 1=failure
59
+
60
+ runner.run_style(false)
41
61
 
42
- This project is under active development and will be changing significantly.
62
+ runner.run_test(false, base_dir)
63
+
64
+ runner.run_rubocop(false)
65
+ ```
66
+
67
+ * Results will be saved into the run directory (measures_dir from above).
68
+
69
+ ## Disclaimer
43
70
 
44
71
  # Testing in Docker
45
72
 
@@ -54,3 +81,9 @@ chmod +x install_openstudio.sh
54
81
  ./install_openstudio.sh 2.4.0 f58a3e1808
55
82
  export RUBYLIB=/usr/Ruby
56
83
  ```
84
+
85
+
86
+ # Releasing
87
+
88
+ New versions of the OpenStudio Measure Tester Gem will be automatically released for any tags. Makes sure to increment
89
+ the version in `/lib/openstudio_measure_tester/version.rb` and tag the release (preferably off the master branch).
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'openstudio_measure_tester'
4
+
5
+ measure_dir = File.absolute_path(ARGV[0], Dir.pwd)
6
+
7
+ if !File.exist?(measure_dir)
8
+ puts "'#{measure_dir}}' does not exist"
9
+ exit
10
+ end
11
+
12
+ begin
13
+ runner = OpenStudioMeasureTester::Runner.new(measure_dir)
14
+ runner.run_all(Dir.pwd)
15
+ rescue StandardError => exception
16
+ puts
17
+ puts '!!!!!!!!!!!!!!!!!!!!! Error Occurred !!!!!!!!!!!!!!!!!!!!!'
18
+ puts exception.message
19
+ puts exception.backtrace
20
+ puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
21
+ puts
22
+ end
@@ -29,11 +29,22 @@
29
29
  require 'openstudio'
30
30
 
31
31
  require 'pp'
32
- require 'active_support'
33
- require 'active_support/core_ext'
34
32
  require 'git'
35
- require 'openstudio_measure_tester/core_ext'
33
+ require 'rexml/document'
34
+ require 'minitest'
35
+ require 'simplecov'
36
+
37
+ # override the default at_exit call
38
+ SimpleCov.at_exit do
39
+ end
36
40
 
41
+ # Override the minitest autorun, to, well, not autorun
42
+ def Minitest.autorun; end
43
+
44
+ # Rubocop loads a lot of objects, anyway to minimize would be nice.
45
+ require 'rubocop'
46
+
47
+ require 'openstudio_measure_tester/core_ext'
37
48
  require 'openstudio_measure_tester/version'
38
49
  require 'openstudio_measure_tester/openstudio_style'
39
50
  require 'openstudio_measure_tester/minitest_result'
@@ -41,9 +52,27 @@ require 'openstudio_measure_tester/coverage'
41
52
  require 'openstudio_measure_tester/rubocop_result'
42
53
  require 'openstudio_measure_tester/openstudio_testing_result'
43
54
  require 'openstudio_measure_tester/dashboard'
55
+ require 'openstudio_measure_tester/runner'
44
56
 
45
57
  require 'openstudio_measure_tester/rake_task'
46
58
 
59
+ # Set the encoding to UTF-8. OpenStudio Docker images do not have this set by default
60
+ Encoding.default_external = Encoding::UTF_8
61
+ Encoding.default_internal = Encoding::UTF_8
62
+
47
63
  module OpenStudioMeasureTester
48
64
  # No action here. Most of this will be rake_tasks at the moment.
49
65
  end
66
+
67
+
68
+ class Minitest::Test
69
+ def teardown
70
+ before = ObjectSpace.count_objects
71
+ GC.start
72
+ after = ObjectSpace.count_objects
73
+ delta = {}
74
+ before.each {|k, v| delta[k] = v - after[k] if after.has_key? k }
75
+ puts "GC Delta: #{delta}"
76
+ end
77
+ end
78
+
@@ -72,7 +72,7 @@ end
72
72
  module Git
73
73
  class Log
74
74
  def empty?
75
- size.zero? # rubocop:disable Style/ZeroLengthPredicate
75
+ size.zero?
76
76
  end
77
77
  end
78
78
  end
@@ -69,6 +69,11 @@ module OpenStudioMeasureTester
69
69
  def parse_results
70
70
  file = "#{@path_to_results}/.resultset.json"
71
71
 
72
+ unless File.exist? file
73
+ puts "Could not find the results of coverage in #{file}"
74
+ return false
75
+ end
76
+
72
77
  puts 'Parsing coverage results'
73
78
  json_data = File.read(file)
74
79
  hash = JSON.parse(json_data)
@@ -95,9 +100,9 @@ module OpenStudioMeasureTester
95
100
  if parts.last == 'measure.rb'
96
101
  class_name = parse_class_name(key)
97
102
  measure_maps[class_name] = {
98
- class_name: class_name,
99
- root_path: File.dirname(key),
100
- files: [key]
103
+ class_name: class_name,
104
+ root_path: File.dirname(key),
105
+ files: [key]
101
106
  }
102
107
  end
103
108
  end
@@ -135,7 +140,7 @@ module OpenStudioMeasureTester
135
140
  # remove nils from array
136
141
  cov_results_by_line.delete(nil)
137
142
 
138
- cov = cov_results_by_line.count {|x| x > 0}
143
+ cov = cov_results_by_line.count { |x| x > 0 }
139
144
  fhash['percent_coverage'] = ((cov.to_f / cov_results_by_line.size.to_f) * 100).round(2)
140
145
  fhash['missed_lines'] = cov_results_by_line.size - cov
141
146
  fhash['relevant_lines'] = cov_results_by_line.size
@@ -156,7 +161,6 @@ module OpenStudioMeasureTester
156
161
  @total_missed_lines += mhash['missed_lines']
157
162
  end
158
163
 
159
-
160
164
  # pp @measure_coverages
161
165
  lines = @total_relevant_lines # unnecessary but breaks formatting otherwise
162
166
  # lines can be zero if coverage doesn't run correctly
@@ -164,6 +168,8 @@ module OpenStudioMeasureTester
164
168
  @total_percent_coverage = (@total_covered_lines.to_f / lines.to_f * 100).round(2)
165
169
  end
166
170
  pp "Total Coverage: #{@total_percent_coverage}"
171
+
172
+ return true
167
173
  end
168
174
 
169
175
  def to_hash
@@ -3,20 +3,20 @@ module OpenStudioMeasureTester
3
3
  class Dashboard
4
4
  attr_reader :html
5
5
 
6
- # @param base_dir [String]: The directory from where the rake test was instantiated
7
- def initialize(base_dir)
8
- @base_dir = base_dir
6
+ # @param test_results_directory [String]: The directory
7
+ def initialize(test_results_directory)
8
+ @test_results_directory = test_results_directory
9
9
 
10
10
  erb_file = File.expand_path('templates/dashboard.html.erb', File.dirname(__FILE__))
11
11
  @template = File.read(erb_file)
12
- file = File.read("#{base_dir}/test_results/combined_results.json")
12
+ file = File.read("#{@test_results_directory}/combined_results.json")
13
13
  @data = file
14
14
  @hash = JSON.parse(@data)
15
15
  end
16
16
 
17
17
  def render
18
18
  rendered = ERB.new(@template, 0, '', '@html').result(binding)
19
- save_dir = "#{@base_dir}/test_results/dashboard"
19
+ save_dir = "#{@test_results_directory}/dashboard"
20
20
 
21
21
  # Render the dashboard
22
22
  FileUtils.mkdir_p save_dir unless Dir.exist? save_dir
@@ -57,23 +57,26 @@ module OpenStudioMeasureTester
57
57
  def parse_results
58
58
  Dir["#{@path_to_results}/reports/*.xml"].each do |file|
59
59
  puts "Parsing minitest report #{file}"
60
- hash = Hash.from_xml(File.read(file))
60
+ doc = REXML::Document.new(File.open(file)).root
61
61
 
62
- # pp hash
62
+ # continue if doc is empty
63
+ next unless doc
63
64
 
64
65
  measure_name = file.split('/')[-1].split('.')[0].split('-')[1].gsub /-?[tT]est\z/, ''
65
66
 
66
67
  mhash = {}
67
-
68
68
  mhash['tested_class'] = measure_name
69
- mhash['measure_tests'] = hash['testsuite']['tests'].to_i
70
- mhash['measure_assertions'] = hash['testsuite']['assertions'].to_i
71
- mhash['measure_errors'] = hash['testsuite']['errors'].to_i
72
- mhash['measure_failures'] = hash['testsuite']['failures'].to_i
73
- mhash['measure_skipped'] = hash['testsuite']['skipped'].to_i
74
69
 
75
70
  # Note: only 1 failure and 1 error possible per test
76
- errors, failures = parse_measure(hash)
71
+ testsuite_element = doc.elements['testsuite']
72
+ errors, failures = parse_measure(testsuite_element)
73
+
74
+ mhash['measure_tests'] = testsuite_element.attributes['tests'].to_i
75
+ mhash['measure_assertions'] = testsuite_element.attributes['assertions'].to_i
76
+ mhash['measure_errors'] = testsuite_element.attributes['errors'].to_i
77
+ mhash['measure_failures'] = testsuite_element.attributes['failures'].to_i
78
+ mhash['measure_skipped'] = testsuite_element.attributes['skipped'].to_i
79
+
77
80
  mhash['issues'] = { errors: errors, failures: failures }
78
81
 
79
82
  @measure_results[measure_name] = mhash
@@ -86,8 +89,6 @@ module OpenStudioMeasureTester
86
89
  end
87
90
 
88
91
  @error_status = true if @total_errors > 0
89
-
90
- # pp measure_results
91
92
  end
92
93
 
93
94
  def to_file
@@ -111,25 +112,15 @@ module OpenStudioMeasureTester
111
112
 
112
113
  private
113
114
 
114
- def parse_measure(measure)
115
+ def parse_measure(testsuite_element)
115
116
  errors = []
116
117
  failures = []
117
118
 
118
- # check if testcase is hash or array
119
- if measure['testsuite']
120
-
121
- if measure['testsuite']['testcase'].class == Hash
122
- # convert to array
123
- measure['testsuite']['testcase'] = [measure['testsuite']['testcase']]
124
- end
125
- measure['testsuite']['testcase'].each do |test|
126
- if test['error']
127
- errors << test['error']
128
- end
129
-
130
- if test['failure']
131
- failures << test['failure']
132
- end
119
+ testsuite_element.elements.each('testcase') do |testcase|
120
+ if testcase.elements['error']
121
+ errors << testcase.elements['error']
122
+ elsif testcase.elements['failure']
123
+ failures << testcase.elements['failure']
133
124
  end
134
125
  end
135
126
 
@@ -74,13 +74,6 @@ module OpenStudioMeasureTester
74
74
  type: :deprecated,
75
75
  severity: :error,
76
76
  file_type: :measure
77
- # }, {
78
- # regex: /require .openstudio_measure_tester\/test_helper./,
79
- # check_type: :if_missing,
80
- # message: "Must include 'require 'openstudio_measure_tester/test_helper'' in Test file to report coverage correctly.",
81
- # type: :syntax,
82
- # severity: :error,
83
- # file_type: :test
84
77
  }, {
85
78
  regex: /MiniTest::Unit::TestCase/,
86
79
  check_type: :if_exists,
@@ -99,9 +92,10 @@ module OpenStudioMeasureTester
99
92
  ].freeze
100
93
 
101
94
  # Pass in the measures_glob with the filename (typically measure.rb)
102
- def initialize(measures_glob)
95
+ def initialize(results_dir, measures_glob)
103
96
  @measures_glob = measures_glob
104
97
  @results = { by_measure: {} }
98
+ @results_dir = results_dir
105
99
 
106
100
  # Individual measure messages
107
101
  @measure_messages = []
@@ -156,9 +150,12 @@ module OpenStudioMeasureTester
156
150
  else
157
151
  measure = measure.get
158
152
  begin
153
+ # there seems to be a race condition with the infoExtractor method
159
154
  measure_info = infoExtractor(measure, OpenStudio::Model::OptionalModel.new, OpenStudio::OptionalWorkspace.new)
160
155
  rescue NameError => error
161
156
  log_message("Unable to parse info from measure. Error: '#{error}'", :general, :error)
157
+ rescue => error
158
+ log_message("Unknown error extracting measure info. Error #{error}", :general, :error)
162
159
  end
163
160
 
164
161
  measure_hash = generate_measure_hash(measure_dir, measure, measure_info)
@@ -213,8 +210,11 @@ module OpenStudioMeasureTester
213
210
  end
214
211
 
215
212
  def save_results
216
- FileUtils.mkdir 'openstudio_style' unless Dir.exist? 'openstudio_style'
217
- File.open('openstudio_style/openstudio_style.json', 'w') do |file|
213
+ save_dir = "#{@results_dir}/openstudio_style"
214
+ save_file = "#{save_dir}/openstudio_style.json"
215
+ puts "Saving OpenStudio Style results to #{save_file}"
216
+ FileUtils.mkdir_p save_dir unless Dir.exist? save_dir
217
+ File.open(save_file, 'w') do |file|
218
218
  file << JSON.pretty_generate(@results)
219
219
  end
220
220
  end