view · edit · sidebar · attach · print · history

20101222-update-ch_oddb_org-generics_xls

<< Masa.20101223-testcase-ch_oddb_org-generics_xls | 2010 | Masa.20101221-update-ch_oddb_org-generics_xls >>


  1. Confirm result last night
  2. Confirm error
  3. Make test case Package#comparable?
  4. Check influences of Package#comparable? update
  5. Update test_model/package.rb
  6. Make test-case export_generics

Goal
  • Update export_generics / 90%
  • Test case export_generics / 70%
Milestones
  1. Confirm error locally 9:30
  2. Test cases (there is no test cases for export_generics method)
    • Package#comparable? 11:00
    • export_generics
  3. (find out export_generics dependency on update_bsv)
  4. (independent run export_generics from update_bsv)
Summary
Commits
ToDo Tomorrow
  • Brush up test-cases, there is similar description in each test-case
Keep in Mind
  1. swissmedic_followers debug
  2. rpdf2txt announcement 20101214
  3. different page 2010, 2011 and navigator link at the bottom of page PM-Wiki Markup for paging between pages
  4. On Ice
  5. export_fachinfo test locally (weekend)
  6. backup script (weekend)
  7. emerge --sync

Confirm result last night

I have ran the jobs (update_bsv and export_generics) yesterday

Result

Hypothesis

  • 'update_bsv' must run before export_generics (in update_bsv_followers method)

Confirm error

ToDo

  1. Run export_generics without update_bsv -> I expect error coming
  2. Run update_bsv and then export_generics -> I expect success

export_generics without update_bsv

Run

  1. bin/oddbd
  2. ext/export/bin/exportd
  3. ext/meddata/bin/meddatad
  4. Updater.new(self).export_generics_xls (bin/admin)

Result

