Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add minitest framework #846

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ jobs:
- name: install gems
run: bundle install

- name: test
- name: rspec test
run: bundle exec rake spec

- name: mini test
run: bundle exec rake test
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "minitest/test_task"

RSpec::Core::RakeTask.new(:spec)


Minitest::TestTask.create(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.warning = false
t.test_globs = ["test/**/*_test.rb"]
end

task :default => :spec
2 changes: 2 additions & 0 deletions ood_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "pry", "~> 0.10"
spec.add_development_dependency "timecop", "~> 0.8"
spec.add_development_dependency "climate_control", "~> 1.2.0"
spec.add_development_dependency "minitest", "~> 5"
spec.add_development_dependency "mocha", "~> 2.4"
end
24 changes: 24 additions & 0 deletions test/job/adapters/slurm_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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)
Comment on lines +13 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces this line from rspec. Minitest doesn't have the same facility, but I've added some helper methods to do the same.

it { is_expected.to respond_to(:submit).with(1).argument.and_keywords(:after, :afterok, :afternotok, :afterany) }

end

def test_submitting_with_hold
slurm = slurm_instance
stub_submit
OodCore::Job::Adapters::Slurm::Batch.any_instance.expects(:submit_string).with(script_content, args: ["-H", "--export", "NONE"], env: {})
slurm.submit(build_script(submit_as_hold: true))
end
Comment on lines +18 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test replaces this rspec test below, and just reinforces my issue with rspec. Here in mintest we see what I have to stub Open3 because at some point calling submit on an adapter will result in an Open3.capture3 call.

I guess I just like the explicit nature of Minitest. How is rspec stubbing Open3? I guess it doesn't need to? Like somehow calling submit will stop execution once slurm.submit_string is called? There's just a bit too much magic happening, to the point where I'm not really even sure what code is being executed during this test.

context "with :submit_as_hold" do
context "as true" do
before { adapter.submit(build_script(submit_as_hold: true)) }
it { expect(slurm).to have_received(:submit_string).with(content, args: ["-H", "--export", "NONE"], env: {}) }
end

end
49 changes: 49 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'ood_core'
require 'mocha/minitest'

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

def build_script(opts = {})
OodCore::Job::Script.new(
**{
content: script_content
}.merge(opts)
)
end

def script_content
"my job script"
end

def stub_submit(jobid = '123')
Open3.stubs(:capture3).returns([jobid, '', exit_success])
end

def exit_success
OpenStruct.new(:success? => true, :exitstatus => 0)
end
end
Loading