scout-gear 10.4.0 → 10.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +100 -656
  3. data/Rakefile +1 -0
  4. data/VERSION +1 -1
  5. data/bin/scout +1 -3
  6. data/lib/scout/association/fields.rb +170 -0
  7. data/lib/scout/association/index.rb +229 -0
  8. data/lib/scout/association/item.rb +227 -0
  9. data/lib/scout/association/util.rb +7 -0
  10. data/lib/scout/association.rb +100 -0
  11. data/lib/scout/entity/format.rb +62 -0
  12. data/lib/scout/entity/identifiers.rb +111 -0
  13. data/lib/scout/entity/object.rb +20 -0
  14. data/lib/scout/entity/property.rb +165 -0
  15. data/lib/scout/entity.rb +40 -0
  16. data/lib/scout/offsite/step.rb +2 -2
  17. data/lib/scout/{tsv/persist → persist/engine}/fix_width_table.rb +25 -33
  18. data/lib/scout/persist/engine/packed_index.rb +100 -0
  19. data/lib/scout/persist/engine/sharder.rb +219 -0
  20. data/lib/scout/{tsv/persist → persist/engine}/tkrzw.rb +0 -17
  21. data/lib/scout/{tsv/persist → persist/engine}/tokyocabinet.rb +55 -31
  22. data/lib/scout/persist/engine.rb +4 -0
  23. data/lib/scout/{tsv/persist/adapter.rb → persist/tsv/adapter/base.rb} +80 -51
  24. data/lib/scout/persist/tsv/adapter/fix_width_table.rb +106 -0
  25. data/lib/scout/persist/tsv/adapter/packed_index.rb +95 -0
  26. data/lib/scout/persist/tsv/adapter/sharder.rb +54 -0
  27. data/lib/scout/persist/tsv/adapter/tkrzw.rb +18 -0
  28. data/lib/scout/persist/tsv/adapter/tokyocabinet.rb +65 -0
  29. data/lib/scout/persist/tsv/adapter.rb +6 -0
  30. data/lib/scout/{tsv/persist → persist/tsv}/serialize.rb +5 -0
  31. data/lib/scout/persist/tsv.rb +107 -0
  32. data/lib/scout/tsv/annotation/repo.rb +83 -0
  33. data/lib/scout/tsv/annotation.rb +169 -0
  34. data/lib/scout/tsv/attach.rb +95 -19
  35. data/lib/scout/tsv/change_id/translate.rb +148 -0
  36. data/lib/scout/tsv/change_id.rb +3 -0
  37. data/lib/scout/tsv/csv.rb +85 -0
  38. data/lib/scout/tsv/dumper.rb +113 -25
  39. data/lib/scout/tsv/entity.rb +5 -0
  40. data/lib/scout/tsv/index.rb +88 -36
  41. data/lib/scout/tsv/open.rb +21 -8
  42. data/lib/scout/tsv/parser.rb +153 -90
  43. data/lib/scout/tsv/path.rb +7 -2
  44. data/lib/scout/tsv/stream.rb +48 -6
  45. data/lib/scout/tsv/transformer.rb +4 -3
  46. data/lib/scout/tsv/traverse.rb +26 -18
  47. data/lib/scout/tsv/util/process.rb +7 -0
  48. data/lib/scout/tsv/util/reorder.rb +25 -15
  49. data/lib/scout/tsv/util/select.rb +9 -1
  50. data/lib/scout/tsv/util/sort.rb +90 -2
  51. data/lib/scout/tsv/util/unzip.rb +56 -0
  52. data/lib/scout/tsv/util.rb +52 -5
  53. data/lib/scout/tsv.rb +45 -27
  54. data/lib/scout/work_queue/socket.rb +8 -0
  55. data/lib/scout/work_queue/worker.rb +22 -5
  56. data/lib/scout/work_queue.rb +38 -24
  57. data/lib/scout/workflow/definition.rb +11 -10
  58. data/lib/scout/workflow/deployment/orchestrator.rb +20 -3
  59. data/lib/scout/workflow/deployment/trace.rb +205 -0
  60. data/lib/scout/workflow/deployment.rb +1 -0
  61. data/lib/scout/workflow/documentation.rb +1 -1
  62. data/lib/scout/workflow/step/archive.rb +42 -0
  63. data/lib/scout/workflow/step/children.rb +51 -0
  64. data/lib/scout/workflow/step/config.rb +1 -1
  65. data/lib/scout/workflow/step/dependencies.rb +24 -7
  66. data/lib/scout/workflow/step/file.rb +19 -0
  67. data/lib/scout/workflow/step/info.rb +37 -9
  68. data/lib/scout/workflow/step/progress.rb +11 -2
  69. data/lib/scout/workflow/step/status.rb +8 -1
  70. data/lib/scout/workflow/step.rb +80 -25
  71. data/lib/scout/workflow/task/dependencies.rb +4 -1
  72. data/lib/scout/workflow/task/inputs.rb +91 -41
  73. data/lib/scout/workflow/task.rb +54 -57
  74. data/lib/scout/workflow/usage.rb +1 -1
  75. data/lib/scout/workflow/util.rb +4 -0
  76. data/lib/scout/workflow.rb +110 -13
  77. data/lib/scout-gear.rb +2 -0
  78. data/lib/scout.rb +0 -1
  79. data/scout-gear.gemspec +80 -23
  80. data/scout_commands/rbbt +2 -0
  81. data/test/data/person/brothers +4 -0
  82. data/test/data/person/identifiers +10 -0
  83. data/test/data/person/marriages +3 -0
  84. data/test/data/person/parents +6 -0
  85. data/test/scout/association/test_fields.rb +105 -0
  86. data/test/scout/association/test_index.rb +70 -0
  87. data/test/scout/association/test_item.rb +21 -0
  88. data/test/scout/entity/test_format.rb +19 -0
  89. data/test/scout/entity/test_identifiers.rb +58 -0
  90. data/test/scout/entity/test_object.rb +0 -0
  91. data/test/scout/entity/test_property.rb +345 -0
  92. data/test/scout/{tsv/persist → persist/engine}/test_fix_width_table.rb +0 -1
  93. data/test/scout/persist/engine/test_packed_index.rb +99 -0
  94. data/test/scout/persist/engine/test_sharder.rb +31 -0
  95. data/test/scout/persist/engine/test_tkrzw.rb +0 -0
  96. data/test/scout/persist/engine/test_tokyocabinet.rb +17 -0
  97. data/test/scout/persist/test_tsv.rb +146 -0
  98. data/test/scout/{tsv/persist/test_adapter.rb → persist/tsv/adapter/test_base.rb} +3 -4
  99. data/test/scout/persist/tsv/adapter/test_fix_width_table.rb +46 -0
  100. data/test/scout/persist/tsv/adapter/test_packed_index.rb +37 -0
  101. data/test/scout/persist/tsv/adapter/test_serialize.rb +0 -0
  102. data/test/scout/persist/tsv/adapter/test_sharder.rb +290 -0
  103. data/test/scout/{tsv/persist → persist/tsv/adapter}/test_tkrzw.rb +3 -6
  104. data/test/scout/persist/tsv/adapter/test_tokyocabinet.rb +282 -0
  105. data/test/scout/persist/tsv/test_serialize.rb +12 -0
  106. data/test/scout/test_association.rb +51 -0
  107. data/test/scout/test_entity.rb +40 -0
  108. data/test/scout/test_tsv.rb +33 -4
  109. data/test/scout/test_work_queue.rb +3 -2
  110. data/test/scout/test_workflow.rb +16 -15
  111. data/test/scout/tsv/annotation/test_repo.rb +150 -0
  112. data/test/scout/tsv/change_id/test_translate.rb +178 -0
  113. data/test/scout/tsv/test_annotation.rb +52 -0
  114. data/test/scout/tsv/test_attach.rb +226 -1
  115. data/test/scout/tsv/test_change_id.rb +25 -0
  116. data/test/scout/tsv/test_csv.rb +50 -0
  117. data/test/scout/tsv/test_dumper.rb +38 -0
  118. data/test/scout/tsv/test_entity.rb +0 -0
  119. data/test/scout/tsv/test_index.rb +82 -0
  120. data/test/scout/tsv/test_open.rb +44 -0
  121. data/test/scout/tsv/test_parser.rb +70 -0
  122. data/test/scout/tsv/test_stream.rb +22 -0
  123. data/test/scout/tsv/test_transformer.rb +27 -3
  124. data/test/scout/tsv/test_traverse.rb +78 -0
  125. data/test/scout/tsv/util/test_process.rb +16 -0
  126. data/test/scout/tsv/util/test_reorder.rb +67 -0
  127. data/test/scout/tsv/util/test_sort.rb +28 -1
  128. data/test/scout/tsv/util/test_unzip.rb +32 -0
  129. data/test/scout/work_queue/test_socket.rb +4 -1
  130. data/test/scout/workflow/deployment/test_orchestrator.rb +17 -26
  131. data/test/scout/workflow/deployment/test_trace.rb +25 -0
  132. data/test/scout/workflow/step/test_archive.rb +28 -0
  133. data/test/scout/workflow/step/test_children.rb +25 -0
  134. data/test/scout/workflow/step/test_info.rb +16 -0
  135. data/test/scout/workflow/task/test_dependencies.rb +16 -16
  136. data/test/scout/workflow/task/test_inputs.rb +45 -1
  137. data/test/scout/workflow/test_definition.rb +52 -0
  138. data/test/scout/workflow/test_step.rb +57 -0
  139. data/test/scout/workflow/test_task.rb +26 -1
  140. data/test/scout/workflow/test_usage.rb +4 -4
  141. data/test/test_helper.rb +23 -1
  142. metadata +71 -14
  143. data/lib/scout/tsv/persist.rb +0 -27
  144. data/test/scout/tsv/persist/test_tokyocabinet.rb +0 -120
  145. data/test/scout/tsv/test_persist.rb +0 -45