Plugin: ODDB::XlsExportPlugin
Error: NoMethodError
Message: undefined method `[]' for nil:NilClass
Backtrace:
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:185:in `_remarks'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:176:in `remarks'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:168:in `format_row'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:71:in `export_comparable'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:78:in `export_comparables'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:76:in `each'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:76:in `export_comparables'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:130:in `export_generics'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:130:in `each'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/generics_xls.rb:130:in `export_generics'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/odba_exporter.rb:98:in `export_generics_xls'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/odba_exporter.rb:255:in `call'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/odba_exporter.rb:255:in `safe_export'
(druby://localhost:10005) /usr/lib64/ruby/1.8/tempfile.rb:172:in `open'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/odba_exporter.rb:254:in `safe_export'
(druby://localhost:10005) /home/masa/ywesee/oddb.org/ext/export/src/odba_exporter.rb:96:in `export_generics_xls'
/home/masa/ywesee/oddb.org/src/plugin/xls_export.rb:23:in `export_generics'
/home/masa/ywesee/oddb.org/src/util/updater.rb:101:in `export_generics_xls'
/home/masa/ywesee/oddb.org/src/util/updater.rb:453:in `call'
/home/masa/ywesee/oddb.org/src/util/updater.rb:453:in `wrap_update'
/home/masa/ywesee/oddb.org/src/util/updater.rb:99:in `export_generics_xls'
(eval):1:in `_admin'
/home/masa/ywesee/oddb.org/src/util/failsafe.rb:9:in `call'
/home/masa/ywesee/oddb.org/src/util/failsafe.rb:9:in `failsafe'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1399:in `_admin'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1397:in `initialize'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1397:in `new'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1397:in `_admin'
/usr/lib64/ruby/1.8/drb/drb.rb:1556:in `__send__'
/usr/lib64/ruby/1.8/drb/drb.rb:1556:in `perform_without_block'
/usr/lib64/ruby/1.8/drb/drb.rb:1516:in `perform'
/usr/lib64/ruby/1.8/drb/drb.rb:1590:in `main_loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1586:in `loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1586:in `main_loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1582:in `start'
/usr/lib64/ruby/1.8/drb/drb.rb:1582:in `main_loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1431:in `run'
/usr/lib64/ruby/1.8/drb/drb.rb:1428:in `start'
/usr/lib64/ruby/1.8/drb/drb.rb:1428:in `run'
/usr/lib64/ruby/1.8/drb/drb.rb:1348:in `initialize'
/usr/lib64/ruby/1.8/drb/drb.rb:1628:in `new'
/usr/lib64/ruby/1.8/drb/drb.rb:1628:in `start_service'
bin/oddbd:38

Note

  • The same error

export_generics after update_bsv

src/util/updater.rb#run

        def run
            logfile_stats
=begin
            if(update_swissmedic)
        update_swissmedic_followers
      end
      update_swissmedicjournal
            update_vaccines
=end
      return_value_update_bsv = update_bsv
      LogFile.append('oddb/debug', " return_value_update_bsv=" + return_value_update_bsv.inspect.to_s, Time.now)

            #if(update_bsv)
            if(return_value_update_bsv)
        update_bsv_followers
            end
=begin
      update_narcotics
      run_on_monthday(1) {
        update_interactions 
      }
=end
        end
...
    def update_bsv_followers

      LogFile.append('oddb/debug', " getin update_bsv_followers", Time.now)
=begin
      update_trade_status
      update_medwin_packages
      update_lppv
      update_price_feeds
      export_oddb_csv
      # export_oddb2_csv # Disabled 4.1.2010
      export_ouwerkerk
=end
      export_generics_xls
#      export_competition_xlss
    end

Run

  1. bin/oddbd
  2. ext/export/bin/exportd
  3. ext/meddata/bin/meddatad
  4. Updater.new(self).export_generics_xls (bin/admin)
  5. jobs/import_daily

Result

Check new files

masa@masa ~/ywesee/oddb.org $ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   src/util/updater.rb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       data/downloads/
#       data/xml/
#       log/

masa@masa ~/ywesee/oddb.org $ ls -al data/downloads/
insgesamt 4396
drwxr-xr-x 2 masa masa      88 22. Dez 08:23 .
drwxr-xr-x 9 masa masa      56 22. Dez 07:55 ..
-rw-r--r-- 1 masa masa 3093504 22. Dez 08:23 generics.xls
-rw-r--r-- 1 masa masa  699700 22. Dez 08:23 generics.xls.gz
-rw-r--r-- 1 masa masa  699805 22. Dez 08:23 generics.xls.zip

masa@masa ~/ywesee/oddb.org $ ls -al data/xml/
insgesamt 6176
drwxr-xr-x 2 masa masa      16 22. Dez 07:55 .
drwxr-xr-x 9 masa masa      56 22. Dez 07:55 ..
-rw-r--r-- 1 masa masa 3160927 22. Dez 07:55 XMLPublications-2010.12.22.zip
-rw-r--r-- 1 masa masa 3160927 22. Dez 07:55 XMLPublications-latest.zip

masa@masa ~/ywesee/oddb.org $ ls -al log/oddb/debug/2010/
insgesamt 8
drwxr-xr-x 2 masa masa   32 22. Dez 08:24 .
drwxr-xr-x 3 masa masa    8 22. Dez 07:55 ..
-rw-r--r-- 1 masa masa 4345 22. Dez 08:23 12.log

Conclusion

  • update_bsv must run before export_generics

Experiment

  • Do not reboot after the run above
    • bin/oddbd, ext/export/bin/exportd, ext/meddata/bin/meddatad
  • Updater.new(self).export_generics_xls (bin/admin)

Result

Experiment

  • Reboot
    • bin/oddbd, ext/export/bin/exportd, ext/meddata/bin/meddatad
  • Updater.new(self).export_generics_xls (bin/admin)

Result

Experiment

  • Delete data/xml
  • Reboot
    • bin/oddbd, ext/export/bin/exportd, ext/meddata/bin/meddatad
  • Updater.new(self).export_generics_xls (bin/admin)

Result

Notes

  • The history (flag) information which indicates 'the system has done update_bsv' must be stored somewhere

Make test case Package#comparable?

Check the current test cases

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/package.rb 
Loaded suite test/test_model/package
Started
.........F.F......................................
Finished in 0.039492 seconds.

  1) Failure:
test_comparables1(ODDB::TestPackage) [test/test_model/package.rb:179]:
<[#<ODDB::Package:0x7f18218038c0
  @feedbacks=[],
  @ikscd="098",
  @narcotics=[],
  @odba_id=11,
  @oid=11,
  @parts=
   [#<ODDB::Part:0x7f1821803898
     @addition=0,
     @comform="Tabletten",
     @comparable_size=Quanty(12.0,''),
     @count=12,
     @measure=Quanty(1,''),
     @multi=Quanty(1,''),
     @odba_id=12,
     @oid=12,
     @revision=Wed Dec 22 09:04:17 +0100 2010,
     @scale=Quanty(1,'')>],
  @revision=Wed Dec 22 09:04:17 +0100 2010>]> expected but was
<[]>.

  2) Failure:
