debian-mirror-gitlab/spec/models/ml/experiment_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
2.5 KiB
Ruby
Raw Permalink Normal View History

2022-08-27 11:52:29 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe Ml::Experiment, feature_category: :mlops do
2022-11-25 23:54:43 +05:30
let_it_be(:exp) { create(:ml_experiments) }
let_it_be(:exp2) { create(:ml_experiments, project: exp.project) }
let(:iid) { exp.iid }
let(:exp_name) { exp.name }
2022-08-27 11:52:29 +05:30
describe 'associations' do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:candidates) }
2023-03-04 22:38:38 +05:30
it { is_expected.to have_many(:metadata) }
2022-08-27 11:52:29 +05:30
end
2022-10-11 01:57:18 +05:30
2023-06-20 00:43:36 +05:30
describe '.package_name' do
describe '.package_name' do
it { expect(exp.package_name).to eq("ml_experiment_#{exp.iid}") }
end
end
2022-11-25 23:54:43 +05:30
describe '#by_project_id_and_iid' do
2022-10-11 01:57:18 +05:30
subject { described_class.by_project_id_and_iid(exp.project_id, iid) }
context 'if exists' do
it { is_expected.to eq(exp) }
end
context 'if does not exist' do
let(:iid) { non_existing_record_id }
it { is_expected.to be(nil) }
end
end
2022-11-25 23:54:43 +05:30
describe '#by_project_id_and_name' do
2022-10-11 01:57:18 +05:30
subject { described_class.by_project_id_and_name(exp.project_id, exp_name) }
context 'if exists' do
it { is_expected.to eq(exp) }
end
context 'if does not exist' do
let(:exp_name) { 'hello' }
it { is_expected.to be_nil }
end
end
2022-11-25 23:54:43 +05:30
describe '#by_project_id' do
let(:project_id) { exp.project_id }
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
subject { described_class.by_project_id(project_id) }
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
it { is_expected.to match_array([exp, exp2]) }
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
context 'when project does not have experiment' do
let(:project_id) { non_existing_record_iid }
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
it { is_expected.to be_empty }
2022-10-11 01:57:18 +05:30
end
end
2023-04-23 21:23:45 +05:30
describe '#with_candidate_count' do
let_it_be(:exp3) do
create(:ml_experiments, project: exp.project).tap do |e|
create_list(:ml_candidates, 3, experiment: e, user: nil)
create(:ml_candidates, experiment: exp2, user: nil)
end
end
subject { described_class.with_candidate_count.to_h { |e| [e.id, e.candidate_count] } }
it 'fetches the candidate count', :aggregate_failures do
expect(subject[exp.id]).to eq(0)
expect(subject[exp2.id]).to eq(1)
expect(subject[exp3.id]).to eq(3)
end
end
2023-06-20 00:43:36 +05:30
describe '#package_for_experiment?' do
using RSpec::Parameterized::TableSyntax
subject { described_class.package_for_experiment?(package_name) }
where(:package_name, :id) do
'ml_experiment_1234' | true
'ml_experiment_1234abc' | false
'ml_experiment_abc' | false
'ml_experiment_' | false
'blah' | false
end
with_them do
it { is_expected.to be(id) }
end
end
2022-08-27 11:52:29 +05:30
end