Browse files

All test passes

  • Loading branch information...
1 parent 4aea43f commit 2482b21bf88d4d34d62e53a2241fce54cf1a0e46 @masom masom committed Dec 28, 2011
Showing with 27 additions and 8 deletions.
  1. +8 −5 lib/tesseract/process.rb
  2. +19 −3 test/tesseract_test.rb
View
13 lib/tesseract/process.rb
@@ -37,9 +37,6 @@ def merge_options!(defaults, options)
if options.has_key? :tesseract_options
@options[:tesseract_options] = defaults[:tesseract_options].merge!(options[:tesseract_options]) if options.has_key? :tesseract_options
- [:tesseract_options, :convert_options].each do |k|
- options.delete(k) if options.has_key? k
- end
end
@@ -51,6 +48,10 @@ def merge_options!(defaults, options)
end
options.delete :convert_options
end
+
+ [:tesseract_options, :convert_options].each do |k|
+ options.delete(k) if options.has_key? k
+ end
@options = defaults.merge options
end
@@ -93,7 +94,8 @@ def generate_convert_command(temp_file)
# Converts the source image to a tiff file.
def to_tiff
temp_file = FileHandler.create_temp_file("#{@hash}.tif")
- system generate_convert_command(temp_file)
+ executed = system generate_convert_command(temp_file)
+ raise RuntimeError, "`#{@options[:convert_command]}` could not be executed." if executed.nil?
temp_file
end
@@ -102,7 +104,8 @@ def tesseract_translation(image_file)
temp_text_file = FileHandler.create_temp_file(@hash.to_s)
config_file = write_configs
txt_file = "#{temp_text_file}.txt"
- system [@options[:tesseract_command], image_file.to_s, temp_text_file.to_s, "-l #{@options[:lang]}", config_file, "&> /dev/null"].join(' ')
+ executed = system [@options[:tesseract_command], image_file.to_s, temp_text_file.to_s, "-l #{@options[:lang]}", config_file, "&> /dev/null"].join(' ')
+ raise RuntimeError, "`#{@options[:tesseract_command]}` could not be executed." if (executed.nil? || executed == false)
out = File.read(txt_file)
File.unlink txt_file
out
View
22 test/tesseract_test.rb
@@ -9,7 +9,7 @@ class TesseractTest < Test::Unit::TestCase
end
should "throw exception" do
assert_raises Exception, Tesseract::DependencyChecker::OS_ERROR do
- Tesseract::Process.new(TEST_FILE)
+ Tesseract::Process.new(TEST_FILE, :check_deps => true)
end
end
teardown do
@@ -24,7 +24,7 @@ class TesseractTest < Test::Unit::TestCase
end
should "throw exception" do
assert_raises Exception, Tesseract::DependencyChecker::IMAGE_MAGICK_ERROR do
- Tesseract::Process.new(TEST_FILE)
+ Tesseract::Process.new(TEST_FILE, :check_deps => true)
end
end
end
@@ -35,7 +35,7 @@ class TesseractTest < Test::Unit::TestCase
end
should "throw exception" do
assert_raises Exception, Tesseract::DependencyChecker::TESSERACT_ERROR do
- Tesseract::Process.new(TEST_FILE)
+ Tesseract::Process.new(TEST_FILE, :check_deps => true)
end
end
end
@@ -85,6 +85,22 @@ class TesseractTest < Test::Unit::TestCase
assert_equal expected, result
end
+ context "tesseract invalid commands" do
+ should "raise an exception when convert could not be executed" do
+ options = {:convert_command => "derp"}
+ tess = Tesseract::Process.new(TEST_FILE, options)
+ assert_raises RuntimeError do
+ tess.to_s
+ end
+ end
+ should "raise an exception when tesseract could not be executed" do
+ options = {:tesseract_command => "derp"}
+ tess = Tesseract::Process.new(TEST_FILE, options)
+ assert_raises RuntimeError do
+ tess.to_s
+ end
+ end
+ end
end
context "tesseract diff lang" do

0 comments on commit 2482b21

Please sign in to comment.