File: test_io.rb

package info (click to toggle)
ruby-mini-exiftool 2.9.0-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 688 kB
  • sloc: ruby: 2,616; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -- encoding: utf-8 --
require 'helpers_for_test'
require 'stringio'

class TestIo < TestCase

  def test_simple_case
    io = open_real_io
    mini_exiftool = MiniExiftool.new(io)
    assert_equal false, io.closed?, 'IO should not be closed.'
    assert_equal 400, mini_exiftool.iso
  end

  def test_non_readable_io
    assert_raises MiniExiftool::Error do
      begin
        MiniExiftool.new($stdout)
      rescue MiniExiftool::Error => e
        assert_equal 'IO is not readable.', e.message
        raise e
      end
    end
  end

  def test_no_writing_when_using_io
    io = open_real_io
    m = MiniExiftool.new(io)
    m.iso = 100
    assert_raises MiniExiftool::Error do
      begin
        m.save
      rescue MiniExiftool::Error => e
        assert_equal 'No writing support when using an IO.', e.message
        raise e
      end
    end
  end

  def test_fast_options
    $DEBUG = true
    s = StringIO.new
    $stderr = s
    MiniExiftool.new open_real_io
    s.rewind
    assert_match /^exiftool -j  "-"$/, s.read
    s = StringIO.new
    $stderr = s
    MiniExiftool.new open_real_io, :fast => true
    s.rewind
    assert_match /^exiftool -j -fast  "-"$/, s.read
    s = StringIO.new
    $stderr = s
    MiniExiftool.new open_real_io, :fast2 => true
    s.rewind
    assert_match /^exiftool -j -fast2  "-"$/, s.read
  ensure
    $DEBUG = false
    $stderr = STDERR
  end

  protected

  def open_real_io
    File.open(File.join(File.dirname(__FILE__), 'data', 'test.jpg'), 'r')
  end

end