Skip to content

Commit

Permalink
WIP: #run_machine_learning_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Apr 11, 2024
1 parent 47a71b5 commit 398c623
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions spec/models/machine_learning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,44 +377,44 @@ def full_sanitizer(string)
end
end

# describe "#run_machine_learning_scripts" do
# it "returns true if python script executed correctly" do
# machine_learning = MachineLearning.new(job)
#
# command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1"
# expect(machine_learning).to receive(:`).with(command) do
# Process.waitpid Process.fork { exit 0 }
# end
#
# expect(Mailer).not_to receive(:machine_learning_error)
#
# expect(machine_learning.send(:run_machine_learning_scripts)).to be true
#
# job.reload
# expect(job.finished_at).not_to be_present
# expect(job.error).not_to be_present
# end
#
# it "returns false if python script errored" do
# machine_learning = MachineLearning.new(job)
#
# command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1"
# expect(machine_learning).to receive(:`).with(command) do
# Process.waitpid Process.fork { abort "error message" }
# end
#
# mailer = double("mailer")
# expect(mailer).to receive(:deliver_later)
# expect(Mailer).to receive(:machine_learning_error).and_return mailer
#
# expect(machine_learning.send(:run_machine_learning_scripts)).to be false
#
# job.reload
# expect(job.finished_at).to be_present
# expect(job.error).not_to eq "error message"
# end
# end
#
describe "#run_machine_learning_scripts" do
it "returns true if python script executed correctly" do
machine_learning = MachineLearning.new(job)

command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1"
expect(machine_learning).to receive(:`).with(command) do
Process.waitpid Process.fork { exit 0 }
end

expect(Mailer).not_to receive(:machine_learning_error)

expect(machine_learning.send(:run_machine_learning_scripts)).to be true

job.reload
expect(job.finished_at).not_to be_present
expect(job.error).not_to be_present
end

it "returns false if python script errored" do
machine_learning = MachineLearning.new(job)

command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1"
expect(machine_learning).to receive(:`).with(command) do
Process.waitpid Process.fork { abort "error message" }
end

mailer = double("mailer")
expect(mailer).to receive(:deliver_later)
expect(Mailer).to receive(:machine_learning_error).and_return mailer

expect(machine_learning.send(:run_machine_learning_scripts)).to be false

job.reload
expect(job.finished_at).to be_present
expect(job.error).not_to eq "error message"
end
end

# describe "#import_ml_proposals_comments_summary" do
# it "feeds the database using content from the JSON file generated by the machine learning script" do
# machine_learning = MachineLearning.new(job)
Expand Down

0 comments on commit 398c623

Please sign in to comment.