test_comparables3(ODDB::TestPackage) [test/test_model/package.rb:210]:
<[#<ODDB::Package:0x7f1821a16270
  @feedbacks=[],
  @ikscd="098",
  @narcotics=[],
  @odba_id=21,
  @oid=21,
  @parts=
   [#<ODDB::Part:0x7f1821a0f4e8
     @addition=0,
     @comform="Tabletten",
     @comparable_size=Quanty(12.0,''),
     @count=12,
     @measure=Quanty(1,''),
     @multi=Quanty(1,''),
     @odba_id=22,
     @oid=22,
     @revision=Wed Dec 22 09:04:17 +0100 2010,
     @scale=Quanty(1,'')>],
  @revision=Wed Dec 22 09:04:17 +0100 2010>,
 #<ODDB::Package:0x7f1821a4b998
  @feedbacks=[],
  @ikscd="097",
  @narcotics=[],
  @odba_id=19,
  @oid=19,
  @parts=
   [#<ODDB::Part:0x7f1821a4b948
     @addition=0,
     @comform="Tabletten",
     @comparable_size=Quanty(12.0,''),
     @count=12,
     @measure=Quanty(1,''),
     @multi=Quanty(1,''),
     @odba_id=20,
     @oid=20,
     @revision=Wed Dec 22 09:04:17 +0100 2010,
     @scale=Quanty(1,'')>],
  @revision=Wed Dec 22 09:04:17 +0100 2010>]> expected but was
<[]>.

50 tests, 126 assertions, 2 failures, 0 errors

Note

  • There are two failures

Experiment

src/model/package.rb

    def comparable?(bottom, top, pack)
      begin
        pack != self \
          && (other = pack.comparable_size) \
          && bottom < other \
          && top > other
#          && top > other \
#          && !pack.basename.nil?
      rescue RuntimeError => e
        false
      end
    end

Check test

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/package.rb 
Loaded suite test/test_model/package
Started
..................................................
Finished in 0.019958 seconds.

50 tests, 126 assertions, 0 failures, 0 errors

Notes

  • My latest update causes the two failures
  • I am not sure this update influences on the other parts or not
  • But this method should be updated because it is certain that packages are NOT comparable without basename
    • The basename definition may have a problem, though. (if there is a number of the beginning of the name, 'basename' will be 'nil')

Next

  • Check the influences on the other testcases

Check influences of Package#comparable? update

Check test_model/suite.rb (all the test of model)

without update Package#comparables?

src/model/package.rb#comparable?

    def comparable?(bottom, top, pack)
      begin
        pack != self \
          && (other = pack.comparable_size) \
          && bottom < other \
          && top > other 
#          && top > other \
#          && !pack.basename.nil?
      rescue RuntimeError => e
        false
      end
    end

Check testcases

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/suite.rb 
/home/masa/ywesee/oddb.org/src/view/drugs/resultlist.rb:21: warning: already initialized constant BACKGROUND_SUFFIX
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/sourcecode_dumpable.rb:73: warning: redefining constant Struct::MethodNamed
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/sourcecode_dumpable.rb:73: warning: already initialized constant MethodNamed
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/sourcecode_dumpable.rb:74: warning: redefining constant Struct::ModuleMethodNamed
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/sourcecode_dumpable.rb:74: warning: already initialized constant ModuleMethodNamed
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/glr_parser.rb:275: warning: redefining constant Struct::Link
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/glr_parser.rb:275: warning: already initialized constant Link
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/conflict_resolution.rb:18: warning: redefining constant Struct::Relation
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/conflict_resolution.rb:18: warning: already initialized constant Relation
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/grammar.rb:591: warning: already initialized constant EpsilonToken
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/graphviz_dot.rb:52: warning: redefining constant Struct::DotGraph
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/graphviz_dot.rb:52: warning: already initialized constant DotGraph
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/directed_graph.rb:16: warning: redefining constant Struct::GraphLink
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/directed_graph.rb:16: warning: already initialized constant GraphLink
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/reduce_actions_generator.rb:273: warning: redefining constant Struct::LaLrPair
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt-rockit/reduce_actions_generator.rb:273: warning: already initialized constant LaLrPair
[DEPRECATED] By requiring 'spreadsheet/excel' you are loading a Compatibility
             layer which provides a drop-in replacement for Spreadsheet::Excel
             versions <= 0.3.5.1. This code will be removed in Spreadsheet
             version 1.0.0

