Skip to content

Commit

Permalink
Rake task for running tests: '$ rake tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzido committed Mar 31, 2013
1 parent ce4f29f commit c6a32eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
require 'rake'
require 'rake/testtask'
require './tabula_web.rb'
require 'resque/tasks'


Rake::TestTask.new do |t|
t.pattern = 'test/**/test_*.rb'
end
27 changes: 22 additions & 5 deletions test/test_table_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@
class TestTableAnalyzer < MiniTest::Unit::TestCase
def setup
@tmp_dir = Dir.mktmpdir
@script_path = File.expand_path(File.dirname(__FILE__))
end

def teardown
FileUtils.remove_entry_secure @tmp_dir
end

# HOW TO WRITE A TEST - EXAMPLE
# def test_some_pdf
# run_jruby_extractor!(File.join(@script_path,'test_pdfs/some_file.pdf'))
# # get the coordinates from the web app (URL that gets requested when you do a lasso)
# text_elements = Tabula::XML.get_text_elements(@tmp_dir, 1, 12.75, 269.875, 561, 790.5)
# table = Tabula.make_table(text_elements) # table is an array of Tabula::Line
# table = lines_to_array(table) # you can convert it to a list of lists of strings, for convenience
#
# expected = [['foo', 'bar'], ['quuxor', 'wat?']] # what you expect from the table analyzer
#
# assert_equal lines_to_array(table), expected # assert the equality
# end


def test_argentina_diputados_voting_record
run_jruby_extractor!('test_pdfs/argentina_diputados_voting_record.pdf')
run_jruby_extractor!(File.join(@script_path,'test_pdfs/argentina_diputados_voting_record.pdf'))

text_elements = Tabula::XML.get_text_elements(@tmp_dir, 1, 12.75, 269.875, 561, 790.5)
table = Tabula.make_table(text_elements)
Expand All @@ -30,7 +45,7 @@ def test_argentina_diputados_voting_record
end

def test_pharma_spaceless
run_jruby_extractor!('test_pdfs/ClinicalResearchDisclosureReport2012Q2.pdf')
run_jruby_extractor!(File.join(@script_path, 'test_pdfs/ClinicalResearchDisclosureReport2012Q2.pdf'))

text_elements = Tabula::XML.get_text_elements(@tmp_dir, 1, 49.9375, 85, 537.625, 130.6875)
table = Tabula.make_table(text_elements)
Expand All @@ -43,7 +58,8 @@ def test_pharma_spaceless
end

def test_bo_page24
run_jruby_extractor!('test_pdfs/bo_page24.pdf')
skip("FAILING - CHARACTERS APPEAR OUT OF ORDER")
run_jruby_extractor!(File.join(@script_path,'test_pdfs/bo_page24.pdf'))
# Request URL:http://localhost:9393/pdf/d1bfae1be8d6b099c1b7bb7b401ca97310e61063/data?x1=50.089285714285715&x2=809.0178571428571&y1=432.5892857142857&y2=490.2678571428571&page=1

text_elements = Tabula::XML.get_text_elements(@tmp_dir, 1, 50.089, 432.589, 809.017, 490.267)
Expand All @@ -63,9 +79,10 @@ def lines_to_array(lines)
end

def run_jruby_extractor!(pdf_path)
jruby_script_path = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib/jruby_dump_characters.rb')
jar_path = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib/jars')
jruby_script_path = File.join(@script_path, '..', 'lib/jruby_dump_characters.rb')
jar_path = File.join(@script_path, '..', 'lib/jars')
jars = File.join(jar_path, 'pdfbox-app-1.8.0.jar')
system({'CLASSPATH' => jars}, "#{Settings::JRUBY_PATH} --1.9 --server #{jruby_script_path} #{pdf_path} #{@tmp_dir} > /dev/null 2>&1")

end
end

0 comments on commit c6a32eb

Please sign in to comment.