-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRakefile
161 lines (132 loc) · 4.83 KB
/
Rakefile
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
require 'rake/testtask'
require 'json'
namespace :test do
full_file_list = nil
if File.exist?('circleci_tests.txt')
# load test files from file.
full_file_list = FileList.new(File.readlines('circleci_tests.txt'))
# Select only .rb files that exist
full_file_list.select! { |item| item.include?('rb') && File.exist?(File.absolute_path("#{item.strip}")) }
full_file_list.map! { |item| File.absolute_path("#{item.strip}") }
File.open("circleci_tests.json","w") do |f|
f.write(JSON.pretty_generate(full_file_list.to_a))
end
else
puts 'Could not find list of files to test at test/circleci_tests.txt'
return false
end
desc 'Run All CircleCI tests locally'
Rake::TestTask.new('measure-tests') do |t|
file_list = FileList.new('test_run_all_test_locally.rb')
t.libs << 'test'
t.test_files = file_list
t.verbose = false
end
# These tests only available in the CI environment
if ENV['CI'] == 'true'
desc 'Run CircleCI tests'
Rake::TestTask.new('circleci') do |t|
# Create a FileList for this task
test_list = FileList.new
# Read the parallelized list of tests
# created by the circleci CLI in config.yml
if File.exist?('circleci_tests.txt')
File.open('circleci_tests.txt', 'r') do |f|
f.each_line do |line|
# Skip comments the CLI may have included
next unless line.include?('.rb')
# Remove whitespaces
line = line.strip
# Ensure the file exists
pth = File.absolute_path("#{line}")
unless File.exist?(pth)
puts "Skipped #{line} because this file doesn't exist"
puts "From #{Dir.pwd}"
next
end
# Add this test to the list
test_list.add(pth)
end
end
# Assign the tests to this task
t.test_files = test_list
else
puts 'Could not find parallelized list of CI tests.'
end
end
desc 'Summarize the test timing'
task 'times' do |t|
require 'nokogiri'
files_to_times = {}
tests_to_times = {}
Dir['test/reports/*.xml'].each do |xml|
doc = File.open(xml) { |f| Nokogiri::XML(f) }
doc.css('testcase').each do |testcase|
time = testcase.attr('time').to_f
file = testcase.attr('file')
name = testcase.attr('name')
# Add to total for this file
if files_to_times[file].nil?
files_to_times[file] = time
else
files_to_times[file] += time
end
# Record for this test itself
if tests_to_times[name].nil?
tests_to_times[name] = time
else
tests_to_times[name] += time
end
end
end
# Write out the test results to file
folder = "#{Dir.pwd}/timing"
Dir.mkdir(folder) unless File.exist?(folder)
# By file
File.open("#{Dir.pwd}/timing/test_by_file.html", 'w') do |html|
html.puts '<table><tr><th>File Name</th><th>Time (min)</th></tr>'
files_to_times.each do |f, time_s|
s = (time_s / 60).round(1) # convert time from sec to min
html.puts "<tr><td>#{f}</td><td>#{s}</td></tr>"
end
html.puts '</table>'
end
# By name
File.open("#{Dir.pwd}/timing/test_by_name.html", 'w') do |html|
html.puts '<table><tr><th>Test Name</th><th>Time (min)</th></tr>'
tests_to_times.each do |f, time_s|
s = (time_s / 60).round(1) # convert time from sec to min
html.puts "<tr><td>#{f}</td><td>#{s}</td></tr>"
end
html.puts '</table>'
end
end
end
end
desc 'Update Measures'
task :measure_xml_update do
system( 'openstudio measure --update_all measures/')
end
desc 'Update Common Resources from TemplateModelMeasure'
task :update_resources do
# Find all files in measures/BTAPTemplateModelMeasure/resources
files = Dir.glob("measures_development/BTAPTemplateModelMeasure/resources/*.*").map(&File.method(:realpath))
folders = Dir.glob("measures/*/resources").map(&File.method(:realpath))
folders.concat(Dir.glob("measures_development/*/resources").map(&File.method(:realpath)))
#copy files over
folders.each do |folder|
files.each do |file|
FileUtils.cp(file, folder)
puts "Copied #{file} to #{folder}"
end unless folder.include?('BTAPTemplateModelMeasure')
end
end
desc 'Update RSMeans Costing Data From Web API'
task :update_costing do
require_relative './measures/btap_results/resources/btap_costing'
data = BTAPCosting.new()
data.create_database()
data.create_dummy_database()
puts "Dummy/Empty database created as default measures/btap_results/resources/costing_database.json.gz. "
puts "Overwrite costing_database.json.gz with costing_database_rsmeans.json.gz to use rsmeans costing."
end