/home/masa/ywesee/oddb.org/src/view/changelog.rb:26: warning: already initialized constant SORT_DEFAULT
/home/masa/ywesee/oddb.org/test/test_model/text.rb:273: warning: parenthesize argument(s) for future version
/home/masa/ywesee/oddb.org/test/test_model/user.rb:15: warning: already initialized constant YUS_SERVER
Loaded suite test/test_model/suite
Started
..........................................................................................................................................................................................................................................................................................................................................................................................................Substance.merge: no active agent, only removing sequence
............................................................................................................................................................................
Finished in 0.216205 seconds.

566 tests, 1376 assertions, 0 failures, 0 errors

Note

  • wunderbar!! No error and failure!!

Check test/suite.rb (all the tests)

without update Package#comparables?

Check testcases

masa@masa ~/ywesee/oddb.org $ ruby test/suite.rb
...
1005 tests, 2415 assertions, 7 failures, 36 errors

Note

  • Too many...
  • But this numbers (failures and errors) should be memorized

Check test_model/suite.rb (all the test of model)

with update Package#comparables? src/model/package.rb#comparable?

    def comparable?(bottom, top, pack)
      begin
        pack != self \
          && (other = pack.comparable_size) \
          && bottom < other \
          && top > other \
          && !pack.basename.nil?
#          && top > other 
      rescue RuntimeError => e
        false
      end
    end

Check testcases

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/suite.rb
...
  1) Failure:
test_comparables1(ODDB::TestPackage) [/home/masa/ywesee/oddb.org/test/test_model/package.rb:179]:
<[#<ODDB::Package:0x7fbe31626000
  @feedbacks=[],
  @ikscd="098",
  @narcotics=[],
  @odba_id=62,
  @oid=62,
  @parts=
   [#<ODDB::Part:0x7fbe31625fd8
     @addition=0,
     @comform="Tabletten",
     @comparable_size=Quanty(12.0,''),
     @count=12,
     @measure=Quanty(1,''),
     @multi=Quanty(1,''),
     @odba_id=63,
     @oid=63,
     @revision=Wed Dec 22 09:23:05 +0100 2010,
     @scale=Quanty(1,'')>],
  @revision=Wed Dec 22 09:23:05 +0100 2010>]> expected but was
<[]>.

  2) Failure:
test_comparables3(ODDB::TestPackage) [/home/masa/ywesee/oddb.org/test/test_model/package.rb:210]:
<[#<ODDB::Package:0x7fbe316012c8
  @feedbacks=[],
  @ikscd="098",
  @narcotics=[],
  @odba_id=72,
  @oid=72,
  @parts=
   [#<ODDB::Part:0x7fbe31600b20
     @addition=0,
     @comform="Tabletten",
     @comparable_size=Quanty(12.0,''),
     @count=12,
     @measure=Quanty(1,''),
     @multi=Quanty(1,''),
     @odba_id=73,
     @oid=73,
     @revision=Wed Dec 22 09:23:05 +0100 2010,
     @scale=Quanty(1,'')>],
  @revision=Wed Dec 22 09:23:05 +0100 2010>,
 #<ODDB::Package:0x7fbe31604248
  @feedbacks=[],
  @ikscd="097",
  @narcotics=[],
  @odba_id=70,
  @oid=70,
  @parts=
   [#<ODDB::Part:0x7fbe31604220
     @addition=0,
     @comform="Tabletten",
     @comparable_size=Quanty(12.0,''),
     @count=12,
     @measure=Quanty(1,''),
     @multi=Quanty(1,''),
     @odba_id=71,
     @oid=71,
     @revision=Wed Dec 22 09:23:05 +0100 2010,
     @scale=Quanty(1,'')>],
  @revision=Wed Dec 22 09:23:05 +0100 2010>]> expected but was
<[]>.

566 tests, 1376 assertions, 2 failures, 0 errors

Note

  • The two faillures come from test_model/package.rb
  • There looks no influence on the other test cases

Check test/suite.rb (all the tests)

with update Package#comparables?

masa@masa ~/ywesee/oddb.org $ ruby test/suite.rb
...
1005 tests, 2415 assertions, 9 failures, 36 errors

