Skip to content

Commit

Permalink
Fix unit tests to make them touch only files under data4tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Feb 26, 2024
1 parent 9ef22bd commit 85b4b92
Show file tree
Hide file tree
Showing 53 changed files with 283 additions and 285 deletions.
19 changes: 11 additions & 8 deletions ext/fiparse/test/test_fachinfo_hpricot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'plugin/text_info'
require 'stub/cgi'
require 'flexmock/minitest'
require 'util/workdir'

module ODDB
class FachinfoDocument
Expand All @@ -27,6 +28,8 @@ def odba_id
end
end
module FiParse
HTML_DIR = File.join(ODDB::PROJECT_ROOT, 'ext/fiparse/test/data/html')

HTML_PREFIX = '<HTML><meta charset="utf-8"/><BODY>'
HTML_POSTFIX = '</HTML></BODY>'
if true
Expand Down Expand Up @@ -361,7 +364,7 @@ class TestFachinfoHpricotAlcaCDe <Minitest::Test
MedicalName = 'Alca-C®'
def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/alcac.fi.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/alcac.fi.html')
@@writer = FachinfoHpricot.new
open(@@path) { |fh|
@@fachinfo = @@writer.extract(Hpricot(fh), :fi, MedicalName)
Expand Down Expand Up @@ -471,7 +474,7 @@ class TestFachinfoHpricot_32917_Zyloric_De <Minitest::Test

def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/fi_32917_zyloric.de.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/fi_32917_zyloric.de.html')
@@writer = FachinfoHpricot.new
open(@@path) { |fh|

Expand Down Expand Up @@ -509,7 +512,7 @@ class TestFachinfoHpricotZyloricFr <Minitest::Test
MedicalName = Zyloric_Reg
def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/fr/fi_Zyloric.fr.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'fr/fi_Zyloric.fr.html')
@@writer = FachinfoHpricot.new
open(@@path) { |fh|

Expand Down Expand Up @@ -562,7 +565,7 @@ class TestFachinfoHpricot_58106_Finasterid_De <Minitest::Test

def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/fi_58106_finasterid.de.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/fi_58106_finasterid.de.html')
@@writer = FachinfoHpricot.new

open(@@path) { |fh|
Expand Down Expand Up @@ -614,7 +617,7 @@ class TestFachinfoHpricot_62439_Xalos_Duo_De <Minitest::Test
MedicInfoName = 'Xalos®-Duo'
def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/fi_62439_xalos_duo.de.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/fi_62439_xalos_duo.de.html')
@@writer = FachinfoHpricot.new
open(@@path) { |fh|
@@fachinfo = @@writer.extract(Hpricot(fh), :fi, MedicInfoName, StylesXalos)
Expand Down Expand Up @@ -664,7 +667,7 @@ class TestFachinfoHpricot_62111_Bisoprolol_De <Minitest::Test
MedicInfoName = 'Bisoprolol Axapharm'
def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/fi_62111_bisoprolol.de.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/fi_62111_bisoprolol.de.html')
@@writer = FachinfoHpricot.new
open(@@path) { |fh|

Expand Down Expand Up @@ -717,7 +720,7 @@ class TestFachinfo_62580_Novartis_Seebri<Minitest::Test
MedicInfoName = ' Seebri Breezhaler'
def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/fi_62580_novartis_seebris.de.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/fi_62580_novartis_seebris.de.html')
@@writer = FachinfoHpricot.new
open(@@path) { |fh|
@@fachinfo = @@writer.extract(Hpricot(fh), :fi, MedicInfoName)
Expand Down Expand Up @@ -806,7 +809,7 @@ class TestFachinfoHpricot_62184_Cipralex_De <Minitest::Test

def setup
return if defined?(@@path) and defined?(@@fachinfo) and @@fachinfo
@@path = File.expand_path('data/html/de/fi_62184_cipralex_de.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/fi_62184_cipralex_de.html')
@@writer = FachinfoHpricot.new

open(@@path) { |fh|
Expand Down
18 changes: 8 additions & 10 deletions ext/fiparse/test/test_patinfo_hpricot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
require 'flexmock/minitest'
require 'patinfo_hpricot'
require 'plugin/text_info'
require 'util/workdir'
$: << File.expand_path('../../../test', File.dirname(__FILE__))
require 'stub/cgi'

module ODDB
module FiParse
HTML_DIR = File.join(ODDB::PROJECT_ROOT, 'ext/fiparse/test/data/html')
class TestPatinfoHpricotCimifeminDe <Minitest::Test
def setup
return if defined?(@@path) and defined?(@@patinfo) and @@patinfo

@@path = File.expand_path('data/html/de/cimifemin.html',
File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/cimifemin.html')
@@writer = PatinfoHpricot.new
open(@@path) { |fh|
@@patinfo = @@writer.extract(Hpricot(fh))
Expand Down Expand Up @@ -271,8 +272,7 @@ class TestPatinfoHpricotCimifeminFr <Minitest::Test
def setup
return if defined?(@@path) and defined?(@@patinfo) and @@patinfo

@@path = File.expand_path('data/html/fr/cimifemin.html',
File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'fr/cimifemin.html')
@@writer = PatinfoHpricot.new
open(@@path) { |fh|
@@writer.extract(Hpricot(fh))
Expand Down Expand Up @@ -314,8 +314,7 @@ class TestPatinfoHpricotInderalDe <Minitest::Test
def setup
return if defined?(@@path) and defined?(@@patinfo) and @@patinfo

@@path = File.expand_path('data/html/de/inderal.html',
File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/inderal.html')
@@writer = PatinfoHpricot.new
open(@@path) { |fh|
@@patinfo = @@writer.extract(Hpricot(fh))
Expand Down Expand Up @@ -357,8 +356,7 @@ def test_pregnancy3
end
class TestPatinfoHpricotPonstanDe <Minitest::Test
def setup
@@path = File.expand_path('data/html/de/ponstan.html',
File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/ponstan.html')
@@writer = PatinfoHpricot.new
open(@@path) { |fh|
@@patinfo = @@writer.extract(Hpricot(fh))
Expand Down Expand Up @@ -400,7 +398,7 @@ class TestPatinfoHpricotNasivinDe <Minitest::Test
def setup
return if defined?(@@path) and defined?(@@patinfo) and @@patinfo

@@path = File.expand_path('data/html/de/nasivin.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/nasivin.html')
@@writer = PatinfoHpricot.new
open(@@path) { |fh|
@@patinfo = @@writer.extract(Hpricot(fh), :pi, 'Nasivin', StylesNasivin)
Expand Down Expand Up @@ -613,7 +611,7 @@ class TestPatinfoHpricot_30785_PonstanDe <Minitest::Test
def setup
return if defined?(@@path) and defined?(@@patinfo) and @@patinfo

@@path = File.expand_path('data/html/de/pi_30785_ponstan.html', File.dirname(__FILE__))
@@path = File.join(HTML_DIR, 'de/pi_30785_ponstan.html')
@@writer = PatinfoHpricot.new
open(@@path) { |fh|
@@patinfo = @@writer.extract(Hpricot(fh), :pi, 'Ponstan', StylesPonstan)
Expand Down
8 changes: 5 additions & 3 deletions ext/fiparse/test/test_pseudo_fachinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
require 'plugin/text_info'
require 'stub/cgi'
require 'flexmock/minitest'
require 'util/workdir'

module ODDB
module FiParse
DOCX_DIR = File.join(ODDB::PROJECT_ROOT, 'ext/fiparse/test/data/docx')
class TestPseudoFachinfoDocument <Minitest::Test
def test_fachinfo_simple
@@path = File.expand_path('data/docx/simple.docx', File.dirname(__FILE__))
@@path = File.join(DOCX_DIR, 'simple.docx')
@@writer = TextinfoPseudoFachinfo.new
open(@@path) { |fh| @@fachinfo = @@writer.extract(fh)}
assert_instance_of(PseudoFachinfoDocument, @@fachinfo)
Expand All @@ -40,7 +42,7 @@ def test_fachinfo_simple
assert_equal(2, yaml.scan(/\ssubheading:/).size, 'Must find exactly 2 subheading')
end
def test_fachinfo_sinovial_FR
@@path = File.expand_path('data/docx/Sinovial_FR.docx', File.dirname(__FILE__))
@@path = File.join(DOCX_DIR, 'Sinovial_FR.docx')
@@writer = TextinfoPseudoFachinfo.new
open(@@path) { |fh| @@fachinfo = @@writer.extract(fh)}
assert_instance_of(PseudoFachinfoDocument, @@fachinfo)
Expand All @@ -59,7 +61,7 @@ def test_fachinfo_sinovial_FR
assert_equal('7612291078458, seringue prête 2 ml', @@fachinfo.packages.paragraphs.first.to_s)
end
def test_fachinfo_sinovial_DE
@@path = File.expand_path('data/docx/Sinovial_DE.docx', File.dirname(__FILE__))
@@path = File.join(DOCX_DIR, 'Sinovial_DE.docx')
@@writer = TextinfoPseudoFachinfo.new
open(@@path) { |fh| @@fachinfo = @@writer.extract(fh)}
assert_instance_of(PseudoFachinfoDocument, @@fachinfo)
Expand Down
6 changes: 4 additions & 2 deletions ext/suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"#{current_dir}/export/test/test_generics_xls.rb",
"#{current_dir}/swissreg/test/test_swissreg.rb",
"#{current_dir}/fiparse/test/test_patinfo_hpricot.rb",
# fails "#{current_dir}/fiparse/test/test_pseudo_fachinfo.rb",
# fails "#{current_dir}/fiparse/test/test_hpricot.rb",
"#{current_dir}/fiparse/test/test_fachinfo_writer.rb",
"#{current_dir}/fiparse/test/test_fiwriter.rb",
"#{current_dir}/meddata/test/test_session.rb",
"#{current_dir}/meddata/test/test_result.rb",
"#{current_dir}/meddata/test/test_meddata.rb",
"#{current_dir}/meddata/test/test_ean_factory.rb",
"#{current_dir}/meddata/test/test_meddparser.rb",
"#{current_dir}/fiparse/test/test_fachinfo_writer.rb",
"#{current_dir}/fiparse/test/test_fiwriter.rb",
"#{current_dir}/export/test/test_csv_exporter.rb",
"#{current_dir}/readonly/test/test_readonly_server.rb",
"#{current_dir}/swissindex/test/test_swissindex.rb",
Expand Down
9 changes: 5 additions & 4 deletions src/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# @config -- oddb.org -- 08.09.2006 -- [email protected]

require 'rclconf'
require 'util/workdir'

module ODDB
SERVER_URI ||="druby://127.0.0.1:10000"
Expand All @@ -22,17 +23,17 @@ module ODDB
MIGEL_URI ||='druby://127.0.0.1:33000'
YUS_DOMAIN ||='oddb.org'

oddb_dir = File.expand_path('..', File.dirname(__FILE__))
oddb_dir = ODDB::PROJECT_ROOT
default_dir = File.expand_path('etc', oddb_dir)
default_config_files = [
File.join(default_dir, 'oddb.yml'),
'/etc/oddb/oddb.yml',
]
defaults = {
'config' => default_config_files,
'data_dir' => File.expand_path('../data', File.dirname(__FILE__)),
'log_dir' => File.expand_path('../log', File.dirname(__FILE__)),
'log_pattern' => File.join(Dir.pwd, defined?(MiniTest) ? 'test/log' : 'log','/%Y/%m/%d/app_log'),
'data_dir' => ODDB::WORK_DIR,
'log_dir' => ODDB::LOG_DIR,
'log_pattern' => File.join(ODDB::LOG_DIR, '/%Y/%m/%d/app_log'),
'url_bag_sl_zip' => 'http://www.xn--spezialittenliste-yqb.ch/File.axd?file=XMLPublications.zip',
'bsv_archives' => '(?:PR|BSV_per_20)(0[3-8])[\d.]+(?:txt|xls)',
'server_url' => SERVER_URI,
Expand Down
12 changes: 6 additions & 6 deletions src/plugin/csv_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
require 'oddb2tdat'
require 'model/package'
require 'model/atcclass'
require 'util/workdir'

module ODDB
class CsvExportPlugin < Plugin
EXPORT_SERVER = DRbObject.new(nil, EXPORT_URI)
EXPORT_DIR = File.join(ARCHIVE_PATH, 'downloads')
MIGEL_EXPORT_DIR = File.expand_path('../../../migel/data/csv', File.dirname(__FILE__))
MIGEL_EXPORT_DIR = File.join(ODDB::PROJECT_ROOT, 'migel/data/csv')
ODDB_RECIPIENTS = ['oddb']
ODDB_RECIPIENTS_DAT = ['oddb_dat']
ODDB_RECIPIENTS_EXTENDED = ['oddb_dat_extended']
Expand Down Expand Up @@ -58,7 +58,7 @@ def _export_drugs(export_name, keys)
@counts = exporter.counts
EXPORT_SERVER.compress(EXPORT_DIR, name)
backup = @app.log_group(:bsv_sl).newest_date.strftime("#{export_name}.%Y-%m-%d.csv")
backup_dir = File.expand_path('../../data/csv', File.dirname(__FILE__))
backup_dir = File.join(ODDB::WORK_DIR, 'csv')
backup_path = File.join(backup_dir, backup)
unless(File.exist? backup_path)
FileUtils.mkdir_p(backup_dir)
Expand Down Expand Up @@ -131,7 +131,7 @@ def export_fachinfo_chapter(term, chapters, lang, file)
'Chapters' => chapters.join(','),
}
EXPORT_SERVER.compress(EXPORT_DIR, file)
backup_dir = File.expand_path('../../data/csv', File.dirname(__FILE__))
backup_dir = File.join(ODDB::WORK_DIR, 'csv')
backup_path = File.join(backup_dir, file)
unless(File.exist? backup_path)
FileUtils.mkdir_p(backup_dir)
Expand Down Expand Up @@ -265,7 +265,7 @@ def export_teilbarkeit
@counts = exporter.divisions
EXPORT_SERVER.compress(EXPORT_DIR, name)
backup = Date.today.strftime("#{export_name}.%Y-%m-%d.csv")
backup_dir = File.expand_path('../../data/csv', File.dirname(__FILE__))
backup_dir = File.join(ODDB::WORK_DIR, 'csv')
backup_path = File.join(backup_dir, backup)
unless(File.exist? backup_path)
FileUtils.mkdir_p(backup_dir)
Expand Down Expand Up @@ -295,7 +295,7 @@ def export_flickr_photo
@counts = exporter.flickr_photos
EXPORT_SERVER.compress(EXPORT_DIR, name)
backup = Date.today.strftime("#{export_name}.%Y-%m-%d.csv")
backup_dir = File.expand_path('../../data/csv', File.dirname(__FILE__))
backup_dir = File.join(ODDB::WORK_DIR, 'csv')
backup_path = File.join(backup_dir, backup)
unless(File.exist? backup_path)
FileUtils.mkdir_p(backup_dir)
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/mail_order_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

module ODDB
class MailOrderPricePlugin < Plugin
CSV_DIR = File.expand_path('../../data/csv', File.dirname(__FILE__))
CSV_DIR = File.join(WORK_DIR, 'csv')
def report
lines = [
"Updated Packages: #{@updated_packages.length}",
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def method_missing(*args)
SWISSMEDIC_HUMAN_URL_FR = 'https://www.swissmedic.ch//swissmedic/fr/medicaments-a-usage-humain'
SWISSMEDIC_HUMAN_URL_IT = 'https://www.swissmedic.ch//swissmedic/it/home/medicamenti-per-uso-umano'
include HttpFile
ARCHIVE_PATH = File.expand_path('../../data', File.dirname(__FILE__))
ARCHIVE_PATH = ODDB::WORK_DIR
# Recipients for Plugin-Specific Update-Logs can be added in
# 'Plugin's subclasses
RECIPIENTS = []
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/refdata_jur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.company_address_matches(new_addr, old_addr)
def self.download_partners_xml
xml = nil
begin
file2save = File.join(ODDB.config.data_dir, 'xml', 'refdata_jur.xml')
file2save = File.join(ODDB::WORK_DIR, 'xml', 'refdata_jur.xml')
FileUtils.rm_f(file2save, verbose: false)
@client = Savon.client(wsdl: "https://refdatabase.refdata.ch/Service/Partner.asmx?WSDL")
# TYPE Search Type
Expand Down Expand Up @@ -78,8 +78,8 @@ def self.setup_default_agent
agent
end
DebugImport = defined?(MiniTest)
Companies_XML = File.expand_path(File.join(__FILE__, '../../../data/xml/refdata_jur_latest.xml'))
Companies_curr = File.expand_path(File.join(__FILE__, "../../../data/xml/refdata_jur_#{Time.now.strftime('%Y.%m.%d')}.xml"))
Companies_XML = File.join(ODDB::WORK_DIR, 'xml/refdata_jur_latest.xml')
Companies_curr = File.join(ODDB::WORK_DIR, "xml/refdata_jur_#{Time.now.strftime('%Y.%m.%d')}.xml")
# MedRegURL = 'http://www.medregom.admin.ch/'
# role_types are => ["Pharm", "Indus", "Hosp", "DruSto", "SerFirm", "DoctMed", "PubHea", "Whole", "Pharmst", "Inst", "HeaIns", "IntOrg", "HeaEmpl", "NursHom", "ONursOrg", "SWFirm", "EmergServ", "Assoc", "NonHealthCare", "HeaTec", "AccIns", "HeaProd", "SpecPra", "Drugg", "GrpPra", "Dent", "Veter", "Nurse", "Lab", "Chiro", "HeaProv", "Physio", "LabLeader", "Midw", "Psycho", "Naturopath", "NutrAdv", "SocSec", "Spitex", "DentGrpPra", "CompTherapist", "VetGrpPra", "PrivPra", "Ergo", "MedPracAss", "DiabAdv", "SpeeTher", "PharmAss", "MedSecr", "EmergCent"]

Expand Down
6 changes: 3 additions & 3 deletions src/plugin/refdata_nat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Doctors
def self.download_doctors_xml
xml = nil
begin
file2save = File.join(ODDB.config.data_dir, 'xml', 'refdata_nat.xml')
file2save = File.join(ODDB::WORK_DIR, 'xml', 'refdata_nat.xml')
FileUtils.rm_f(file2save, verbose: false)
@client = Savon.client(wsdl: "https://refdatabase.refdata.ch/Service/Partner.asmx?WSDL")
# TYPE Search Type
Expand Down Expand Up @@ -71,8 +71,8 @@ def self.setup_default_agent
agent
end
DebugImport = defined?(MiniTest)
Doctors_XML = File.expand_path(File.join(__FILE__, '../../../data/xml/refdata_nat_latest.xml'))
Doctors_curr = File.expand_path(File.join(__FILE__, "../../../data/xml/refdata_nat_#{Time.now.strftime('%Y.%m.%d')}.xml"))
Doctors_XML = File.join(ODDB::WORK_DIR, 'xml/refdata_nat_latest.xml')
Doctors_curr = File.join(ODDB::WORK_DIR, "xml/refdata_nat_#{Time.now.strftime('%Y.%m.%d')}.xml")
# MedRegURL = 'http://www.medregom.admin.ch/'
# role_types are => ["Pharm", "Indus", "Hosp", "DruSto", "SerFirm", "DoctMed", "PubHea", "Whole", "Pharmst", "Inst", "HeaIns", "IntOrg", "HeaEmpl", "NursHom", "ONursOrg", "SWFirm", "EmergServ", "Assoc", "NonHealthCare", "HeaTec", "AccIns", "HeaProd", "SpecPra", "Drugg", "GrpPra", "Dent", "Veter", "Nurse", "Lab", "Chiro", "HeaProv", "Physio", "LabLeader", "Midw", "Psycho", "Naturopath", "NutrAdv", "SocSec", "Spitex", "DentGrpPra", "CompTherapist", "VetGrpPra", "PrivPra", "Ergo", "MedPracAss", "DiabAdv", "SpeeTher", "PharmAss", "MedSecr", "EmergCent"]

Expand Down
Loading

0 comments on commit 85b4b92

Please sign in to comment.