Class: LearnTest::PythonUnittest::Runner
- Inherits:
-
Object
- Object
- LearnTest::PythonUnittest::Runner
- Defined in:
- lib/learn_test/python_unittest/runner.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#formatted_results ⇒ Object
Returns the value of attribute formatted_results.
-
#json_output ⇒ Object
Returns the value of attribute json_output.
-
#keep_results ⇒ Object
readonly
Returns the value of attribute keep_results.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parsed_output ⇒ Object
Returns the value of attribute parsed_output.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #calculate_duration ⇒ Object
- #cleanup ⇒ Object
- #concat_failure_descriptions ⇒ Object
- #format_results ⇒ Object
-
#initialize(username, user_id, repo_name, options) ⇒ Runner
constructor
A new instance of Runner.
- #jsonify ⇒ Object
- #keep_results? ⇒ Boolean
- #push_results ⇒ Object
- #run ⇒ Object
- #run_nose ⇒ Object
- #set_json_output ⇒ Object
Constructor Details
#initialize(username, user_id, repo_name, options) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/learn_test/python_unittest/runner.rb', line 7 def initialize(username, user_id, repo_name, ) @username = username @user_id = user_id @repo_name = repo_name @options = @json_output = "" @parsed_output = nil @formatted_results = {} @keep_results = !!.delete('--keep') @connection = Faraday.new(url: SERVICE_URL) do |faraday| faraday.adapter Faraday.default_adapter end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/learn_test/python_unittest/runner.rb', line 5 def connection @connection end |
#formatted_results ⇒ Object
Returns the value of attribute formatted_results.
4 5 6 |
# File 'lib/learn_test/python_unittest/runner.rb', line 4 def formatted_results @formatted_results end |
#json_output ⇒ Object
Returns the value of attribute json_output.
4 5 6 |
# File 'lib/learn_test/python_unittest/runner.rb', line 4 def json_output @json_output end |
#keep_results ⇒ Object (readonly)
Returns the value of attribute keep_results.
5 6 7 |
# File 'lib/learn_test/python_unittest/runner.rb', line 5 def keep_results @keep_results end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/learn_test/python_unittest/runner.rb', line 5 def @options end |
#parsed_output ⇒ Object
Returns the value of attribute parsed_output.
4 5 6 |
# File 'lib/learn_test/python_unittest/runner.rb', line 4 def parsed_output @parsed_output end |
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
5 6 7 |
# File 'lib/learn_test/python_unittest/runner.rb', line 5 def repo_name @repo_name end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/learn_test/python_unittest/runner.rb', line 5 def user_id @user_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/learn_test/python_unittest/runner.rb', line 5 def username @username end |
Instance Method Details
#calculate_duration ⇒ Object
68 69 70 71 72 |
# File 'lib/learn_test/python_unittest/runner.rb', line 68 def calculate_duration parsed_output[:results].map do |example| example[:time] end.inject(:+) end |
#cleanup ⇒ Object
88 89 90 |
# File 'lib/learn_test/python_unittest/runner.rb', line 88 def cleanup FileUtils.rm('.results.json') unless keep_results? end |
#concat_failure_descriptions ⇒ Object
74 75 76 77 78 |
# File 'lib/learn_test/python_unittest/runner.rb', line 74 def concat_failure_descriptions parsed_output[:results].select do |example| example[:type] == 'failure' end.map { |ex| ex[:tb] }.join(';') end |
#format_results ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/learn_test/python_unittest/runner.rb', line 48 def format_results self.formatted_results.merge!({ username: username, github_user_id: user_id, repo_name: repo_name, build: { test_suite: [{ framework: 'unittest', formatted_output: parsed_output, duration: calculate_duration }] }, examples: parsed_output[:stats][:total], passing_count: parsed_output[:stats][:passes], pending_count: parsed_output[:stats][:skipped], failure_count: parsed_output[:stats][:errors], failure_descriptions: concat_failure_descriptions }) end |
#jsonify ⇒ Object
44 45 46 |
# File 'lib/learn_test/python_unittest/runner.rb', line 44 def jsonify self.parsed_output = Oj.load(json_output, symbol_keys: true) end |
#keep_results? ⇒ Boolean
32 33 34 |
# File 'lib/learn_test/python_unittest/runner.rb', line 32 def keep_results? keep_results end |
#push_results ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/learn_test/python_unittest/runner.rb', line 80 def push_results connection.post do |req| req.url SERVICE_ENDPOINT req.headers['Content-Type'] = 'application/json' req.body = Oj.dump(formatted_results, mode: :compat) end end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/learn_test/python_unittest/runner.rb', line 21 def run run_nose if !.include?('-h') && !.include?('--help') set_json_output jsonify format_results push_results cleanup end end |
#run_nose ⇒ Object
36 37 38 |
# File 'lib/learn_test/python_unittest/runner.rb', line 36 def run_nose system("nosetests #{.join(' ')} --verbose --with-json --json-file='./.results.json'") end |
#set_json_output ⇒ Object
40 41 42 |
# File 'lib/learn_test/python_unittest/runner.rb', line 40 def set_json_output self.json_output = File.read('.results.json') end |