From c727877ffe9e70aeec4c2c99f3db35f1ed6695c0 Mon Sep 17 00:00:00 2001 From: Paul Keen <125715+pftg@users.noreply.github.com> Date: Sun, 20 Dec 2020 16:44:28 +0200 Subject: [PATCH] Fixes GitHub action configurations and make tests works --- .github/workflows/test.yml | 32 ++--- .yardopts | 1 - Gemfile | 2 - ruby-vips.gemspec | 2 +- spec/connection_spec.rb | 285 ++++++++++++++++++------------------- spec/image_spec.rb | 38 +++-- spec/mutate_spec.rb | 2 +- spec/region_spec.rb | 30 ++-- spec/spec_helper.rb | 37 +++-- 9 files changed, 206 insertions(+), 223 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6fe8dd9e..fc076955 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,8 @@ env: SPEC_OPTS: '--backtrace' jobs: - name: Lint + lint: + name: Lint runs-on: ubuntu-latest steps: @@ -24,15 +25,15 @@ jobs: bundler-cache: true - name: Run Standard Ruby linter - run: bin/standardrb --no-fix --fail-fast + run: bundle exec standardrb --no-fix --fail-fast continue-on-error: true test: name: Functional Testing - runs-on: ubuntu-20.04 # In order to install libvips 8.9+ version strategy: matrix: + os-version: [ 'ubuntu-20.04' ] ruby-version: - 2.1 - 2.2 @@ -42,6 +43,9 @@ jobs: - 2.6 - 2.7 - jruby + fail-fast: true + + runs-on: ${{ matrix.os-version }} steps: - name: Checkout code @@ -62,28 +66,8 @@ jobs: env: DEBIAN_FRONTEND: noninteractive run: - sudo apt install --fix-missing -qq --no-install-recommends -o Acquire::Retries=3 + sudo apt install --fix-missing -qq -o Acquire::Retries=3 libvips libvips-dev libvips-tools - gettext - libcfitsio-dev - libexpat1-dev - libfftw3-dev - libgif-dev - libglib2.0-dev - libgsf-1-dev - libjpeg-turbo8-dev - liblcms2-dev - libmagickwand-dev - libmatio-dev - libopenexr-dev - libopenslide-dev - liborc-0.4-dev - libpango1.0-dev - libpoppler-glib-dev - libtiff5-dev - libwebp-dev - librsvg2-dev - libmagick++-dev - name: Run Tests run: bundle exec rake spec diff --git a/.yardopts b/.yardopts index 98b43161..cc365c89 100644 --- a/.yardopts +++ b/.yardopts @@ -1,2 +1 @@ ---markup-provider=redcarpet --markup=markdown diff --git a/Gemfile b/Gemfile index 971b2d89..03e75f05 100644 --- a/Gemfile +++ b/Gemfile @@ -4,5 +4,3 @@ source 'https://rubygems.org' gemspec gem 'github-markup' -gem 'redcarpet', platforms: :ruby -gem 'standard', platforms: :ruby diff --git a/ruby-vips.gemspec b/ruby-vips.gemspec index 4dc37d11..6576a454 100644 --- a/ruby-vips.gemspec +++ b/ruby-vips.gemspec @@ -47,7 +47,7 @@ and it can process large images without loading the whole image in memory. # RuboCop requires Ruby >= 2.2 if Gem.ruby_version >= Gem::Version.new("2.2") - spec.add_development_dependency "rubocop", ["~> 0.64"] + spec.add_development_dependency "standard" end end diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index 78bf3eda..c2587dc8 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -1,170 +1,163 @@ require 'spec_helper.rb' -if Vips::at_least_libvips?(8, 9) - RSpec.describe Vips::Source do - it 'can create a source from a descriptor' do - source = Vips::Source.new_from_descriptor(0) +RSpec.describe Vips::Source, version: [8, 9] do + it 'can create a source from a descriptor' do + source = Vips::Source.new_from_descriptor(0) - expect(source) - end + expect(source) + end - it 'can create a source from a filename' do - source = Vips::Source.new_from_file simg('wagon.jpg') + it 'can create a source from a filename' do + source = Vips::Source.new_from_file simg('wagon.jpg') - expect(source) - end + expect(source) + end - it 'can\'t create a source from a bad filename' do - expect { - Vips::Source.new_from_file simg('banana.jpg') - }.to raise_exception(Vips::Error) - end + it 'can\'t create a source from a bad filename' do + expect { + Vips::Source.new_from_file simg('banana.jpg') + }.to raise_exception(Vips::Error) + end - it 'can create a source from an area of memory' do - str = File.open(simg('wagon.jpg'), 'rb').read - source = Vips::Source.new_from_memory str + it 'can create a source from an area of memory' do + str = File.open(simg('wagon.jpg'), 'rb').read + source = Vips::Source.new_from_memory str - expect(source) - end + expect(source) + end - it 'sources have filenames and nicks' do - source = Vips::Source.new_from_file simg('wagon.jpg') + it 'sources have filenames and nicks' do + source = Vips::Source.new_from_file simg('wagon.jpg') - expect(source.filename).to eq(simg('wagon.jpg')) - expect(source.nick) - end + expect(source.filename).to eq(simg('wagon.jpg')) + expect(source.nick) + end - it 'can load an image from filename source' do - source = Vips::Source.new_from_file simg('wagon.jpg') - image = Vips::Image.new_from_source source, '' + it 'can load an image from filename source' do + source = Vips::Source.new_from_file simg('wagon.jpg') + image = Vips::Image.new_from_source source, '' - expect(image) - expect(image.width).to eq(685) - expect(image.height).to eq(478) - expect(image.bands).to eq(3) - expect(image.avg).to be_within(0.001).of(109.789) + expect(image) + expect(image.width).to eq(685) + expect(image.height).to eq(478) + expect(image.bands).to eq(3) + expect(image.avg).to be_within(0.001).of(109.789) - end end end -if Vips::at_least_libvips?(8, 9) - RSpec.describe Vips::Target do - it 'can create a target to a filename' do - target = Vips::Target.new_to_file timg('x.jpg') - - expect(target) - end - - it 'can create a target to a descriptor' do - target = Vips::Target.new_to_descriptor 1 - - expect(target) - end - - it 'can create a target to a memory area' do - target = Vips::Target.new_to_memory - - expect(target) - end - - it 'can\'t create a target to a bad filename' do - expect { - Vips::Target.new_to_file '/banana/monkey' - }.to raise_exception(Vips::Error) - end - - it 'can save an image to a filename target' do - source = Vips::Source.new_from_file simg('wagon.jpg') - image = Vips::Image.new_from_source source, '' - filename = timg('x4.png') - target = Vips::Target.new_to_file filename - image.write_to_target target, '.png' - - image = Vips::Image.new_from_file filename - expect(image) - expect(image.width).to eq(685) - expect(image.height).to eq(478) - expect(image.bands).to eq(3) - expect(image.avg).to be_within(0.001).of(109.789) - end - - it 'can save an image to a memory target' do - source = Vips::Source.new_from_file simg('wagon.jpg') - image = Vips::Image.new_from_source source, '' - target = Vips::Target.new_to_memory - image.write_to_target target, '.png' - memory = target.get('blob') - - image = Vips::Image.new_from_buffer memory, '' - expect(image) - expect(image.width).to eq(685) - expect(image.height).to eq(478) - expect(image.bands).to eq(3) - expect(image.avg).to be_within(0.001).of(109.789) - end +RSpec.describe Vips::Target, version: [8, 9] do + it 'can create a target to a filename' do + target = Vips::Target.new_to_file timg('x.jpg') + + expect(target) + end + + it 'can create a target to a descriptor' do + target = Vips::Target.new_to_descriptor 1 + + expect(target) + end + + it 'can create a target to a memory area' do + target = Vips::Target.new_to_memory + expect(target) end + + it 'can\'t create a target to a bad filename' do + expect { + Vips::Target.new_to_file '/banana/monkey' + }.to raise_exception(Vips::Error) + end + + it 'can save an image to a filename target' do + source = Vips::Source.new_from_file simg('wagon.jpg') + image = Vips::Image.new_from_source source, '' + filename = timg('x4.png') + target = Vips::Target.new_to_file filename + image.write_to_target target, '.png' + + image = Vips::Image.new_from_file filename + expect(image) + expect(image.width).to eq(685) + expect(image.height).to eq(478) + expect(image.bands).to eq(3) + expect(image.avg).to be_within(0.001).of(109.789) + end + + it 'can save an image to a memory target' do + source = Vips::Source.new_from_file simg('wagon.jpg') + image = Vips::Image.new_from_source source, '' + target = Vips::Target.new_to_memory + image.write_to_target target, '.png' + memory = target.get('blob') + + image = Vips::Image.new_from_buffer memory, '' + expect(image) + expect(image.width).to eq(685) + expect(image.height).to eq(478) + expect(image.bands).to eq(3) + expect(image.avg).to be_within(0.001).of(109.789) + end + end -if Vips::at_least_libvips?(8, 9) - RSpec.describe Vips::SourceCustom do - it 'can create a custom source' do - source = Vips::SourceCustom.new - - expect(source) - end - - it 'can load a custom source' do - file = File.open simg('wagon.jpg'), "rb" - source = Vips::SourceCustom.new - source.on_read { |length| file.read length } - source.on_seek { |offset, whence| file.seek(offset, whence) } - image = Vips::Image.new_from_source source, "" - - expect(image) - expect(image.width).to eq(685) - expect(image.height).to eq(478) - expect(image.bands).to eq(3) - expect(image.avg).to be_within(0.001).of(109.789) - end - - it 'on_seek is optional' do - file = File.open simg('wagon.jpg'), "rb" - source = Vips::SourceCustom.new - source.on_read { |length| file.read length } - image = Vips::Image.new_from_source source, "" - - expect(image) - expect(image.width).to eq(685) - expect(image.height).to eq(478) - expect(image.bands).to eq(3) - expect(image.avg).to be_within(0.001).of(109.789) - end - - it 'can create a user output stream' do - target = Vips::TargetCustom.new - - expect(target) - end - - it 'can write an image to a user output stream' do - filename = timg('x5.png') - file = File.open filename, "wb" - target = Vips::TargetCustom.new - target.on_write { |chunk| file.write(chunk) } - target.on_finish { file.close } - image = Vips::Image.new_from_file simg('wagon.jpg') - image.write_to_target target, ".png" - - image = Vips::Image.new_from_file filename - expect(image) - expect(image.width).to eq(685) - expect(image.height).to eq(478) - expect(image.bands).to eq(3) - expect(image.avg).to be_within(0.001).of(109.789) - end +RSpec.describe Vips::SourceCustom, version: [8, 9] do + it 'can create a custom source' do + source = Vips::SourceCustom.new + + expect(source) + end + + it 'can load a custom source' do + file = File.open simg('wagon.jpg'), "rb" + source = Vips::SourceCustom.new + source.on_read { |length| file.read length } + source.on_seek { |offset, whence| file.seek(offset, whence) } + image = Vips::Image.new_from_source source, "" + + expect(image) + expect(image.width).to eq(685) + expect(image.height).to eq(478) + expect(image.bands).to eq(3) + expect(image.avg).to be_within(0.001).of(109.789) + end + + it 'on_seek is optional' do + file = File.open simg('wagon.jpg'), "rb" + source = Vips::SourceCustom.new + source.on_read { |length| file.read length } + image = Vips::Image.new_from_source source, "" + + expect(image) + expect(image.width).to eq(685) + expect(image.height).to eq(478) + expect(image.bands).to eq(3) + expect(image.avg).to be_within(0.001).of(109.789) + end + + it 'can create a user output stream' do + target = Vips::TargetCustom.new + + expect(target) + end + it 'can write an image to a user output stream' do + filename = timg('x5.png') + file = File.open filename, "wb" + target = Vips::TargetCustom.new + target.on_write { |chunk| file.write(chunk) } + target.on_finish { file.close } + image = Vips::Image.new_from_file simg('wagon.jpg') + image.write_to_target target, ".png" + + image = Vips::Image.new_from_file filename + expect(image) + expect(image.width).to eq(685) + expect(image.height).to eq(478) + expect(image.bands).to eq(3) + expect(image.avg).to be_within(0.001).of(109.789) end end diff --git a/spec/image_spec.rb b/spec/image_spec.rb index 701320d1..aa30c29a 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -116,7 +116,7 @@ def has_jpeg? expect(im.bands).to eq(3) end - it 'can set scale and offset on a convolution mask' do + it 'can set scale and offset on a convolution mask', version: [8, 10] do image = Vips::Image.new_from_array [1, 2], 8, 2 expect(image.width).to eq(2) expect(image.height).to eq(1) @@ -362,20 +362,18 @@ def has_jpeg? expect(x.bands).to eq(5) end - if Vips::at_least_libvips?(8, 6) - it 'can composite' do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] - image = image.copy interpretation: :srgb - base = image + 10 - overlay = image.bandjoin 128 - comb = base.composite overlay, :over - pixel = comb.getpoint(0, 0) + it 'can composite', version: [8, 6] do + image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + image = image.copy interpretation: :srgb + base = image + 10 + overlay = image.bandjoin 128 + comb = base.composite overlay, :over + pixel = comb.getpoint(0, 0) - expect(pixel[0]).to be_within(0.1).of(105) - expect(pixel[1]).to be_within(0.1).of(133) - expect(pixel[2]).to be_within(0.1).of(135) - expect(pixel[3]).to eq(255) - end + expect(pixel[0]).to be_within(0.1).of(105) + expect(pixel[1]).to be_within(0.1).of(133) + expect(pixel[2]).to be_within(0.1).of(135) + expect(pixel[3]).to eq(255) end it 'has minpos/maxpos' do @@ -659,12 +657,10 @@ def has_jpeg? expect(x.has_alpha?).to be true end - if Vips::at_least_libvips?(8, 6) - it 'can add_alpha' do - x = Vips::Image.new_from_file './spec/samples/no_alpha.png' - expect(x.has_alpha?).to be false - y = x.add_alpha - expect(y.has_alpha?).to be true - end + it 'can add_alpha', version: [8, 6] do + x = Vips::Image.new_from_file './spec/samples/no_alpha.png' + expect(x.has_alpha?).to be false + y = x.add_alpha + expect(y.has_alpha?).to be true end end diff --git a/spec/mutate_spec.rb b/spec/mutate_spec.rb index 87b8b83c..9793757d 100644 --- a/spec/mutate_spec.rb +++ b/spec/mutate_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper.rb' RSpec.describe Vips::MutableImage do - it 'can set! metadata in mutate' do + it 'can set! metadata in mutate', version: [8, 10] do image = Vips::Image.black(16, 16) image = image.mutate do |x| x.set_type! GObject::GINT_TYPE, "banana", 12 diff --git a/spec/region_spec.rb b/spec/region_spec.rb index 6168a541..b8fa85f6 100644 --- a/spec/region_spec.rb +++ b/spec/region_spec.rb @@ -8,26 +8,22 @@ expect(region) end - if Vips::at_least_libvips?(8, 8) - it 'can fetch pixels from a region' do - image = Vips::Image.black(100, 100) - region = Vips::Region.new image - pixel_data = region.fetch 10, 20, 30, 40 + it 'can fetch pixels from a region', version: [8, 8] do + image = Vips::Image.black(100, 100) + region = Vips::Region.new image + pixel_data = region.fetch 10, 20, 30, 40 - expect(pixel_data) - expect(pixel_data.length == 30 * 40) - end + expect(pixel_data) + expect(pixel_data.length == 30 * 40) end - if Vips::at_least_libvips?(8, 8) - it 'can make regions with width and height' do - image = Vips::Image.black(100, 100) - region = Vips::Region.new image - pixel_data = region.fetch 10, 20, 30, 40 + it 'can make regions with width and height', version: [8, 8] do + image = Vips::Image.black(100, 100) + region = Vips::Region.new image + pixel_data = region.fetch 10, 20, 30, 40 - expect(pixel_data) - expect(region.width == 30) - expect(region.height == 40) - end + expect(pixel_data) + expect(region.width == 30) + expect(region.height == 40) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 581d650e..d4300302 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,10 +3,13 @@ require 'tempfile' require 'pathname' +Vips.set_debug ENV['DEBUG'] +# Vips.leak_set true + module Spec module Path - def root - @root ||= Pathname.new(File.expand_path('..', __FILE__)) + def set_root(path) + @root = Pathname.new(path).expand_path end def sample(*path) @@ -18,12 +21,11 @@ def tmp(*path) end extend self - end - module Helpers - def reset_working! - FileUtils.rm Dir[tmp.join('*.*')], :force => true - FileUtils.mkdir_p(tmp) + private + + def root + @root ||= set_root(File.expand_path('..', __FILE__)) end end end @@ -38,9 +40,24 @@ def timg(name) RSpec.configure do |config| config.include Spec::Path - config.include Spec::Helpers - config.before :each do - reset_working! + config.around do |example| + Dir.mktmpdir do |dir| + set_root(dir) + FileUtils.mkdir_p(Spec::Path.sample) + FileUtils.mkdir_p(Spec::Path.tmp) + example.run + end + end + + config.before(:example, jpeg: true) do + skip 'required jpegload for this spec' unless has_jpeg? + end + + config.before(:example,:version) do |example| + required_version = example.metadata[:version] + unless Vips::at_least_libvips?(*required_version) + skip "required at least #{required_version.join('.')} version of the libvips" + end end end