@@ -0,0 +1,51 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/tsv'
5
+ class TestAssociation < Test::Unit::TestCase
6
+
7
+ def test_marriages_simple
8
+ database = Association.database(datadir_test.person.marriages, :source => "Wife", :target => "Husband")
9
+ assert_equal "001", database["002"]["Husband"]
10
+ assert_equal "2021", database["002"]["Date"]
11
+ end
12
+
13
+ def test_marriages_open
14
+ database = Association.database(datadir_test.person.marriages, :source => "Wife (ID)=>Alias", :target => "Husband (ID)=>Name")
15
+ assert_equal "Miguel", database["Clei"]["Husband"]
16
+ assert_equal "2021", database["Clei"]["Date"]
17
+ assert_include database.key_field, "Alias"
18
+ end
19
+
20
+ def test_marriages_partial_field
21
+ database = Association.database(datadir_test.person.marriages, :source => "Wife=>Alias", :target => "Husband=>Name")
22
+ assert_equal "Miguel", database["Clei"]["Husband"]
23
+ assert_equal "2021", database["Clei"]["Date"]
24
+ assert_include database.key_field, "Alias"
25
+ assert_include database.fields.first, "Name"
26
+ end
27
+
28
+ def test_marriages_open_from_tsv
29
+ database = Association.database(datadir_test.person.marriages.tsv, :source => "Wife (ID)=>Alias", :target => "Husband (ID)=>Name")
30
+ assert_equal "Miguel", database["Clei"]["Husband"]
31
+ assert_equal "2021", database["Clei"]["Date"]
32
+ assert_include database.key_field, "Alias"
33
+ end
34
+
35
+ def test_brothers_id
36
+ database = Association.database(datadir_test.person.brothers, :source => "Older=~Older (Alias)=>Name", :target => "Younger=~Younger (Alias)=>ID")
37
+ assert_equal '001', database["Isabel"]["Younger"]
38
+ end
39
+
40
+ def test_brothers_rename
41
+ database = Association.database(datadir_test.person.brothers, :source => "Older=~Older (Alias)=>Name")
42
+ assert_equal "Older (Name)", database.key_field
43
+ end
44
+
45
+ def test_parents_flat
46
+ tsv = datadir_test.person.parents.tsv type: :flat, fields: ["Parent"]
47
+ database = Association.database(tsv)
48
+ assert_equal database["Miki"], %w(Juan Mariluz)
49
+ end
50
+ end
51
+
@@ -0,0 +1,40 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestEntity < Test::Unit::TestCase
5
+
6
+ setup do
7
+ Entity.entity_property_cache = tmpdir.property_cache
8
+ end
9
+
10
+ module Person
11
+ extend Entity
12
+
13
+ annotation :language
14
+
15
+ property :salutation do
16
+ case language
17
+ when 'es'
18
+ "Hola #{self}"
19
+ else
20
+ "Hi #{self}"
21
+ end
22
+ end
23
+ end
24
+
25
+ module EmptyEntity
26
+ extend Entity
27
+ end
28
+
29
+ def test_person
30
+ person = Person.setup("Miguel", 'es')
31
+ assert_equal "Hola Miguel", person.salutation
32
+
33
+ person.language = 'en'
34
+ assert_equal "Hi Miguel", person.salutation
35
+ end
36
+
37
+ def test_empty
38
+ refute EmptyEntity.setup("foo").nil?
39
+ end
40
+ end
@@ -2,6 +2,11 @@ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
2
  require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
