<commit_before>require 'digest/md5'
require 'mini_exiftool'
require 'fileutils'
require 'tempfile'
require 'test/unit'
begin
  require 'turn'
rescue LoadError
end

class TestSave < Test::Unit::TestCase

  def setup
    @temp_file = Tempfile.new('test')
    @temp_file.close
    @temp_filename = @temp_file.path
    @org_filename = File.dirname(__FILE__) + '/data/test.jpg'
    FileUtils.cp(@org_filename, @temp_filename)
    @mini_exiftool = MiniExiftool.new @temp_filename
    @mini_exiftool_num = MiniExiftool.new @temp_filename, :numerical => true
    @org_md5 = Digest::MD5.hexdigest(File.read(@org_filename))
  end

  def test_allowed_value
    assert_equal @org_md5, @org_md5
    @mini_exiftool_num['Orientation'] = 2
    result = @mini_exiftool_num.save
    assert_equal true, result
    assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@org_filename))
    assert_not_equal @org_md5, Digest::MD5.hexdigest(File.read(@temp_filename))
    assert_equal false, @mini_exiftool_num.changed?
    result = @mini_exiftool_num.save
    assert_equal false, result
  end

  def test_non_allowed_value
    @mini_exiftool['Orientation'] = 'some string'
    result = @mini_exiftool.save
    assert_equal false, result
    assert_equal 1, @mini_exiftool.errors.size
    assert_equal("Can't convert IFD0:Orientation (not in PrintConv)",
                 @mini_exiftool.errors['Orientation'])
    assert @mini_exiftool.changed?
    assert @mini_exiftool.changed_tags.include?('Orientation')
  end

  def test_no_changing_of_file_when_error
    @mini_exiftool['ISO'] = 800
    @mini_exiftool['Orientation'] = 'some value'
    @mini_exiftool['ExposureTime'] = '1/30'
    result = @mini_exiftool.save
    assert_equal false, result
    assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@org_filename))
    assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@temp_filename))
  end

end
<commit_msg>Deleting unnecessary Line in Test.<commit_after>require 'digest/md5'
require 'mini_exiftool'
require 'fileutils'
require 'tempfile'
require 'test/unit'
begin
  require 'turn'
rescue LoadError
end

class TestSave < Test::Unit::TestCase

  def setup
    @temp_file = Tempfile.new('test')
    @temp_file.close
    @temp_filename = @temp_file.path
    @org_filename = File.dirname(__FILE__) + '/data/test.jpg'
    FileUtils.cp(@org_filename, @temp_filename)
    @mini_exiftool = MiniExiftool.new @temp_filename
    @mini_exiftool_num = MiniExiftool.new @temp_filename, :numerical => true
    @org_md5 = Digest::MD5.hexdigest(File.read(@org_filename))
  end

  def test_allowed_value
    @mini_exiftool_num['Orientation'] = 2
    result = @mini_exiftool_num.save
    assert_equal true, result
    assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@org_filename))
    assert_not_equal @org_md5, Digest::MD5.hexdigest(File.read(@temp_filename))
    assert_equal false, @mini_exiftool_num.changed?
    result = @mini_exiftool_num.save
    assert_equal false, result
  end

  def test_non_allowed_value
    @mini_exiftool['Orientation'] = 'some string'
    result = @mini_exiftool.save
    assert_equal false, result
    assert_equal 1, @mini_exiftool.errors.size
    assert_equal("Can't convert IFD0:Orientation (not in PrintConv)",
                 @mini_exiftool.errors['Orientation'])
    assert @mini_exiftool.changed?
    assert @mini_exiftool.changed_tags.include?('Orientation')
  end

  def test_no_changing_of_file_when_error
    @mini_exiftool['ISO'] = 800
    @mini_exiftool['Orientation'] = 'some value'
    @mini_exiftool['ExposureTime'] = '1/30'
    result = @mini_exiftool.save
    assert_equal false, result
    assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@org_filename))
    assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@temp_filename))
  end

end

{'fraction_non_alphanumeric': 0.11002380322665961, 'fraction_numerical': 0.011108172441153134, 'mean_word_length': 4.687218045112782, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5786364', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1306, 'n_words': 233}