Note

  • Two failures increases, but these two come from package.rb
  • There looks no influence on the other test cases other than test_model/package.rb

Update test_model/package.rb

Anyway,

  • I should update test_model/package.rb since the influence looks small

Memo

  • There is no 'test_comparable?'

test/test_model/package.rb

    def test_comparable?
      part1 = flexmock :comparable_size => Dose.new(5, 'ml')
      part2 = flexmock :comparable_size => Dose.new(10, 'ml')
      @package.parts.push part1, part2

      pack = ODDB::Package.new('98')
      seq = StubPackageSequence.new
      seq.basename = "masa"
      pack.parts.push part1, part2
      pack.sequence = seq

      top = @package.comparable_size * 1.25
      bottom = @package.comparable_size * 0.75
      assert(@package.comparable?(bottom, top, pack))
    end
    def test_comparable_failcase
      part1 = flexmock :comparable_size => Dose.new(5, 'ml')
      part2 = flexmock :comparable_size => Dose.new(10, 'ml')
      @package.parts.push part1, part2

      pack = ODDB::Package.new('98')
      pack.parts.push part1, part2
      # pack.basename == nil

      top = @package.comparable_size * 1.25
      bottom = @package.comparable_size * 0.75
      assert_equal(false, @package.comparable?(bottom, top, pack))
    end

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/package.rb 
Loaded suite test/test_model/package
Started
..
Finished in 0.002655 seconds.

2 tests, 2 assertions, 0 failures, 0 errors

Note

  • The other test cases are commented out temporarily
    def test_comparables1
      seq = StubPackageSequence.new
seq.basename = "abc"
      pack = ODDB::Package.new('98')
pack.sequence = seq
      part = ODDB::Part.new
      part.size = '12 Tabletten'
      pack.parts.push part
      seq.active_packages = [pack]
      @package.sequence.comparables = [seq]
      part = ODDB::Part.new
      part.size = '15 Tabletten'

      @package.parts.push part
      assert_equal([pack], @package.comparables)
    end

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/package.rb 
Loaded suite test/test_model/package
Started
...
Finished in 0.004064 seconds.

3 tests, 3 assertions, 0 failures, 0 errors
    def test_comparables3
      seq = StubPackageSequence.new
seq.basename = "abc"
      seqpack = ODDB::Package.new('97')
seqpack.sequence = seq
      part = ODDB::Part.new
      part.size = '12 Tabletten'
      seqpack.parts.push part
      pack = ODDB::Package.new('98')
pack.sequence = seq
      part = ODDB::Part.new
      part.size = '12 Tabletten'
      pack.parts.push part
      seq.active_packages = [pack]
      @package.sequence.comparables = [seq]
      @package.sequence.active_packages = [seqpack, @package]
      part = ODDB::Part.new
      part.size = '15 Tabletten'
      @package.parts.push part
      assert_equal([pack, seqpack], @package.comparables)
    end

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/package.rb 
Loaded suite test/test_model/package
Started
....
Finished in 0.006047 seconds.

4 tests, 4 assertions, 0 failures, 0 errors

Check all the test cases

masa@masa ~/ywesee/oddb.org $ ruby test/test_model/suite.rb
...
568 tests, 1378 assertions, 0 failures, 0 errors

Note

  • Good

Commit

Make test-case export_generics

Check the current test-case

masa@masa ~/ywesee/oddb.org/ext/export $ ls -al test
insgesamt 4
drwxr-xr-x 2 masa masa    8 22. Dez 07:28 .
drwxr-xr-x 5 masa masa   24 22. Dez 07:28 ..
-rw-r--r-- 1 masa masa 3293 22. Dez 07:28 test_csv_exporter.rb

Note

  • There is no test-case for generics_xls.rb

Strategy

  • Check all the methods of generics_xls.rb one by one
  • Refer to test_csv_exporter.rb

Check test_csv_exporter.rb

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_csv_exporter.rb 
Loaded suite test/test_csv_exporter
Started
FF"8600;00;9300.00;Test de;Teste fr;Fussnote;FRussnote;Taxen;Taxes;Limit;LimitFR;Titel;Titre;C,I;30;n;{teiliste}:{spital},{list1}:{blabla};{list1}:{blabla}\n"
.
Finished in 0.001627 seconds.

  1) Failure:
