view · edit · sidebar · attach · print · history

20100914 test-import_gkv

<< Masa.20100915-update-limitation-text | 2010 | Masa.20100913-test-import_gkv >>


  1. Add test_import_gkv
  2. Practice Block
  3. Debug libjpeg error
  4. Ticket 242
  5. Searching the specific part of source code to show "L"

Goal
  • test import_gkv / 100%
  • Ticket 242 / 30%
Milestones
  1. Confirm Error yesterday
  2. BraSt
  3. Commit 8:45
  4. Practice & Summarize flexmock block case 10:15
  5. Debug imagemagick error 12:00
  6. Read Ticket 242 12:25
  7. Dig in code
    1. Review the joblog about search result
    2. p-set search
Summary
Commits
ToDo Tomorrow
  1. 20100907 Ticket 242, Comment 9 - notification Mail
  2. Dimdi-Import-Error.
Keep in Mind
Attached Files

Add 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

Commit

Notes

  • This is a blackbox test. It does not check the detail, in particular, the parts which are depending on Gkv#latest_url method and Gkv#download_latest method.
  • The function of latest_url and download_latest are replaced with flexmock object. Those tests are checked in test cases of Gkv class.
  • The Updater.reported_import method is also replaced with flexmock object but there is no test case regarding Updater.reported_import method.
  • The test cases other than Updater.run should be composed.

How to block call (Practice)

Idea

link

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

# Debug libjpeg error

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.
  1. I get the sourcecode of jpeglib.80 and compile it, then I put it in /usr/lib directory.
  2. reinstall imagemagick
  3. Then, imagemagick, (import, display, animate, etc.) worked.

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

Ticket 242

Summary

  • There is no "L" on the search result of 7680382940243 (Lexotanil 1.5) and 7680382941059(Lexotanil 6)
  • "L" should be also put on the result
  • Some explanation should also be shown after the click of "L"

_Explanation example_

Searching the specific part of source code to show "L"

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

  • The symbol :limitation_text is used for the expression of limitation
  • grep search with :limitation_text

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

src/model/package.rb

 def limitation_text
   @sl_entry.limitation_text unless @sl_entry.nil?
 end
  • @sl_entry.limitation_text is called
  • where is @sl_entry?
    • @sl_entry is created by create_sl_entry method
    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

  • Only the third @odba_class = ODDB::LimitationText, why?

Look at SlEntry class

src/modl/slentry.rb

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

  • limitation_text is saved in SlEntry#@limitation_text but when is it saved?
  • because there is no method for saving it in the SlEntry class
  • it is maybe in Persistence module, maybe.

What to do next

  • trace grep-def-limitation_text results

Experiment

http://scm.ywesee.com/?p=oddb.org/.git;a=blob;f=src/view/drugs/package.rb;h=0750b71d7953ca7d6f5ec45fbe5b41fed492470f;hb=HEAD#l187<src/view/drugs/package.rb

  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

  • nothing happened

Experiment

src/model/sequence.rb

    def limitation_text
p "getin limitation_text"
      @packages.each_value { |package|
        if(txt = package.limitation_text)
          return txt
        end
      }
      nil
    end

Result

  • Nothing happened

Interim Summary

When we search a drug from the top page,

  1. src/model/package.rb: def limitation_text called
  2. src/model/sequence.rb: def limitation_text not called
  3. src/view/drugs/package.rb: def limitation_text(model, session=@session) not called

I have not checked the followings yet

  1. src/view/additional_information.rb: def limitation_text(model, session=@session)
  2. src/view/analysis/position.rb: def limitation_text(model)
  3. src/view/drugs/csv_result.rb: def limitation_text(pack)
  4. src/view/drugs/limitationtext.rb: def limitation_text_title(model, session)
  5. src/view/migel/group.rb: def limitation_text(model)
  6. src/view/migel/limitationtext.rb: def limitation_text_title(model, session)
  7. src/view/migel/product.rb: def limitation_text(model)
  8. src/view/migel/result.rb: def limitation_text(model)
  9. src/view/migel/subgroup.rb: def limitation_text(model)
view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 12:00 PM