3
 
4
4
  class TestTSV < Test::Unit::TestCase
5
+ def test_identifier_file
6
+ tsv = datadir_test.person.marriages.tsv
7
+ assert tsv.identifier_files.any?
8
+ end
9
+
5
10
  def test_open_with_data
6
11
  content =<<-'EOF'
7
12
  #: :sep=/\s+/#:type=:double#:merge=:concat
@@ -20,7 +25,7 @@ row4 a a id3
20
25
  EOF
21
26
 
22
27
  tsv = TmpFile.with_file(content) do |filename|
23
- TSV.open(filename, :persist => false)
28
+ TSV.open(filename)
24
29
  end
25
30
 
26
31
  TmpFile.with_file(content2) do |filename|
@@ -263,7 +268,7 @@ c 3
263
268
  end
264
269
  end
265
270
 
266
- def TODO_test_tsv_grep
271
+ def test_tsv_grep
267
272
  content =<<-EOF
268
273
  #: :sep=/\\s+/#:type=:single
269
274
  #Id Value
@@ -277,8 +282,7 @@ d 22
277
282
  tsv = TSV.open(filename, :key_field => "Value", :tsv_grep => "2")
278
283
  assert_includes tsv, "2"
279
284
  refute_includes tsv, "3"
280
- assert(tsv.include?("2"))
281
- assert(! tsv.include?("3"))
285
+ refute_includes tsv, "1"
282
286
  end
