tests: skip ugoira tests if ffmpeg/mkvmerge not installed.

This commit is contained in:
evazion
2019-09-01 13:10:37 -05:00
parent 3216f83ad8
commit 6e7b882dda
5 changed files with 22 additions and 30 deletions

View File

@@ -37,7 +37,6 @@ gem 'httparty'
gem 'rakismet' gem 'rakismet'
gem 'recaptcha', require: "recaptcha/rails" gem 'recaptcha', require: "recaptcha/rails"
gem 'activemodel-serializers-xml' gem 'activemodel-serializers-xml'
gem 'ptools'
gem 'jquery-rails' gem 'jquery-rails'
gem 'webpacker', '>= 4.0.x' gem 'webpacker', '>= 4.0.x'
gem 'retriable' gem 'retriable'

View File

@@ -152,8 +152,6 @@ GEM
ffaker (2.12.0) ffaker (2.12.0)
ffi (1.11.1) ffi (1.11.1)
ffi (1.11.1-x64-mingw32) ffi (1.11.1-x64-mingw32)
ffi-win32-extensions (1.0.3)
ffi
flamegraph (0.9.5) flamegraph (0.9.5)
get_process_mem (0.2.4) get_process_mem (0.2.4)
ffi (~> 1.0) ffi (~> 1.0)
@@ -290,9 +288,6 @@ GEM
unicode (~> 0.4.4) unicode (~> 0.4.4)
pry-rails (0.3.9) pry-rails (0.3.9)
pry (>= 0.10.4) pry (>= 0.10.4)
ptools (1.3.5)
ptools (1.3.5-universal-mingw32)
win32-file (>= 0.7.0)
public_suffix (3.1.1) public_suffix (3.1.1)
rack (2.0.7) rack (2.0.7)
rack-contrib (2.1.0) rack-contrib (2.1.0)
@@ -440,14 +435,6 @@ GEM
websocket-extensions (0.1.4) websocket-extensions (0.1.4)
whenever (1.0.0) whenever (1.0.0)
chronic (>= 0.6.3) chronic (>= 0.6.3)
win32-file (0.8.2)
ffi
ffi-win32-extensions
win32-file-stat (>= 1.4.0)
win32-file-stat (1.5.5)
ffi
ffi-win32-extensions
win32console (1.3.2)
zeitwerk (2.1.9) zeitwerk (2.1.9)
PLATFORMS PLATFORMS
@@ -496,7 +483,6 @@ DEPENDENCIES
pry-byebug pry-byebug
pry-inline pry-inline
pry-rails pry-rails
ptools
rack-mini-profiler rack-mini-profiler
rails (~> 6.0) rails (~> 6.0)
rakismet rakismet

View File

@@ -1,5 +1,11 @@
class PixivUgoiraConverter class PixivUgoiraConverter
def self.enabled?
system("type -p ffmpeg > /dev/null") && system("type -p mkvmerge > /dev/null")
end
def self.generate_webm(ugoira_file, frame_data) def self.generate_webm(ugoira_file, frame_data)
raise NotImplementedError, "can't convert ugoira to webm: ffmpeg or mkvmerge not installed" unless enabled?
folder = Zip::File.new(ugoira_file.path) folder = Zip::File.new(ugoira_file.path)
output_file = Tempfile.new(binmode: true) output_file = Tempfile.new(binmode: true)
write_path = output_file.path write_path = output_file.path

View File

@@ -94,16 +94,15 @@ class UploadServiceTest < ActiveSupport::TestCase
end end
should "work on an ugoira url" do should "work on an ugoira url" do
begin skip unless PixivUgoiraConverter.enabled?
file = subject.get_file_for_upload(@upload) file = subject.get_file_for_upload(@upload)
assert_not_nil(@upload.context["ugoira"]) assert_not_nil(@upload.context["ugoira"])
assert_operator(File.size(file.path), :>, 0) assert_operator(File.size(file.path), :>, 0)
file.close file.close
rescue Net::OpenTimeout rescue Net::OpenTimeout
skip "network failure" skip "network failure"
end
end end
end end
end end
@@ -227,6 +226,8 @@ class UploadServiceTest < ActiveSupport::TestCase
end end
should "generate a preview and a video" do should "generate a preview and a video" do
skip unless PixivUgoiraConverter.enabled?
preview, crop, sample = subject.generate_resizes(@file, @upload) preview, crop, sample = subject.generate_resizes(@file, @upload)
assert_operator(File.size(preview.path), :>, 0) assert_operator(File.size(preview.path), :>, 0)
assert_operator(File.size(crop.path), :>, 0) assert_operator(File.size(crop.path), :>, 0)
@@ -454,6 +455,8 @@ class UploadServiceTest < ActiveSupport::TestCase
end end
should "download the file" do should "download the file" do
skip unless PixivUgoiraConverter.enabled?
@service = subject.new(source: @source) @service = subject.new(source: @source)
begin begin
@upload = @service.start! @upload = @service.start!
@@ -848,7 +851,7 @@ class UploadServiceTest < ActiveSupport::TestCase
context "a post that is replaced by a ugoira" do context "a post that is replaced by a ugoira" do
should "save the frame data" do should "save the frame data" do
skip "ffmpeg not installed" unless check_ffmpeg skip "ffmpeg not installed" unless PixivUgoiraConverter.enabled?
begin begin
as_user { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") } as_user { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") }
@post.reload @post.reload
@@ -871,6 +874,8 @@ class UploadServiceTest < ActiveSupport::TestCase
context "a post that is replaced to another file then replaced back to the original file" do context "a post that is replaced to another file then replaced back to the original file" do
should "not delete the original files" do should "not delete the original files" do
begin begin
skip unless PixivUgoiraConverter.enabled?
# this is called thrice to delete the file for 62247364 # this is called thrice to delete the file for 62247364
FileUtils.expects(:rm_f).times(3) FileUtils.expects(:rm_f).times(3)
@@ -910,6 +915,8 @@ class UploadServiceTest < ActiveSupport::TestCase
# swap the images between @post1 and @post2. # swap the images between @post1 and @post2.
begin begin
as_user do as_user do
skip unless PixivUgoiraConverter.enabled?
@post1.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350") @post1.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
@post2.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") @post2.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
assert_equal("4ceadc314938bc27f3574053a3e1459a", @post1.md5) assert_equal("4ceadc314938bc27f3574053a3e1459a", @post1.md5)

View File

@@ -1,5 +1,3 @@
require 'ptools'
module DownloadTestHelper module DownloadTestHelper
def assert_downloaded(expected_filesize, source, referer=nil) def assert_downloaded(expected_filesize, source, referer=nil)
download = Downloads::File.new(source, referer) download = Downloads::File.new(source, referer)
@@ -33,8 +31,4 @@ module DownloadTestHelper
res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers)) res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers))
assert_equal(size, res.content_length) assert_equal(size, res.content_length)
end end
def check_ffmpeg
File.which("ffmpeg") && File.which("mkvmerge")
end
end end