test_dump_1(ODDB::OdbaExporter::TestCsvExporter) [test/test_csv_exporter.rb:72]:
<"7601000616715;1998;Herrn;Dr. med;Fabrice;Dami;false;at_work;;;Foobodenstrasse 1;1234;Neuch\342tel;NE;fon1,fon2;;amig@amig.ch;franz\366sisch;Kardiologie,Psychokardiologie\n"> expected but was
<"7601000616715;1998;Herrn;Dr. med;Fabrice;Dami;false;at_work;\"\";\"\";Foobodenstrasse 1;1234;Neuch\342tel;NE;fon1,fon2;\"\";amig@amig.ch;franz\366sisch;Kardiologie,Psychokardiologie\n">.

  2) Failure:
test_dump_2(ODDB::OdbaExporter::TestCsvExporter) [test/test_csv_exporter.rb:82]:
<"7601000616715;1998;Herrn;Dr. med;Fabrice;Dami;true;at_praxis;;;Foobodenstrasse 1;1234;Neuch\342tel;NE;fon1,fon2;;amig@amig.ch;franz\366sisch;Kardiologie,Psychokardiologie\n"> expected but was
<"7601000616715;1998;Herrn;Dr. med;Fabrice;Dami;true;at_praxis;\"\";\"\";Foobodenstrasse 1;1234;Neuch\342tel;NE;fon1,fon2;\"\";amig@amig.ch;franz\366sisch;Kardiologie,Psychokardiologie\n">.

3 tests, 3 assertions, 2 failures, 0 errors

Note

  • Two test-cases fail

Read the flows of generics_xls.rb

The following methods are only in generics_xls.rb

  1. initialize
  2. export_generics
    1. export_comparables
      1. export_comparable
        1. format_row
          1. format_original
            1. preprocess_fields
            2. format_price
          2. format_generic
            1. preprocess_fields
            2. format_price
          3. remarks
          4. _remarks
    2. export_generic
      1. _remarks
  3. close

Notes

  • initialize (new), export_generics, and close methods are called from OdbaExporter.export_generics_xls method
  • 'export_generics' is divided mainly into two parts
    • export_comparables ('originals' is exported) 6686 records
    • export_generic ('(generics- comparables)' is exported) 7804 - 6686 = 1118 records
  • 'format_' and 'remarks' methods are related to the xls output format
  • If there is some 'flag', some specific word is exported in the last column of record (see 'remarks' method)
  • The 'flag' is stored in @smj_flags and @bsv_flags in initialize method
  • @smj_flags and @bsv_flags come from @app.log_group(:swissmedic_journal) and @app.log_group(:bsv_sl)
    • I have to understand @app.log_group

Make test-cases one by one

Template

ext/export/test/test_generics_xls.rb

#!/usr/bin/env ruby
# Odba::Exporter::TestGenericsXls -- oddb -- 22.12.2010 -- mhatakeyama@ywesee.com

#$: << File.expand_path('../src', File.dirname(__FILE__))

require 'test/unit'
require 'flexmock'

module ODDB
  module OdbaExporter
    class TestGenericsXls < Test::Unit::TestCase
      include FlexMock::TestCase
      def setup
      end
      def test_export_comparable
      end
      def test_export_comparables
      end
      def test_export_generic
      end
      def test_export_generics
      end
      def test_format_original
      end
      def test_format_generic
      end
      def test_format_price
      end
      def test_format_row
      end
      def test_preprocess_fields
      end
      def test_remarks
      end
      def test__remarks
      end
    end
  end
end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
...........
Finished in 0.00039 seconds.

11 tests, 0 assertions, 0 failures, 0 errors

setup

ext/export/test/test_generics_xls.rb

#!/usr/bin/env ruby
# Odba::Exporter::TestGenericsXls -- oddb -- 22.12.2010 -- mhatakeyama@ywesee.com

$: << File.expand_path('../src', File.dirname(__FILE__))
$: << File.expand_path('../../../src', File.dirname(__FILE__))
$: << File.expand_path('../../..', File.dirname(__FILE__))

require 'test/unit'
require 'flexmock'
require 'spreadsheet'
require 'generics_xls'

module ODDB
  module OdbaExporter
    class TestGenericsXls < Test::Unit::TestCase
      include FlexMock::TestCase
      def setup
        flexstub(ODBA.cache) do |cacheobj|
           cacheobj.should_receive(:fetch_named).and_return do 
             flexmock do |appobj|
               appobj.should_receive(:log_group).and_return do 
                 flexmock do |obj|
                   obj.should_receive(:latest).and_return do 
                     flexmock do |obj2|
                       obj2.should_receive(:change_flags).and_return({})
                     end
                   end
                 end
               end
             end
           end
        end

        @generics_xls = GenericXls.new(".")
      end