283
287
  end
284
288
 
@@ -358,4 +362,29 @@ row2 a a id3
358
362
  assert_include tsv.keys, 'row2'
359
363
  end
360
364
 
365
+ def test_to_hash
366
+ content =<<-EOF
367
+ #Id ValueA ValueB OtherID
368
+ row1 a|aa|aaa b Id1|Id2
369
+ row2 A B Id3
370
+ EOF
371
+
372
+ TmpFile.with_file(content) do |filename|
373
+ tsv = TSV.open(filename, :sep => /\s+/)
374
+ hash = tsv.to_hash
375
+ refute TSV === hash
376
+ end
377
+ end
378
+
379
+ def test_identifiers
380
+ content =<<-EOF
381
+ #Id ValueA ValueB OtherID
382
+ row1 a|aa|aaa b Id1|Id2
383
+ row2 A B Id3
384
+ EOF
385
+
386
+ TmpFile.with_file(content) do |filename|
387
+ tsv = TSV.open(filename, :sep => /\s+/, :identifiers => Scout.share.identifiers)
388
+ end
389
+ end
361
390
  end
@@ -91,7 +91,7 @@ class TestWorkQueue < Test::Unit::TestCase
91
91
 
92
92
  def test_queue_error
93
93
  5.times do |i|
94
- num = 100
94
+ num = 20
95
95
  reps = 10_000
96
96
 
97
97
  q = WorkQueue.new num do |obj|
@@ -106,8 +106,8 @@ class TestWorkQueue < Test::Unit::TestCase
106
106
 
107
107
  Log.with_severity 7 do
108
108
  t = Thread.new do
109
- Thread.current["name"] = "queue writer"
110
109
  Thread.current.report_on_exception = false
110
+ Thread.current["name"] = "queue writer"
111
111
  reps.times do |i|
112
112
  q.write i
113
113
  end
