Skip to content

Commit

Permalink
refactor respect interface test
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Jul 15, 2024
1 parent cc79d49 commit b276bcd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/job/adapters/slurm_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'

class TestSlurm < Minitest::Test
include TestHelper

def slurm_instance(config = {})
OodCore::Job::Factory.build({ adapter: 'slurm' }.merge(config))
end

def test_submit_interface
slurm = slurm_instance

assert(slurm.respond_to?(:submit))
veryify_keywords(slurm, :submit, [:after, :afterok, :afternotok, :afterany])
verify_args(slurm, :submit, 1)
end
end
28 changes: 28 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'ood_core'

module TestHelper

# verify the keywords of an objects interface.
# Example: given the interface - def foo(bar: nil)
# veryify_keywords(object, :foo, [:bar])
# to verify that the method foo takes only one keyword :bar.
def veryify_keywords(object, method, keywords)
parameters = object.method(method.to_sym).parameters
actual_keywords = parameters.select do |key, _value|
key.to_sym == :key
end.map do |_key, value|
value
end.sort

assert_equal(keywords.sort, actual_keywords)
end

def verify_args(object, method, num_of_args)
parameters = object.method(method.to_sym).parameters
actual_num_of_args = parameters.select do |key, _value|
key.to_sym == :req || key.to_sym == :opt
end.count

assert_equal(actual_num_of_args, num_of_args)
end
end

0 comments on commit b276bcd

Please sign in to comment.