...

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb
Started
.
Finished in 0.001849 seconds.

1 tests, 0 assertions, 0 failures, 0 errors

Note

  • Test passes but the code looks not good

Improved setup

ext/export/test/test_generics_xls.rb

$: << File.expand_path('../src', File.dirname(__FILE__))
$: << File.expand_path('../../../src', File.dirname(__FILE__))
$: << File.expand_path('../../..', File.dirname(__FILE__))

require 'test/unit'
require 'flexmock'
require 'spreadsheet'
require 'generics_xls'
require 'date'

module ODDB
  module OdbaExporter
    class TestGenericXls < Test::Unit::TestCase
      include FlexMock::TestCase
      def setup

        loggroup_swiss = LogGroup.new(:swissmedic_journal)
        loggroup_swiss.create_log(Date.today)
        loggroup_swiss.latest.change_flags = {}
        loggroup_bsv = LogGroup.new(:bsv_sl)
        loggroup_bsv.create_log(Date.today)
        loggroup_bsv.latest.change_flags = {}

        flexstub(ODBA.cache) do |cacheobj|
           cacheobj.should_receive(:fetch_named).and_return do
             flexmock do |appobj|
               appobj.should_receive(:log_group).with(:swissmedic_journal).and_return(loggroup_swiss)
               appobj.should_receive(:log_group).with(:bsv_sl).and_return(loggroup_bsv)
             end
           end
        end

        @generics_xls = GenericXls.new(".")
      end
...

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
.
Finished in 0.001876 seconds.

1 tests, 0 assertions, 0 failures, 0 errors

test__remarks

ext/export/test/test_generics_xls.rb

      def setup
        loggroup_swiss = LogGroup.new(:swissmedic_journal)
        loggroup_swiss.create_log(Date.today)
        loggroup_swiss.latest.change_flags = {123 => [:new]}
        loggroup_bsv = LogGroup.new(:bsv_sl)
        loggroup_bsv.create_log(Date.today)
        loggroup_bsv.latest.change_flags = {123 => [:price_cut]}

        flexstub(ODBA.cache) do |cacheobj|
           cacheobj.should_receive(:fetch_named).and_return do
             flexmock do |appobj|
               appobj.should_receive(:log_group).with(:swissmedic_journal).and_return(loggroup_swiss)
               appobj.should_receive(:log_group).with(:bsv_sl).and_return(loggroup_bsv)
             end
           end
        end

        @generics_xls = GenericXls.new(".")
      end
      def test__remarks1
        pac = flexmock(Package) do |pacobj|
          pacobj.should_receive(:"registration.pointer").and_return(999)
          pacobj.should_receive(:pointer).and_return(999)
        end
        assert_nil(@generics_xls._remarks(pac, 'Generikum'))
      end
      def test__remarks2
         pac = flexmock(Package) do |pacobj|
          pacobj.should_receive(:"registration.pointer").and_return(123)
          pacobj.should_receive(:pointer).and_return(123)
        end
        assert_equal("Generikum: neue Registration, Preissenkung", @generics_xls._remarks(pac, 'Generikum'))
      end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
..
Finished in 0.004724 seconds.

2 tests, 2 assertions, 0 failures, 0 errors

Note

  • Good

test_remarks

      def test_remarks
        pac = flexstub(Package) do |pacobj|
          pacobj.should_receive(:"registration.pointer").and_return(123)
          pacobj.should_receive(:pointer).and_return(123)
        end
        assert_equal("Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung", @generics_xls.remarks(pac, pac))
      end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb
Loaded suite test/test_generics_xls
Started
...
Finished in 0.007019 seconds.

3 tests, 3 assertions, 0 failures, 0 errors

test_format_price

ext/export/src/generics_xls.rb#format_price

            def format_price(price)
                if(price && price > 0.0)
                    sprintf("%4.2f", price.to_f)
                end
            end

Note

  • What is 'price && price'?
  • This is meaningless
  • But it is no problem to run, so I keep it
      def test_format_price
        price = nil
        assert_nil(@generics_xls.format_price(price))
        price = 12.349
        assert_equal("12.35", @generics_xls.format_price(price))
      end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb
Loaded suite test/test_generics_xls
Started
....
Finished in 0.008478 seconds.