@@ -123,6 +123,7 @@ class TestWorkQueue < Test::Unit::TestCase
123
123
  raise $!
124
124
  ensure
125
125
  t.join
126
+ q.close
126
127
  end
127
128
  end
128
129
  end
@@ -6,6 +6,9 @@ class TestWorkflow < Test::Unit::TestCase
6
6
  module Pantry
7
7
  extend Resource
8
8
  self.subdir = 'share/pantry'
9
+ self.path_maps[:tmp] = TestWorkflow.tmpdir
10
+ self.path_maps[:default] = :tmp
11
+ self.map_order = [:tmp]
9
12
 
10
13
  Pantry.claim Pantry.eggs, :proc do
11
14
  Log.info "Buying Eggs in the store"
@@ -24,42 +27,40 @@ class TestWorkflow < Test::Unit::TestCase
24
27
  end
25
28
 
26
29
  module Baking
27
- def self.whisk(eggs)
30
+ extend Workflow
31
+
32
+ helper :whisk do |eggs|
28
33
  "Whisking eggs from #{eggs}"
29
34
  end
30
35
 
31
- def self.mix(base, mixer)
36
+ helper :mix do |base, mixer|
32
37
  "Mixing base (#{base}) with mixer (#{mixer})"
33
38
  end
34
39
 
35
- def self.bake(batter)
40
+ helper :bake do |batter|
36
41
  "Baking batter (#{batter})"
37
42
  end
38
- end
39
-
40
- module Baking
41
- extend Workflow
42
43
 
43
44
  dep :prepare_batter
44
45
  task :bake_muffin_tray => :string do
45
- Baking.bake(step(:prepare_batter).load)
46
+ bake(step(:prepare_batter).load)
46
47
  end
47
48
 
48
49
  dep :whisk_eggs
49
50
  input :add_bluberries, :boolean
50
51
  task :prepare_batter => :string do |add_bluberries|
51
52
  whisked_eggs = step(:whisk_eggs).load
52
- batter = Baking.mix(whisked_eggs, Pantry.flour.produce)
53
+ batter = mix(whisked_eggs, Pantry.flour.produce)
53
54
 
54
55
  if add_bluberries
55
- batter = Baking.mix(batter, Pantry.blueberries.produce)
56
+ batter = mix(batter, Pantry.blueberries.produce)
56
57
  end
57
58
 
58
59
  batter
59
60
  end
60
61
 
61
62
  task :whisk_eggs => :string do
62
- Baking.whisk(Pantry.eggs.produce)
63
+ whisk(Pantry.eggs.produce)
63
64
  end
64
65
  end
65
66
 
@@ -78,10 +79,10 @@ class TestWorkflow < Test::Unit::TestCase
78
79
  end
79
80
 
80
81
  def test_baking
81
- assert_equal "Baking batter (Mixing base (Mixing base (Whisking eggs from share/pantry/eggs) with mixer (share/pantry/flour)) with mixer (share/pantry/blueberries))",
82
- Baking.job(:bake_muffin_tray, :add_bluberries => true).run
83
-
84
82
  assert_equal "Baking batter (Mixing base (Whisking eggs from share/pantry/eggs) with mixer (share/pantry/flour))",
85
- Baking.job(:bake_muffin_tray).run
83
+ Baking.job(:bake_muffin_tray, "Normal muffin").run
84
+
85
+ assert_equal "Baking batter (Mixing base (Mixing base (Whisking eggs from share/pantry/eggs) with mixer (share/pantry/flour)) with mixer (share/pantry/blueberries))",
86
+ Baking.job(:bake_muffin_tray, "Blueberry muffin", :add_bluberries => true).run
86
87
  end
87
88
  end
