<commit_before>require 'test_helper'
require 'tempfile'

module ImageTests
  def self.included spec_class
    spec_class.class_eval do

      let(:imgfile) { 'test/480x270.jpg' }
      let(:img) { MicroMagick::Convert.new(imgfile) }

      let(:corrupt) { MicroMagick::Convert.new('test/borked.jpg') }

      # By using the block format, the tempfile will be closed and deleted:
      let(:outfile) { Tempfile.open(%w(out .jpg)) { |ea| ea.path } }

      it 'extracts image geometry correctly' do
        img.width.must_equal 270
        img.height.must_equal 480
        img.corrupt?.must_be_false
      end

      def corrupt_checks_broken
        MicroMagick.imagemagick? && MicroMagick.version < Gem::Version.new('6.7.0')
      end

      it 'detects corrupt images properly' do
        if corrupt_checks_broken
          puts "skipping .corrupt? tests"
        else
          corrupt.width.must_be_nil
          corrupt.height.must_be_nil
          corrupt.corrupt?.must_be_true
        end
      end

      it 'extracts image geometry for problematic JPGs' do
        jpg = MicroMagick::Image.new('test/bad_exif.jpg')
        jpg.width.must_equal(1944)
        jpg.height.must_equal(2592)
      end

      it 'resizes to cropped square' do
        img.resize('64x64')
        command = img.write(outfile)
        command.must_equal "#{MicroMagick.cmd_prefix}convert -size 64x64 test/480x270.jpg -resize 64x64 " + Shellwords.escape(outfile)
        File.exist?(outfile).must_be_true
        g = MicroMagick::Geometry.new(outfile)
        g.width.must_equal 64 * 270 / 480
        g.height.must_equal 64
      end

      it 'removes exif headers from .strip' do
        img.strip
        command = img.write(outfile)
        command.must_equal "#{MicroMagick.cmd_prefix}convert test/480x270.jpg +profile \\* " + Shellwords.escape(outfile)

        stripped = MicroMagick::Image.new(outfile)
        stripped.corrupt?.must_be_false
        stripped.width.must_equal img.width
        stripped.height.must_equal img.height
<commit_msg>use skip properly<commit_after>require 'test_helper'
require 'tempfile'

module ImageTests
  def self.included spec_class
    spec_class.class_eval do

      let(:imgfile) { 'test/480x270.jpg' }
      let(:img) { MicroMagick::Convert.new(imgfile) }

      let(:corrupt) { MicroMagick::Convert.new('test/borked.jpg') }

      # By using the block format, the tempfile will be closed and deleted:
      let(:outfile) { Tempfile.open(%w(out .jpg)) { |ea| ea.path } }

      it 'extracts image geometry correctly' do
        img.width.must_equal 270
        img.height.must_equal 480
        img.corrupt?.must_be_false
      end

      def old_imagemagick
        MicroMagick.imagemagick? && MicroMagick.version < Gem::Version.new('6.7.0')
      end

      it 'detects corrupt images properly' do
        skip "Old ImageMagick versions don't detect corruption properly" if old_imagemagick
        corrupt.width.must_be_nil
        corrupt.height.must_be_nil
        corrupt.corrupt?.must_be_true
      end

      it 'extracts image geometry for problematic JPGs' do
        jpg = MicroMagick::Image.new('test/bad_exif.jpg')
        jpg.width.must_equal(1944)
        jpg.height.must_equal(2592)
      end

      it 'resizes to cropped square' do
        img.resize('64x64')
        command = img.write(outfile)
        command.must_equal "#{MicroMagick.cmd_prefix}convert -size 64x64 test/480x270.jpg -resize 64x64 " + Shellwords.escape(outfile)
        File.exist?(outfile).must_be_true
        g = MicroMagick::Geometry.new(outfile)
        g.width.must_equal 64 * 270 / 480
        g.height.must_equal 64
      end

      it 'removes exif headers from .strip' do
        img.strip
        command = img.write(outfile)
        command.must_equal "#{MicroMagick.cmd_prefix}convert test/480x270.jpg +profile \\* " + Shellwords.escape(outfile)

        stripped = MicroMagick::Image.new(outfile)
        stripped.corrupt?.must_be_false
        stripped.width.must_equal img.width
        stripped.height.must_equal img.height

{'fraction_non_alphanumeric': 0.09931000492853623, 'fraction_numerical': 0.028092656481025137, 'mean_word_length': 2.624107142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735356', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1282, 'n_words': 268}