4 tests, 5 assertions, 0 failures, 0 errors

preprocess_fields

      def test_preprocess_fields
        fields = [1,2,3,Date.new(2010, 12, 31)]
        assert_equal(["1","2","3","31.12.2010"], @generics_xls.preprocess_fields(fields))
      end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
.....
Finished in 0.010271 seconds.

5 tests, 6 assertions, 0 failures, 0 errors

format_original

      def test_format_original
        pac = flexstub(Package) do |pacobj|
          pacobj.should_receive(:basename).and_return("basename")
          pacobj.should_receive(:dose).and_return("dose")
          pacobj.should_receive(:comparable_size).and_return(111)
          pacobj.should_receive(:barcode).and_return(222)
          pacobj.should_receive(:pharmacode).and_return(333)
          pacobj.should_receive(:name).and_return("name")
          pacobj.should_receive(:price_exfactory).and_return(444.444)
          pacobj.should_receive(:price_public).and_return(555.555)
          pacobj.should_receive(:company_name).and_return("company_name")
          pacobj.should_receive(:ikscat).and_return(666)
          pacobj.should_receive(:sl_entry).and_return(777)
          pacobj.should_receive(:registration_date).and_return(Date.new(2010,12,31))
        end
        expect = ["basename", "basename dose/111", "222", "333", "name", "dose", "111",
                  "444.44", "555.55", "company_name", "666", "SL", "31.12.2010"]
        assert_equal(expect,  @generics_xls.format_original(pac))
      end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
......
Finished in 0.013855 seconds.

6 tests, 7 assertions, 0 failures, 0 errors

test_format_generic

      def test_format_generic
        pac = flexstub(Package) do |pacobj|
          pacobj.should_receive(:basename).and_return("basename")
          pacobj.should_receive(:dose).and_return("dose")
          pacobj.should_receive(:comparable_size).and_return(111)
          pacobj.should_receive(:barcode).and_return(222)
          pacobj.should_receive(:pharmacode).and_return(333)
          pacobj.should_receive(:name).and_return("name")
          pacobj.should_receive(:price_exfactory).and_return(444.444)
          pacobj.should_receive(:price_public).and_return(555.555)
          pacobj.should_receive(:company_name).and_return("company_name")
          pacobj.should_receive(:ikscat).and_return(666)
          pacobj.should_receive(:sl_entry).and_return(nil)
          pacobj.should_receive(:registration_date).and_return(Date.new(2010,12,31))
        end
        expect = ["222", "333", "name", "dose", "111", "444.44", "555.55", "company_name",
                  "666", "", "31.12.2010"]
        assert_equal(expect,  @generics_xls.format_generic(pac))

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
.......
Finished in 0.017462 seconds.

7 tests, 8 assertions, 0 failures, 0 errors

test_format_row

      def test_format_row
        pac = flexstub(Package) do |pacobj|
          pacobj.should_receive(:basename).and_return("basename")
          pacobj.should_receive(:dose).and_return("dose")
          pacobj.should_receive(:comparable_size).and_return(111)
          pacobj.should_receive(:barcode).and_return(222)
          pacobj.should_receive(:pharmacode).and_return(333)
          pacobj.should_receive(:name).and_return("name")
          pacobj.should_receive(:price_exfactory).and_return(444.444)
          pacobj.should_receive(:price_public).and_return(555.555)
          pacobj.should_receive(:company_name).and_return("company_name")
          pacobj.should_receive(:ikscat).and_return(666)
          pacobj.should_receive(:sl_entry).and_return('SL')
          pacobj.should_receive(:registration_date).and_return(Date.new(2010,12,31))
          pacobj.should_receive(:"registration.pointer").and_return(123)
          pacobj.should_receive(:pointer).and_return(123)
        end
        expect = ["basename", "basename dose/111", "222", "333", "name", "dose", "111",
                  "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "222",
                  "333", "name", "dose", "111", "444.44", "555.55", "company_name",
                  "666", "SL", "31.12.2010",
                  "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
        assert_equal(expect,  @generics_xls.format_row(pac, pac))
      end

Result

masa@masa ~/ywesee/oddb.org/ext/export $ ruby test/test_generics_xls.rb 
Loaded suite test/test_generics_xls
Started
........
Finished in 0.021883 seconds.

8 tests, 9 assertions, 0 failures, 0 errors

test_export_generic

view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 12:04 PM