<< Masa.20100915-update-limitation-text | 2010 | Masa.20100913-test-import_gkv >>
Confirm Error again
masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb /home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency Loaded suite test/util/test_updater Started ..."get-in import_gkv" url=http://hogehoge/ F. Finished in 0.038145 seconds. 1) Failure: test_import_gkv(ODDB::Util::TestUpdater) [test/util/test_updater.rb:122:in `test_import_gkv' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing' /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `download_latest' /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:59:in `import_gkv' test/util/test_updater.rb:127:in `test_import_gkv']: in mock 'flexmock(ODDB::Import::Gkv)': <"wirkstoffkuerzel-200610.xls"> expected but was <"http://hogehoge/">. 5 tests, 10 assertions, 1 failures, 0 errors
Experiment
def test_import_gkv today = Date.new(2006,10) flexmock(Util::Mail).should_receive(:notify_admins)\ .with(String, Array).times(1) gkv = flexmock(Import::Gkv).new_instances gkv.should_receive(:current_date).and_return today pdf_url = 'https://www.gkv-spitzenverband.de/upload/Zuzahlungsbefreit_sort_Name_100901_14383.pdf' gkv.should_receive(:latest_url).and_return(pdf_url) download = StringIO.new('downloaded from gkv') gkv.should_receive(:download_latest).times(1).and_return do |url, opt, block| assert_equal pdf_url, url block.call download end gkv.should_receive(:import).with(download).times(1).and_return [] @updater.import_gkv end
Result
masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb /home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency Loaded suite test/util/test_updater Started ..... Finished in 0.038158 seconds. 5 tests, 10 assertions, 0 failures, 0 errors
Notes
The Updater.reported_import method is also replaced with flexmock object but there is no test case regarding Updater.reported_import method.
Idea
Sample block
# Refer http://www.ruby-lang.org/ja/man/html/_A5AFA5E9A5B9A1BFA5E1A5BDA5C3A5C9A4CEC4EAB5C1.html (japanese) class TEST def test_block1(arg, &block) print "block.class=", block.class, "\n" block.call(arg) #=> this argument is passed to block argument end def test_block2(arg1, arg2, &block) block.call(arg1, arg2) end def test_block3(*arg, &block) block.call(arg) end def test_block4(arg) yield(arg) end def test_block5(arg) Proc.new.call(arg) #=> warning end def test_block6(arg) proc.call(arg) end def test_block7(*arg) p arg[0] if arg[0] if block_given? #=> built-in functino yield("block called") else p "no block called" end end end if __FILE__ == $0 test=TEST.new test.test_block1("boo1") do |a| p a end test.test_block2("boo2","baa2") do |a,b| p a, b end test.test_block3("boo3","baa3","bee3") do |a| p a end test.test_block4("boo4") do |a| p a end test.test_block5("boo5") do |a| p a end test.test_block6("boo6") do |a| p a end test.test_block7("boo7") do |a| p a end test.test_block7 end
Result
masa@masa ~/work/test_mock $ ruby test.rb block.class=Proc "boo1" "boo2" "baa2" ["boo3", "baa3", "bee3"] "boo4" "boo5" test.rb:22: warning: tried to create Proc object without a block "boo6" "boo7" "block called" "no block called"
Flexmock block test
test.rb
class MOCK # def block(arg, &block) # block.call(arg) # end def block(arg) yield(arg) end end class TEST def test_test(arg) mock = MOCK.new mock.block(arg) do |a| p a end end end
test_test.rb
require 'test/unit' require 'flexmock' require 'test' class TestTest < Test::Unit::TestCase include FlexMock::TestCase def test_test a = "booboo" flexstub(MOCK) do |mockclass| mockclass.should_receive(:new).and_return do flexmock('mock object') do |mockobj| mockobj.should_receive(:block).and_return do |arg, block| #=> this will be arguments of block method assert_equal "booboo", arg #block.call "AAA" end end end end test = TEST.new test.test_test(a) end end
Result
masa@masa ~/work/test_mock $ ruby test_test.rb Loaded suite test_test Started . Finished in 0.000737 seconds. 1 tests, 1 assertions, 0 failures, 0 errors
When I run display (ImageMagik application), the following error came
masa@masa ~/work $ display capture.jpg display: /usr/lib64/libjpeg.so.8: no version information available (required by /usr/lib/libtiff.so.3) display: Wrong JPEG library version: library is 62, caller expects 80 `capture.jpg' @ error/jpeg.c/EmitMessage/235.
This is caused by some settings done a few weeks ago with Davatz-san. I did not memorize the change.
Log
masa@masa /usr/lib64 $ sudo emerge -C imagemagick Passwort: * This action can remove important packages! In order to be safer, use * `emerge -pv --depclean <atom>` to check for reverse dependencies before * removing packages. media-gfx/imagemagick selected: 6.6.2.5 protected: none omitted: none >>> 'Selected' packages are slated for removal. >>> 'Protected' and 'omitted' packages will not be removed. >>> Waiting 5 seconds before starting... >>> (Control-C to abort)... >>> Unmerging in: 5 4 3 2 1 >>> Unmerging media-gfx/imagemagick-6.6.2.5... /sbin/ldconfig: /usr/lib/libjpeg.so.62 ist kein symbolischer Link * GNU info directory index is up-to-date. !!! existing preserved libs: >>> package: media-libs/libpng-1.4.3 * - /usr/lib64/libpng12.so * - /usr/lib64/libpng12.so.0 * - /usr/lib64/libpng12.so.0.43.0 * used by /usr/bin/emacs-23 (app-editors/emacs-23.1-r2) * used by /usr/bin/gegl (media-libs/gegl-0.0.22) * used by /usr/bin/gs (app-text/ghostscript-gpl-8.64-r3) * used by 27 other files Use emerge @preserved-rebuild to rebuild packages using these libraries masa@masa /usr/lib64 $ sudo emerge imagemagick masa@masa ~/work $ display capture.jpg display: Wrong JPEG library version: library is 62, caller expects 80 `capture.jpg' @ error/jpeg.c/EmitMessage/235.
From Davatz-san
The libjpeg error I solved on my local machine by copying libjpeg.so.62 to libjpeg.so.8.0.2 in /usr/lib First I had to compile the correct version of libjpeg though, with emerge =libjpeg-6b-r9
Summary
_Explanation example_
Refer
Experiment
src/custom/lookandfeelbase.rb def result_list_components { # [0,0] => :limitation_text, [1,0] => :minifi, [2,0] => :fachinfo, [3,0] => :patinfo, [4,0,0] => :narcotic, [4,0,1] => :complementary_type, [4,0,2] => :comarketing, [5,0,0] => 'result_item_start', [5,0,1] => :name_base, [5,0,2] => 'result_item_end', [6,0] => :comparable_size, [7,0] => :price_exfactory, [8,0] => :price_public, [9,0] => :deductible, [10,0] => :ddd_price, [11,0] => :compositions, [12,0] => :company_name, [13,0] => :ikscat, [14,0] => :feedback, [15,0] => :twitter_share, [16,0] => :google_search, [17,0] => :notify, } end
Result
BraSt
Hypothesis
grep search
masa@masa ~/ywesee/oddb.org $ grep -r "def limitation_text" src src/model/package.rb: def limitation_text src/model/registration.rb: def limitation_text_count src/model/sequence.rb: def limitation_text src/model/sequence.rb: def limitation_text_count src/util/oddbapp.rb: def limitation_text_count src/view/additional_information.rb: def limitation_text(model, session=@session) src/view/analysis/position.rb: def limitation_text(model) src/view/drugs/csv_result.rb: def limitation_text(pack) src/view/drugs/limitationtext.rb: def limitation_text_title(model, session) src/view/drugs/package.rb: def limitation_text(model, session=@session) src/view/migel/group.rb: def limitation_text(model) src/view/migel/limitationtext.rb: def limitation_text_title(model, session) src/view/migel/product.rb: def limitation_text(model) src/view/migel/result.rb: def limitation_text(model) src/view/migel/subgroup.rb: def limitation_text(model)
Look at them one by one
def limitation_text @sl_entry.limitation_text unless @sl_entry.nil? end
def create_sl_entry @sl_entry = SlEntry.new end
Experiment
def limitation_text #print caller(0).join("\n").to_s, "\n" #p "get-in limitation_text" p @sl_entry.limitation_text unless @sl_entry.nil? @sl_entry.limitation_text unless @sl_entry.nil? end
Result
#<ODBA::Stub:70096340984540#10899115 @odba_class= @odba_container=70096340984700#702814> nil #<ODBA::Stub:70096340730880#23135746 @odba_class=ODDB::LimitationText @odba_container=70096340733060#23135745> #<ODBA::Stub:70096340621900#24323050 @odba_class= @odba_container=70096340623300#24323049> #<ODBA::Stub:70096340515240#10899116 @odba_class= @odba_container=70096340515420#702818> nil
Notes
Look at SlEntry class
module ODDB class SlEntry include Persistence attr_accessor :limitation, :limitation_points attr_accessor :introduction_date, :bsv_dossier, :status, :type, :valid_from, :valid_until attr_reader :limitation_text def create_limitation_text @limitation_text = LimitationText.new end def delete_limitation_text @limitation_text = nil self.odba_isolated_store nil end def pointer_descr :sl_entry end private def adjust_types(values, app=nil) values = values.dup values.each { |key, value| case(key) when :introduction_date values[key] = if (value.is_a? Date) value else Date.parse(value.tr('.', '-')) end when :limitation values[key] = ([true, 'true', 'Y'].include? value) ? true : false when :limitation_points points = value.to_i values[key] = (points > 0) ? points : nil end unless value.nil? } end end end
Notes
What to do next
Experiment
def limitation_text(model, session=@session) p "getin limitation_text" text = HtmlGrid::Div.new(model, @session, self) text.label = true if(lim = model.limitation_text) text.value = lim.send(@session.language) text.css_class = "long-text" end text end
Result
Experiment
def limitation_text p "getin limitation_text" @packages.each_value { |package| if(txt = package.limitation_text) return txt end } nil end
Result
When we search a drug from the top page,
called
I have not checked the followings yet