@@ -0,0 +1,150 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/tsv'
5
+ require 'scout/annotation'
6
+
7
+ class TestAnnotationRepo < Test::Unit::TestCase
8
+ module AnnotationClass
9
+ extend Annotation
10
+
11
+ annotation :code
12
+ end
13
+
14
+ def test_simple_annotation_nil
15
+
16
+ TmpFile.with_file do |repo|
17
+ annotation = Persist.annotation_repo_persist(repo, "My annotation nil") do
18
+ nil
19
+ end
20
+
21
+ assert_nil annotation
22
+
23
+ annotation = assert_nothing_raised do
24
+ Persist.annotation_repo_persist(repo, "My annotation nil") do
25
+ raise
26
+ end
27
+ end
28
+
29
+ assert_nil annotation
30
+ end
31
+ end
32
+
33
+ def test_simple_annotation_empty
34
+
35
+ TmpFile.with_file do |repo|
36
+ annotation = Persist.annotation_repo_persist(repo, "My annotation nil") do
37
+ []
38
+ end
39
+
40
+ assert_empty annotation
41
+
42
+ annotation = assert_nothing_raised do
43
+ Persist.annotation_repo_persist(repo, "My annotation nil") do
44
+ raise
45
+ end
46
+ end
47
+
48
+ assert_empty annotation
49
+ end
50
+ end
51
+
52
+
53
+
54
+ def test_simple_annotation
55
+
56
+ TmpFile.with_file do |repo|
57
+ annotation = Persist.annotation_repo_persist(repo, "My annotation simple") do
58
+ AnnotationClass.setup("TESTANNOTATION", code: "test_code")
59
+ end
60
+
61
+ assert_equal "TESTANNOTATION", annotation
62
+ assert_equal "test_code", annotation.code
63
+
64
+ annotation = assert_nothing_raised do
65
+ Persist.annotation_repo_persist(repo, "My annotation simple") do
66
+ raise
67
+ end
68
+ end
69
+
70
+ assert_equal "TESTANNOTATION", annotation
71
+ assert_equal "test_code", annotation.code
72
+ end
73
+ end
74
+
75
+ def test_array_with_annotation
76
+
77
+ TmpFile.with_file do |repo|
78
+ annotation = Persist.annotation_repo_persist(repo, "My annotation") do
79
+ [
80
+ AnnotationClass.setup("TESTANNOTATION", code: "test_code"),
81
+ AnnotationClass.setup("TESTANNOTATION2", code: "test_code2")
82
+ ]
83
+ end.first
84
+
85
+ assert_equal "TESTANNOTATION", annotation
86
+ assert_equal "test_code", annotation.code
87
+
88
+ annotation = assert_nothing_raised do
89
+ Persist.annotation_repo_persist(repo, "My annotation") do
90
+ raise
91
+ end.last
92
+ end
93
+
94
+ assert_equal "TESTANNOTATION2", annotation
95
+ assert_equal "test_code2", annotation.code
96
+ end
97
+ end
98
+
99
+ def test_annotation_array
100
+
101
+ TmpFile.with_file do |repo|
102
+ annotation = Persist.annotation_repo_persist(repo, "My annotation array") do
103
+ a = AnnotationClass.setup(["TESTANNOTATION", "TESTANNOTATION2"], code: "test_code")
104
+ a.extend AnnotatedArray
105
+ a
106
+ end.first
107
+
108
+ assert_equal "TESTANNOTATION", annotation
109
+ assert_equal "test_code", annotation.code
110
+
111
+ annotation = assert_nothing_raised do
112
+ Persist.annotation_repo_persist(repo, "My annotation array") do
113
+ raise
114
+ end.last
115
+ end
116
+
117
+ assert_equal "TESTANNOTATION2", annotation
118
+ assert_equal "test_code", annotation.code
119
+ end
120
+ end
121
+
122
+ def test_annotation_array_with_fields
123
+
124
+ TmpFile.with_file do |repo_file|
125
+ repo = Persist.open_tokyocabinet(repo_file, false, :list, :BDB)
126
+ TSV.setup(repo, :fields => ["literal", "annotation_types", "code"], :key_field => "Annotation ID", type: :list)
127
+ repo.extend TSVAdapter
128
+
129
+ annotation = Persist.annotation_repo_persist(repo, "My annotation array") do
130
+ a = AnnotationClass.setup(["TESTANNOTATION", "TESTANNOTATION2"], code: "test_code")
131
+ a.extend AnnotatedArray
132
+ a
133
+ end.first
134
+
135
+ assert_equal "TESTANNOTATION", annotation
136
+ assert_equal "test_code", annotation.code
137
+
138
+ repo = Persist.open_tokyocabinet(repo_file, false, :list, :BDB)
139
+ annotation2 = assert_nothing_raised do
140
+ Persist.annotation_repo_persist(repo, "My annotation array") do
141
+ raise
142
+ end.last
143
+ end
144
+
145
+ assert_equal "TESTANNOTATION2", annotation2
146
+ assert_equal "test_code", annotation2.code
147
+ end
148
+ end
149
+ end
150
+
@@ -0,0 +1,178 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/tsv'
5
+
6
+ class TestTSVTranslate < Test::Unit::TestCase
7
+ def test_marriage_index
8
+ marriages = datadir_test.person.marriages.tsv
9
+ identifiers = datadir_test.person.identifiers.tsv
10
+ index = TSV.translation_index [marriages, identifiers], "Husband (ID)", "Husband (Name)"
11
+ assert_equal 'Miguel', index["001"]
12
+ end
13
+
14
+ def test_translate_marriages
15
+ marriages = datadir_test.person.marriages.tsv
16
+ marriages = marriages.translate "Husband (ID)", "Husband (Name)"
17
+ marriages = marriages.translate "Wife (ID)", "Wife (Name)"
18
+ assert_equal "Cleia", marriages["Miguel"]["Wife"]
19
+ end
20
+
21
+
22
+ def test_translation_path
23
+ file_paths = {
24
+ :file1 => %w(A B C),
25
+ :file2 => %w(Y Z A),
26
+ :file3 => %w(Y X),
27
+ :file4 => %w(X R),
28
+ :file5 => %w(A R),
29
+ }
30
+
31
+ assert_equal [:file1], TSV.translation_path(file_paths, "C", "A")
32
+ assert_equal [:file1, :file2], TSV.translation_path(file_paths, "B", "Y")
33
+ assert_equal [:file1, :file2, :file3], TSV.translation_path(file_paths, "B", "X")
34
+ assert_equal [:file1, :file5], TSV.translation_path(file_paths, "B", "R")
35
+ end
36
+
37
+ def test_translation_index
38
+ f1=<<-EOF
39
+ #: :sep=' '
40
+ #A B C
41
+ a b c
42
+ aa bb cc
43
+ EOF
44
+
45
+ f2=<<-EOF
46
+ #: :sep=' '
47
+ #Y Z A
48
+ y z a
49
+ yy zz aa
50
+ EOF
51
+
52
+ f3=<<-EOF
53
+ #: :sep=' '
54
+ #Y X
55
+ y x
56
+ yy xx
57
+ EOF
58
+
59
+ TmpFile.with_file(f1) do |tf1|
60
+ TmpFile.with_file(f2) do |tf2|
61
+ TmpFile.with_file(f3) do |tf3|
62
+ index = TSV.translation_index([tf1, tf2, tf3], 'A', 'X')
63
+ assert_equal 'x', index['a']
64
+ assert_equal 'xx', index['aa']
65
+
66
+ index = TSV.translation_index([tf1, TSV.open(tf2), tf3], 'A', 'X')
67
+ assert_equal 'x', index['a']
68
+ assert_equal 'xx', index['aa']
69
+
70
+ index = TSV.translation_index([tf1, TSV.open(tf2), tf3], 'C', 'Y')
71
+ assert_equal 'y', index['c']
72
+ assert_equal 'yy', index['cc']
73
+
74
+ index = TSV.translation_index([tf1, TSV.open(tf2), tf3], 'Z', 'Y')
75
+ assert_equal 'y', index['z']
76
+ assert_equal 'yy', index['zz']
77
+
78
+ index = TSV.translation_index([tf1, tf2, tf3], 'X', 'A')
79
+ assert_equal 'a', index['x']
80
+ assert_equal 'aa', index['xx']
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ def test_translation_index_no_source
87
+ f1=<<-EOF
88
+ #: :sep=' '
89
+ #A B C
90
+ a b c
91
+ aa bb cc
92
+ EOF
93
+
94
+ f2=<<-EOF
95
+ #: :sep=' '
96
+ #Y Z A
97
+ y z a
98
+ yy zz aa
99
+ EOF
100
+
101
+ f3=<<-EOF
102
+ #: :sep=' '
103
+ #Y X
104
+ y x
105
+ yy xx
106
+ EOF
107
+
108
+ TmpFile.with_file(f1) do |tf1|
109
+ TmpFile.with_file(f2) do |tf2|
110
+ TmpFile.with_file(f3) do |tf3|
111
+ index = TSV.translation_index([tf2,tf3],nil , 'X')
112
+ assert_equal 'x', index['a']
113
+ assert_equal 'xx', index['aa']
114
+ end
115
+ end
116
+ end
117
+ end
118
+ def test_translate
119
+
120
+ f1=<<-EOF
121
+ #: :sep=' '
122
+ #A B C
123
+ a b c
124
+ aa bb cc
125
+ EOF
126
+
127
+ identifiers=<<-EOF
128
+ #: :sep=' '
129
+ #A X
130
+ a x
131
+ aa xx
132
+ EOF
133
+
134
+ TmpFile.with_file(f1) do |tf1|
135
+ TmpFile.with_file(identifiers) do |ti|
136
+ tsv = TSV.open tf1, :identifiers => ti
137
+
138
+ assert TSV.translate(tsv, tsv.key_field, "X").include? "x"
139
+ end
140
+ end
141
+ end
142
+
143
+ def test_translate_two_files
144
+
145
+ f1=<<-EOF
146
+ #: :sep=' '
147
+ #A B C
148
+ a b c
149
+ aa bb cc
150
+ EOF
151
+
152
+ identifiers1=<<-EOF
153
+ #: :sep=' '
154
+ #Y Z A
155
+ y z a
156
+ yy zz aa
157
+ EOF
158
+
159
+ identifiers2=<<-EOF
160
+ #: :sep=' '
161
+ #Y X
162
+ y x
163
+ yy xx
164
+ EOF
165
+
166
+ TmpFile.with_file(f1) do |tf1|
167
+ TmpFile.with_file(identifiers1) do |ti1|
168
+ TmpFile.with_file(identifiers2) do |ti2|
169
+ tsv = TSV.open tf1, :identifiers => [ti1, ti2]
170
+
171
+ assert TSV.translate(tsv, tsv.key_field, "X").include? "x"
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ end
178
+
@@ -0,0 +1,52 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+ require 'scout/tsv'
4
+
5
+ class TestAnnotationTSV < Test::Unit::TestCase
6
+ module AnnotationClass
7
+ extend Annotation
8
+
9
+ annotation :code, :code2
10
+ end
11
+
12
+ def test_tsv
13
+ str1 = "string1"
14
+ str2 = "string2"
15
+ AnnotationClass.setup(str1, :c11, :c12)
16
+ AnnotationClass.setup(str2, :c21, :c22)
17
+
18
+ assert_equal str1, Annotation.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.annotation_id + "#0"]["literal"]
19
+ assert_equal :c11, Annotation.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.annotation_id + "#0"]["code"]
20
+ assert_equal str2, Annotation.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str2.annotation_id + "#1"]["literal"]
21
+ assert_equal :c21, Annotation.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str2.annotation_id + "#1"]["code"]
22
+ assert_equal "c11", JSON.parse(Annotation.tsv([str1, str2], :code, :JSON).tap{|t| t.unnamed = false}[str1.annotation_id + "#0"]["JSON"])["code"]
23
+ end
24
+
25
+ def test_load_array_tsv
26
+ str1 = "string1"
27
+ str2 = "string2"
28
+ AnnotationClass.setup(str1, :c11, :c12)
29
+ AnnotationClass.setup(str2, :c21, :c22)
30
+
31
+ tsv = Annotation.tsv([str1, str2], :all)
32
+
33
+ list = Annotation.load_tsv(tsv)
34
+ assert_equal [str1, str2], list
35
+ assert_equal :c11, list.first.code
36
+ end
37
+
38
+ def test_load_extended_array_tsv
39
+ str1 = "string1"
40
+ str2 = "string2"
41
+ a = [str1, str2]
42
+ code = "Annotation String 2"
43
+ AnnotationClass.setup(a, code)
44
+ a.extend AnnotatedArray
45
+
46
+
47
+ assert_equal code, Annotation.load_tsv(Annotation.tsv(a, :all)).code
48
+
49
+ assert_equal str2, Annotation.load_tsv(Annotation.tsv(a, :literal, :JSON)).sort.last
50
+ end
51
+ end
52
+