Fix rubocop offenses - Requires Ruby 3.1+
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CppCatch2Adapter < TestingFrameworkAdapter
|
||||
ALL_PASSED_REGEXP = /in\s+(\d+)\s+test case/.freeze
|
||||
COUNT_REGEXP = /test cases:\s+(\d+)/.freeze
|
||||
FAILURES_REGEXP = / \|\s+(\d+)\s+failed/.freeze
|
||||
ASSERTION_ERROR_REGEXP = /\n(.+)error:(.+);/.freeze
|
||||
ALL_PASSED_REGEXP = /in\s+(\d+)\s+test case/
|
||||
COUNT_REGEXP = /test cases:\s+(\d+)/
|
||||
FAILURES_REGEXP = / \|\s+(\d+)\s+failed/
|
||||
ASSERTION_ERROR_REGEXP = /\n(.+)error:(.+);/
|
||||
|
||||
def self.framework_name
|
||||
'CppCatch2'
|
||||
@ -17,7 +17,7 @@ class CppCatch2Adapter < TestingFrameworkAdapter
|
||||
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
|
||||
{count:, failed:, error_messages: error_matches.flatten.compact_blank}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Junit5Adapter < TestingFrameworkAdapter
|
||||
COUNT_REGEXP = /(\d+) tests found/.freeze
|
||||
FAILURES_REGEXP = /(\d+) tests failed/.freeze
|
||||
ASSERTION_ERROR_REGEXP = /=> java\.lang\.AssertionError:?\s(.*?)\s*org\.junit|=> org\.junit\.ComparisonFailure:\s(.*?)\s*org\.junit|=>\s(.*?)\s*org\.junit\.internal\.ComparisonCriteria\.arrayEquals|=> org\.opentest4j\.AssertionFailedError:?\s(.*?)\s*org.junit/m.freeze
|
||||
COUNT_REGEXP = /(\d+) tests found/
|
||||
FAILURES_REGEXP = /(\d+) tests failed/
|
||||
ASSERTION_ERROR_REGEXP = /=> java\.lang\.AssertionError:?\s(.*?)\s*org\.junit|=> org\.junit\.ComparisonFailure:\s(.*?)\s*org\.junit|=>\s(.*?)\s*org\.junit\.internal\.ComparisonCriteria\.arrayEquals|=> org\.opentest4j\.AssertionFailedError:?\s(.*?)\s*org.junit/m
|
||||
|
||||
def self.framework_name
|
||||
'JUnit 5'
|
||||
@ -13,10 +13,10 @@ class Junit5Adapter < TestingFrameworkAdapter
|
||||
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
if failed.zero?
|
||||
{count: count, passed: count}
|
||||
{count:, passed: count}
|
||||
else
|
||||
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
|
||||
{count:, failed:, error_messages: error_matches.flatten.compact_blank}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class JunitAdapter < TestingFrameworkAdapter
|
||||
COUNT_REGEXP = /Tests run: (\d+)/.freeze
|
||||
FAILURES_REGEXP = /Failures: (\d+)/.freeze
|
||||
SUCCESS_REGEXP = /OK \((\d+) tests?\)\s*(?:\x1B\]0;|exit)?\s*\z/.freeze
|
||||
ASSERTION_ERROR_REGEXP = /java\.lang\.AssertionError:?\s(.*?)\tat org\.junit|org\.junit\.ComparisonFailure:\s(.*?)\tat org\.junit|\)\r\n(.*?)\tat org\.junit\.internal\.ComparisonCriteria\.arrayEquals\(ComparisonCriteria\.java:50\)/m.freeze
|
||||
COUNT_REGEXP = /Tests run: (\d+)/
|
||||
FAILURES_REGEXP = /Failures: (\d+)/
|
||||
SUCCESS_REGEXP = /OK \((\d+) tests?\)\s*(?:\x1B\]0;|exit)?\s*\z/
|
||||
ASSERTION_ERROR_REGEXP = /java\.lang\.AssertionError:?\s(.*?)\tat org\.junit|org\.junit\.ComparisonFailure:\s(.*?)\tat org\.junit|\)\r\n(.*?)\tat org\.junit\.internal\.ComparisonCriteria\.arrayEquals\(ComparisonCriteria\.java:50\)/m
|
||||
|
||||
def self.framework_name
|
||||
'JUnit 4'
|
||||
@ -17,7 +17,7 @@ class JunitAdapter < TestingFrameworkAdapter
|
||||
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
|
||||
{count:, failed:, error_messages: error_matches.flatten.compact_blank}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MochaAdapter < TestingFrameworkAdapter
|
||||
SUCCESS_REGEXP = /(\d+) passing/.freeze
|
||||
FAILURES_REGEXP = /(\d+) failing/.freeze
|
||||
SUCCESS_REGEXP = /(\d+) passing/
|
||||
FAILURES_REGEXP = /(\d+) failing/
|
||||
|
||||
def self.framework_name
|
||||
'Mocha'
|
||||
@ -11,6 +11,6 @@ class MochaAdapter < TestingFrameworkAdapter
|
||||
def parse_output(output)
|
||||
success = output[:stdout].scan(SUCCESS_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||
{count: success + failed, failed: failed}
|
||||
{count: success + failed, failed:}
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PyLintAdapter < TestingFrameworkAdapter
|
||||
REGEXP = %r{Your code has been rated at (-?\d+\.?\d*)/(\d+\.?\d*)}.freeze
|
||||
ASSERTION_ERROR_REGEXP = /^(.*?\.py):(\d+):(.*?)\(([^,]*?), ([^,]*?),([^,]*?)\) (.*?)$/.freeze
|
||||
REGEXP = %r{Your code has been rated at (-?\d+\.?\d*)/(\d+\.?\d*)}
|
||||
ASSERTION_ERROR_REGEXP = /^(.*?\.py):(\d+):(.*?)\(([^,]*?), ([^,]*?),([^,]*?)\) (.*?)$/
|
||||
|
||||
def self.framework_name
|
||||
'PyLint'
|
||||
@ -41,8 +41,8 @@ class PyLintAdapter < TestingFrameworkAdapter
|
||||
end
|
||||
concatenated_errors = assertion_error_matches.map {|result| "#{result[:name]}: #{result[:result]}" }
|
||||
{
|
||||
count: count,
|
||||
failed: failed,
|
||||
count:,
|
||||
failed:,
|
||||
error_messages: concatenated_errors.flatten.compact_blank,
|
||||
detailed_linter_results: assertion_error_matches.flatten.compact_blank,
|
||||
}
|
||||
@ -69,7 +69,7 @@ class PyLintAdapter < TestingFrameworkAdapter
|
||||
captures = message[:result].match(Regexp.new(regex))&.named_captures&.symbolize_keys
|
||||
|
||||
if captures.nil?
|
||||
Sentry.capture_message({regex: regex, message: message[:result]}.to_json)
|
||||
Sentry.capture_message({regex:, message: message[:result]}.to_json)
|
||||
replacement = {}
|
||||
else
|
||||
replacement = captures.each do |key, value|
|
||||
@ -100,7 +100,7 @@ class PyLintAdapter < TestingFrameworkAdapter
|
||||
def self.get_t(key, default)
|
||||
# key might be "linter.#{severity}.#{name}.#{key}.#{value}"
|
||||
# or something like "linter.#{severity}.#{name}.replacement"
|
||||
translation = I18n.t(key, default: default)
|
||||
translation = I18n.t(key, default:)
|
||||
cleaned_key = key.delete_suffix(".#{default}") # Remove any custom prefix, might have no effect
|
||||
keys = cleaned_key.split('.')
|
||||
final_key = keys.pop
|
||||
@ -111,7 +111,7 @@ class PyLintAdapter < TestingFrameworkAdapter
|
||||
# Read config key
|
||||
I18n.t(keys.append('log_missing').join('.'), default: false)
|
||||
end
|
||||
Sentry.capture_message({key: cleaned_key, default: default}.to_json) if translation == default && log_missing
|
||||
Sentry.capture_message({key: cleaned_key, default:}.to_json) if translation == default && log_missing
|
||||
translation
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PyUnitAdapter < TestingFrameworkAdapter
|
||||
COUNT_REGEXP = /Ran (\d+) test/.freeze
|
||||
FAILURES_REGEXP = /FAILED \(.*failures=(\d+).*\)/.freeze
|
||||
ERRORS_REGEXP = /FAILED \(.*errors=(\d+).*\)/.freeze
|
||||
ASSERTION_ERROR_REGEXP = /^(ERROR|FAIL):\ (.*?)\ .*?^[^.\n]*?(Error|Exception):\s((\s|\S)*?)(>>>[^>]*?)*\s\s(-|=){70}/m.freeze
|
||||
COUNT_REGEXP = /Ran (\d+) test/
|
||||
FAILURES_REGEXP = /FAILED \(.*failures=(\d+).*\)/
|
||||
ERRORS_REGEXP = /FAILED \(.*errors=(\d+).*\)/
|
||||
ASSERTION_ERROR_REGEXP = /^(ERROR|FAIL):\ (.*?)\ .*?^[^.\n]*?(Error|Exception):\s((\s|\S)*?)(>>>[^>]*?)*\s\s(-|=){70}/m
|
||||
|
||||
def self.framework_name
|
||||
'PyUnit'
|
||||
@ -32,6 +32,6 @@ class PyUnitAdapter < TestingFrameworkAdapter
|
||||
Sentry.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json)
|
||||
assertion_error_matches = []
|
||||
end
|
||||
{count: count, failed: failed + errors, error_messages: assertion_error_matches.flatten.compact_blank}
|
||||
{count:, failed: failed + errors, error_messages: assertion_error_matches.flatten.compact_blank}
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RScriptAdapter < TestingFrameworkAdapter
|
||||
REGEXP = /(\d+) examples?, (\d+) passed?/.freeze
|
||||
ASSERTION_ERROR_REGEXP = /AssertionError:\s(.*)/.freeze
|
||||
REGEXP = /(\d+) examples?, (\d+) passed?/
|
||||
ASSERTION_ERROR_REGEXP = /AssertionError:\s(.*)/
|
||||
|
||||
def self.framework_name
|
||||
'R Script'
|
||||
@ -14,6 +14,6 @@ class RScriptAdapter < TestingFrameworkAdapter
|
||||
passed = captures.second
|
||||
failed = count - passed
|
||||
assertion_error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||
{count: count, failed: failed, error_messages: assertion_error_matches.flatten.compact_blank}
|
||||
{count:, failed:, error_messages: assertion_error_matches.flatten.compact_blank}
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RspecAdapter < TestingFrameworkAdapter
|
||||
REGEXP = /(\d+) examples?, (\d+) failures?/.freeze
|
||||
REGEXP = /(\d+) examples?, (\d+) failures?/
|
||||
|
||||
def self.framework_name
|
||||
'RSpec 3'
|
||||
@ -11,6 +11,6 @@ class RspecAdapter < TestingFrameworkAdapter
|
||||
captures = output[:stdout].scan(REGEXP).try(:last).map(&:to_i)
|
||||
count = captures.first
|
||||
failed = captures.second
|
||||
{count: count, failed: failed}
|
||||
{count:, failed:}
|
||||
end
|
||||
end
|
||||
|
@ -128,7 +128,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
|
||||
|
||||
# First, clean the workspace and second, copy all files to their location.
|
||||
# This ensures that no artifacts from a previous submission remain in the workspace.
|
||||
body = {copy: copy, delete: ['./*']}
|
||||
body = {copy:, delete: ['./*']}
|
||||
response = self.class.http_connection.patch url, body.to_json
|
||||
return if response.status == 204
|
||||
|
||||
@ -143,8 +143,8 @@ class Runner::Strategy::Poseidon < Runner::Strategy
|
||||
def retrieve_files(path: './', recursive: true, privileged_execution: false)
|
||||
url = "#{runner_url}/files"
|
||||
params = {
|
||||
path: path,
|
||||
recursive: recursive,
|
||||
path:,
|
||||
recursive:,
|
||||
privilegedExecution: privileged_execution || @execution_environment.privileged_execution,
|
||||
}
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Retrieving files at #{runner_url} with #{params}" }
|
||||
@ -199,7 +199,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
|
||||
end
|
||||
|
||||
def attach_to_execution(command, event_loop, starting_time, privileged_execution: false)
|
||||
websocket_url = execute_command(command, privileged_execution: privileged_execution)
|
||||
websocket_url = execute_command(command, privileged_execution:)
|
||||
socket = Connection.new(websocket_url, self, event_loop)
|
||||
yield(socket, starting_time)
|
||||
socket
|
||||
@ -293,13 +293,13 @@ class Runner::Strategy::Poseidon < Runner::Strategy
|
||||
end
|
||||
|
||||
def self.http_connection
|
||||
@http_connection ||= Faraday.new(ssl: {ca_file: config[:ca_file]}, headers: headers) do |faraday|
|
||||
@http_connection ||= Faraday.new(ssl: {ca_file: config[:ca_file]}, headers:) do |faraday|
|
||||
faraday.adapter :net_http_persistent
|
||||
end
|
||||
end
|
||||
|
||||
def self.new_http_connection
|
||||
Faraday.new(ssl: {ca_file: config[:ca_file]}, headers: headers) do |faraday|
|
||||
Faraday.new(ssl: {ca_file: config[:ca_file]}, headers:) do |faraday|
|
||||
faraday.adapter :net_http
|
||||
end
|
||||
end
|
||||
@ -316,7 +316,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
|
||||
def execute_command(command, privileged_execution: false)
|
||||
url = "#{runner_url}/execute"
|
||||
body = {
|
||||
command: command,
|
||||
command:,
|
||||
timeLimit: @execution_environment.permitted_execution_time,
|
||||
privilegedExecution: privileged_execution || @execution_environment.privileged_execution,
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SqlResultSetComparatorAdapter < TestingFrameworkAdapter
|
||||
MISSING_TUPLES_REGEXP = /Missing tuples: \[\]/.freeze
|
||||
UNEXPECTED_TUPLES_REGEXP = /Unexpected tuples: \[\]/.freeze
|
||||
MISSING_TUPLES_REGEXP = /Missing tuples: \[\]/
|
||||
UNEXPECTED_TUPLES_REGEXP = /Unexpected tuples: \[\]/
|
||||
|
||||
def self.framework_name
|
||||
'SqlResultSetComparator'
|
||||
|
@ -133,7 +133,7 @@ namespace :detect_exercise_anomalies do
|
||||
segment.each do |user|
|
||||
reason = "{\"segment\": \"#{key}\", \"feature\": \"#{user[:reason]}\", value: \"#{user[:value]}\"}"
|
||||
AnomalyNotification.create(user_id: user[:user_id], user_type: user[:user_type],
|
||||
exercise: exercise, exercise_collection: collection, reason: reason)
|
||||
exercise:, exercise_collection: collection, reason:)
|
||||
end
|
||||
end
|
||||
|
||||
@ -142,7 +142,7 @@ namespace :detect_exercise_anomalies do
|
||||
user = u[:user_type] == InternalUser.name ? InternalUser.find(u[:user_id]) : ExternalUser.find(u[:user_id])
|
||||
host = CodeOcean::Application.config.action_mailer.default_url_options[:host]
|
||||
feedback_link = Rails.application.routes.url_helpers.url_for(action: :new,
|
||||
controller: :user_exercise_feedbacks, exercise_id: exercise.id, host: host)
|
||||
controller: :user_exercise_feedbacks, exercise_id: exercise.id, host:)
|
||||
UserMailer.exercise_anomaly_needs_feedback(user, exercise, feedback_link).deliver
|
||||
end
|
||||
log("Asked #{users_to_notify.size} users for feedback.", 2)
|
||||
|
@ -9,8 +9,8 @@ namespace :export_exercises do
|
||||
Exercise.where(public: true).each do |exercise|
|
||||
puts "Exporting exercise ##{exercise.id}"
|
||||
error = ExerciseService::PushExternal.call(
|
||||
zip: ProformaService::ExportTask.call(exercise: exercise),
|
||||
codeharbor_link: codeharbor_link
|
||||
zip: ProformaService::ExportTask.call(exercise:),
|
||||
codeharbor_link:
|
||||
)
|
||||
if error.nil?
|
||||
successful_exports << exercise.id
|
||||
|
Reference in New Issue
Block a user