miga-base 0.7.3.1 → 0.7.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/lib/miga/cli.rb +10 -8
  3. data/lib/miga/cli/action.rb +2 -3
  4. data/lib/miga/cli/action/about.rb +5 -6
  5. data/lib/miga/cli/action/add.rb +18 -12
  6. data/lib/miga/cli/action/add_result.rb +2 -3
  7. data/lib/miga/cli/action/archive.rb +1 -2
  8. data/lib/miga/cli/action/classify_wf.rb +8 -6
  9. data/lib/miga/cli/action/console.rb +0 -1
  10. data/lib/miga/cli/action/daemon.rb +7 -7
  11. data/lib/miga/cli/action/date.rb +0 -1
  12. data/lib/miga/cli/action/derep_wf.rb +5 -4
  13. data/lib/miga/cli/action/doctor.rb +71 -82
  14. data/lib/miga/cli/action/doctor/base.rb +102 -0
  15. data/lib/miga/cli/action/edit.rb +14 -2
  16. data/lib/miga/cli/action/files.rb +8 -8
  17. data/lib/miga/cli/action/find.rb +5 -6
  18. data/lib/miga/cli/action/generic.rb +7 -7
  19. data/lib/miga/cli/action/get.rb +20 -17
  20. data/lib/miga/cli/action/get_db.rb +8 -2
  21. data/lib/miga/cli/action/index_wf.rb +1 -1
  22. data/lib/miga/cli/action/init.rb +53 -41
  23. data/lib/miga/cli/action/init/daemon_helper.rb +65 -43
  24. data/lib/miga/cli/action/lair.rb +7 -7
  25. data/lib/miga/cli/action/ln.rb +6 -6
  26. data/lib/miga/cli/action/ls.rb +1 -2
  27. data/lib/miga/cli/action/ncbi_get.rb +11 -3
  28. data/lib/miga/cli/action/new.rb +4 -4
  29. data/lib/miga/cli/action/next_step.rb +0 -1
  30. data/lib/miga/cli/action/preproc_wf.rb +3 -3
  31. data/lib/miga/cli/action/quality_wf.rb +1 -1
  32. data/lib/miga/cli/action/rm.rb +2 -3
  33. data/lib/miga/cli/action/run.rb +8 -8
  34. data/lib/miga/cli/action/stats.rb +8 -4
  35. data/lib/miga/cli/action/summary.rb +7 -6
  36. data/lib/miga/cli/action/tax_dist.rb +8 -4
  37. data/lib/miga/cli/action/tax_index.rb +3 -4
  38. data/lib/miga/cli/action/tax_set.rb +7 -6
  39. data/lib/miga/cli/action/tax_test.rb +6 -5
  40. data/lib/miga/cli/action/wf.rb +25 -19
  41. data/lib/miga/cli/base.rb +34 -32
  42. data/lib/miga/cli/objects_helper.rb +27 -18
  43. data/lib/miga/cli/opt_helper.rb +3 -2
  44. data/lib/miga/common.rb +2 -5
  45. data/lib/miga/common/base.rb +15 -16
  46. data/lib/miga/common/format.rb +8 -5
  47. data/lib/miga/common/hooks.rb +1 -4
  48. data/lib/miga/common/path.rb +4 -9
  49. data/lib/miga/common/with_daemon.rb +5 -2
  50. data/lib/miga/common/with_daemon_class.rb +1 -1
  51. data/lib/miga/common/with_result.rb +2 -1
  52. data/lib/miga/daemon.rb +93 -44
  53. data/lib/miga/daemon/base.rb +30 -11
  54. data/lib/miga/dataset.rb +47 -37
  55. data/lib/miga/dataset/base.rb +52 -37
  56. data/lib/miga/dataset/hooks.rb +3 -4
  57. data/lib/miga/dataset/result.rb +17 -1
  58. data/lib/miga/dataset/status.rb +6 -5
  59. data/lib/miga/json.rb +5 -7
  60. data/lib/miga/lair.rb +4 -0
  61. data/lib/miga/metadata.rb +4 -3
  62. data/lib/miga/project.rb +29 -20
  63. data/lib/miga/project/base.rb +52 -37
  64. data/lib/miga/project/dataset.rb +33 -26
  65. data/lib/miga/project/hooks.rb +0 -3
  66. data/lib/miga/project/result.rb +14 -5
  67. data/lib/miga/remote_dataset.rb +85 -72
  68. data/lib/miga/remote_dataset/base.rb +11 -13
  69. data/lib/miga/remote_dataset/download.rb +34 -12
  70. data/lib/miga/result.rb +48 -53
  71. data/lib/miga/result/base.rb +0 -2
  72. data/lib/miga/result/dates.rb +1 -3
  73. data/lib/miga/result/source.rb +15 -16
  74. data/lib/miga/result/stats.rb +37 -27
  75. data/lib/miga/tax_dist.rb +6 -3
  76. data/lib/miga/tax_index.rb +17 -17
  77. data/lib/miga/taxonomy.rb +6 -1
  78. data/lib/miga/taxonomy/base.rb +19 -15
  79. data/lib/miga/version.rb +19 -16
  80. data/scripts/project_stats.bash +3 -0
  81. data/scripts/stats.bash +1 -1
  82. data/test/common_test.rb +3 -11
  83. data/test/daemon_helper.rb +38 -0
  84. data/test/daemon_test.rb +91 -99
  85. data/test/dataset_test.rb +63 -59
  86. data/test/format_test.rb +3 -11
  87. data/test/hook_test.rb +50 -55
  88. data/test/json_test.rb +7 -8
  89. data/test/lair_test.rb +22 -28
  90. data/test/metadata_test.rb +6 -14
  91. data/test/project_test.rb +33 -40
  92. data/test/remote_dataset_test.rb +26 -32
  93. data/test/result_stats_test.rb +17 -27
  94. data/test/result_test.rb +41 -34
  95. data/test/tax_dist_test.rb +2 -4
  96. data/test/tax_index_test.rb +4 -10
  97. data/test/taxonomy_test.rb +7 -9
  98. data/test/test_helper.rb +42 -1
  99. data/test/with_daemon_test.rb +14 -22
  100. data/utils/adapters.fa +13 -0
  101. data/utils/cleanup-databases.rb +6 -5
  102. data/utils/distance/base.rb +0 -1
  103. data/utils/distance/commands.rb +19 -12
  104. data/utils/distance/database.rb +24 -21
  105. data/utils/distance/pipeline.rb +23 -10
  106. data/utils/distance/runner.rb +20 -16
  107. data/utils/distance/temporal.rb +1 -3
  108. data/utils/distances.rb +1 -1
  109. data/utils/domain-ess-genes.rb +7 -7
  110. data/utils/index_metadata.rb +5 -4
  111. data/utils/mytaxa_scan.rb +18 -16
  112. data/utils/representatives.rb +5 -4
  113. data/utils/requirements.txt +1 -1
  114. data/utils/subclade/base.rb +0 -1
  115. data/utils/subclade/pipeline.rb +7 -6
  116. data/utils/subclade/runner.rb +9 -9
  117. data/utils/subclade/temporal.rb +0 -2
  118. data/utils/subclades-compile.rb +39 -37
  119. data/utils/subclades.rb +1 -1
  120. metadata +6 -4
@@ -2,19 +2,10 @@ require 'test_helper'
2
2
  require 'miga/project'
3
3
 
4
4
  class DatasetTest < Test::Unit::TestCase
5
+ include TestHelper
5
6
 
6
7
  def setup
7
- $tmp = Dir.mktmpdir
8
- ENV['MIGA_HOME'] = $tmp
9
- FileUtils.touch(File.expand_path('.miga_rc', ENV['MIGA_HOME']))
10
- FileUtils.touch(File.expand_path('.miga_daemon.json', ENV['MIGA_HOME']))
11
- $p1 = MiGA::Project.new(File.expand_path('project1', $tmp))
12
- $d1 = $p1.add_dataset('dataset1')
13
- end
14
-
15
- def teardown
16
- FileUtils.rm_rf $tmp
17
- ENV['MIGA_HOME'] = nil
8
+ initialize_miga_home
18
9
  end
19
10
 
20
11
  def test_known_types
@@ -23,9 +14,10 @@ class DatasetTest < Test::Unit::TestCase
23
14
  end
24
15
 
25
16
  def test_exist
17
+ dataset
26
18
  assert_respond_to(MiGA::Dataset, :exist?)
27
- assert { MiGA::Dataset.exist?($p1, 'dataset1') }
28
- assert { !MiGA::Dataset.exist?($p1, 'Nope') }
19
+ assert { MiGA::Dataset.exist?(project, dataset.name) }
20
+ assert { !MiGA::Dataset.exist?(project, 'Nope') }
29
21
  end
30
22
 
31
23
  def test_info_fields
@@ -34,16 +26,16 @@ class DatasetTest < Test::Unit::TestCase
34
26
  end
35
27
 
36
28
  def test_initialize
37
- assert_raise { MiGA::Dataset.new($p1, 'dataset-1') }
38
- assert_equal($p1, $d1.project)
39
- assert_equal('dataset1', $d1.name)
40
- assert_predicate($d1, :is_ref?)
41
- assert_equal(MiGA::Metadata, $d1.metadata.class)
42
- assert_equal(:incomplete, $d1.status)
29
+ assert_raise { MiGA::Dataset.new(project, 'dataset-1') }
30
+ assert_equal(project, dataset.project)
31
+ assert_equal('dataset0', dataset.name)
32
+ assert_predicate(dataset, :is_ref?)
33
+ assert_equal(MiGA::Metadata, dataset.metadata.class)
34
+ assert_equal(:incomplete, dataset.status)
43
35
  end
44
36
 
45
37
  def test_save
46
- d2 = $p1.add_dataset('ds_save')
38
+ d2 = project.add_dataset('ds_save')
47
39
  assert_respond_to(d2, :save)
48
40
  d2.save
49
41
  assert_not_predicate(d2, :is_multi?)
@@ -57,39 +49,43 @@ class DatasetTest < Test::Unit::TestCase
57
49
  end
58
50
 
59
51
  def test_remove
60
- d2 = $p1.add_dataset('ds_remove')
52
+ d2 = project.add_dataset('ds_remove')
61
53
  assert_path_exist(d2.metadata.path)
62
54
  d2.remove!
63
55
  assert_path_not_exist(d2.metadata.path)
64
56
  end
65
57
 
66
58
  def test_info
67
- assert_equal($d1.name, $d1.info.first)
59
+ assert_equal(dataset.name, dataset.info.first)
68
60
  end
69
61
 
70
62
  def test_add_result
71
- d2 = $p1.add_dataset('ds_add_result')
63
+ d2 = project.add_dataset('ds_add_result')
72
64
  assert_nil(d2.add_result(:koop))
73
65
  assert_nil(d2.add_result(:raw_reads))
74
66
  FileUtils.touch(
75
- File.expand_path("data/01.raw_reads/#{d2.name}.1.fastq",$p1.path))
67
+ File.join(project.path, 'data', '01.raw_reads', "#{d2.name}.1.fastq")
68
+ )
76
69
  assert_nil(d2.add_result(:raw_reads))
77
70
  FileUtils.touch(
78
- File.expand_path("data/01.raw_reads/#{d2.name}.done",$p1.path))
71
+ File.join(project.path, 'data', '01.raw_reads', "#{d2.name}.done")
72
+ )
79
73
  assert_equal(MiGA::Result, d2.add_result(:raw_reads).class)
80
74
  end
81
75
 
82
76
  def test_preprocessing
83
- d2 = $p1.add_dataset('ds_preprocessing')
77
+ d2 = project.add_dataset('ds_preprocessing')
84
78
  assert_nil(d2.first_preprocessing)
85
79
  assert_nil(d2.next_preprocessing)
86
80
  assert_not_predicate(d2, :done_preprocessing?)
87
- FileUtils.touch(File.expand_path(
88
- "data/02.trimmed_reads/#{d2.name}.1.clipped.fastq", $p1.path
89
- ))
90
- FileUtils.touch(File.expand_path(
91
- "data/02.trimmed_reads/#{d2.name}.done", $p1.path
92
- ))
81
+ FileUtils.touch(
82
+ File.join(
83
+ project.path, 'data', '02.trimmed_reads', "#{d2.name}.1.clipped.fastq"
84
+ )
85
+ )
86
+ FileUtils.touch(
87
+ File.join(project.path, 'data', '02.trimmed_reads', "#{d2.name}.done")
88
+ )
93
89
  assert_equal(:trimmed_reads, d2.first_preprocessing(true))
94
90
  assert_equal(:read_quality, d2.next_preprocessing(true))
95
91
  assert { !d2.done_preprocessing?(true) }
@@ -115,28 +111,31 @@ class DatasetTest < Test::Unit::TestCase
115
111
  end
116
112
 
117
113
  def test_profile_advance
118
- d2 = $p1.add_dataset('ds_profile_advance')
114
+ d2 = project.add_dataset('ds_profile_advance')
119
115
  assert_equal(0, d2.profile_advance(true).first)
120
116
  assert_equal(0, d2.profile_advance(true).last)
121
117
  assert_equal(0, d2.profile_advance(true).inject(:+))
122
- Dir.mkdir(File.expand_path(
123
- "data/03.read_quality/#{d2.name}.solexaqa", $p1.path
124
- ))
125
- Dir.mkdir(File.expand_path(
126
- "data/03.read_quality/#{d2.name}.fastqc", $p1.path
127
- ))
128
- FileUtils.touch(File.expand_path(
129
- "data/03.read_quality/#{d2.name}.done", $p1.path
130
- ))
131
- assert_equal([0,0,1,2], d2.profile_advance(true)[0..3])
118
+ Dir.mkdir(
119
+ File.join(project.path, 'data', '03.read_quality', "#{d2.name}.solexaqa")
120
+ )
121
+ Dir.mkdir(
122
+ File.join(project.path, 'data', '03.read_quality', "#{d2.name}.fastqc")
123
+ )
124
+ FileUtils.touch(
125
+ File.join(project.path, 'data', '03.read_quality', "#{d2.name}.done")
126
+ )
127
+ assert_equal([0, 0, 1, 2], d2.profile_advance(true)[0..3])
132
128
  assert_equal(2, d2.profile_advance(true).last)
133
129
  end
134
130
 
135
131
  def test_add_result_other
136
- d2 = $p1.add_dataset('ds_add_result_other')
137
- Dir.mkdir(File.expand_path(
138
- "data/07.annotation/01.function/01.essential/#{d2.name}.ess", $p1.path
139
- ))
132
+ d2 = project.add_dataset('ds_add_result_other')
133
+ Dir.mkdir(
134
+ File.join(
135
+ project.path, 'data', '07.annotation', '01.function', '01.essential',
136
+ "#{d2.name}.ess"
137
+ )
138
+ )
140
139
  to_test = {
141
140
  trimmed_fasta: [
142
141
  "data/04.trimmed_fasta/#{d2.name}.SingleReads.fa",
@@ -152,28 +151,28 @@ class DatasetTest < Test::Unit::TestCase
152
151
  "data/06.cds/#{d2.name}.done"
153
152
  ],
154
153
  essential_genes: %w[ess.faa ess/log done]
155
- .map do |x|
156
- "data/07.annotation/01.function/01.essential/#{d2.name}.#{x}"
157
- end,
154
+ .map do |x|
155
+ "data/07.annotation/01.function/01.essential/#{d2.name}.#{x}"
156
+ end,
158
157
  ssu: [
159
158
  "data/07.annotation/01.function/02.ssu/#{d2.name}.ssu.fa",
160
159
  "data/07.annotation/01.function/02.ssu/#{d2.name}.done"
161
160
  ],
162
161
  mytaxa_scan: %w[pdf wintax mytaxa reg done]
163
- .map do |x|
164
- "data/07.annotation/03.qa/02.mytaxa_scan/#{d2.name}.#{x}"
165
- end,
162
+ .map do |x|
163
+ "data/07.annotation/03.qa/02.mytaxa_scan/#{d2.name}.#{x}"
164
+ end,
166
165
  distances: [
167
166
  "data/09.distances/01.haai/#{d2.name}.db",
168
167
  "data/09.distances/#{d2.name}.done"
169
168
  ]
170
169
  }
171
- to_test.each do |k,v|
170
+ to_test.each do |k, v|
172
171
  assert_nil(d2.add_result(k), "Result for #{k} should be nil.")
173
- v.each { |i| FileUtils.touch(File.expand_path(i, $p1.path)) }
174
- FileUtils.touch(File.expand_path(
175
- "data/04.trimmed_fasta/#{d2.name}.done", $p1.path
176
- ))
172
+ v.each { |i| FileUtils.touch(File.expand_path(i, project.path)) }
173
+ FileUtils.touch(
174
+ File.join(project.path, 'data', '04.trimmed_fasta', "#{d2.name}.done")
175
+ )
177
176
  assert_equal(
178
177
  MiGA::Result,
179
178
  d2.add_result(k).class,
@@ -183,7 +182,7 @@ class DatasetTest < Test::Unit::TestCase
183
182
  end
184
183
 
185
184
  def test_activate
186
- d = $d1
185
+ d = dataset
187
186
  assert_equal(:incomplete, d.status)
188
187
  assert_predicate(d, :active?)
189
188
  d.inactivate!
@@ -193,4 +192,9 @@ class DatasetTest < Test::Unit::TestCase
193
192
  assert_equal(:incomplete, d.status)
194
193
  assert_predicate(d, :active?)
195
194
  end
195
+
196
+ def test_preprocessing_tasks
197
+ assert_include(MiGA::Dataset.PREPROCESSING_TASKS, :cds)
198
+ assert_include(MiGA::Dataset.PREPROCESSING_TASKS, :taxonomy)
199
+ end
196
200
  end
@@ -1,17 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class FormatTest < Test::Unit::TestCase
4
-
5
- def setup
6
- $tmp = Dir.mktmpdir
7
- end
8
-
9
- def teardown
10
- FileUtils.rm_rf $tmp
11
- end
4
+ include TestHelper
12
5
 
13
6
  def helper_write_file(content)
14
- f = File.join($tmp, 'f.fa')
7
+ f = tmpfile('f.fa')
15
8
  File.open(f, 'w') { |h| h.print content }
16
9
  f
17
10
  end
@@ -76,7 +69,7 @@ class FormatTest < Test::Unit::TestCase
76
69
  o = MiGA::MiGA.seqs_length(f, :fastq, n50: true)
77
70
  assert_equal(3, o[:med])
78
71
  end
79
-
72
+
80
73
  def test_tabulate
81
74
  tab = MiGA::MiGA.tabulate(%w[a b], [%w[123 45], %w[678 90]])
82
75
  assert_equal(' a b ', tab[0])
@@ -84,5 +77,4 @@ class FormatTest < Test::Unit::TestCase
84
77
  assert_equal('123 45', tab[2])
85
78
  assert_equal('678 90', tab[3])
86
79
  end
87
-
88
80
  end
@@ -2,35 +2,24 @@ require 'test_helper'
2
2
  require 'miga/project'
3
3
 
4
4
  class HookTest < Test::Unit::TestCase
5
+ include TestHelper
5
6
 
6
7
  def setup
7
- $tmp = Dir.mktmpdir
8
- ENV['MIGA_HOME'] = $tmp
9
- FileUtils.touch(File.expand_path('.miga_rc', ENV['MIGA_HOME']))
10
- FileUtils.touch(File.expand_path('.miga_daemon.json', ENV['MIGA_HOME']))
11
- $p1 = MiGA::Project.new(File.expand_path('project1', $tmp))
12
- $d1 = $p1.add_dataset('dataset1')
13
- end
14
-
15
- def teardown
16
- FileUtils.rm_rf $tmp
17
- ENV['MIGA_HOME'] = nil
8
+ initialize_miga_home
18
9
  end
19
10
 
20
11
  def test_add_hook
21
- assert_nil($d1.hooks[:on_save])
22
- $d1.add_hook(:on_save, :run_lambda, Proc.new { $counter += 1 })
23
- assert_equal(1, $d1.hooks[:on_save].size)
12
+ assert_nil(dataset.hooks[:on_save])
13
+ dataset.add_hook(:on_save, :run_lambda, Proc.new { $counter += 1 })
14
+ assert_equal(1, dataset.hooks[:on_save].size)
24
15
  $counter = 1
25
- $d1.save
16
+ dataset.save
26
17
  assert_equal(2, $counter)
27
18
  end
28
19
 
29
20
  def test_missing_action
30
- $d1.add_hook(:on_save, :this_is_not_an_action)
31
- assert_raise do
32
- $d1.save
33
- end
21
+ dataset.add_hook(:on_save, :this_is_not_an_action)
22
+ assert_raise { dataset.save }
34
23
  end
35
24
 
36
25
  ##
@@ -47,76 +36,82 @@ class HookTest < Test::Unit::TestCase
47
36
  def test_dataset_result_hooks
48
37
  $res = :test
49
38
  $counter = 1
50
- $d1.add_hook(:on_result_ready,
51
- :run_lambda, Proc.new { |r| $res = r })
52
- $d1.add_hook(:on_result_ready_trimmed_reads,
53
- :run_lambda, Proc.new { $counter += 1 })
54
- FileUtils.touch(File.expand_path(
55
- "data/02.trimmed_reads/#{$d1.name}.1.clipped.fastq", $p1.path))
56
- FileUtils.touch(File.expand_path(
57
- "data/02.trimmed_reads/#{$d1.name}.done", $p1.path))
39
+ dataset.add_hook(:on_result_ready, :run_lambda, Proc.new { |r| $res = r })
40
+ dataset.add_hook(
41
+ :on_result_ready_trimmed_reads, :run_lambda, Proc.new { $counter += 1 }
42
+ )
43
+ FileUtils.touch(
44
+ File.join(
45
+ project.path, 'data', '02.trimmed_reads',
46
+ "#{dataset.name}.1.clipped.fastq"
47
+ )
48
+ )
49
+ FileUtils.touch(
50
+ File.join(
51
+ project.path, 'data', '02.trimmed_reads', "#{dataset.name}.done"
52
+ )
53
+ )
58
54
  assert_equal(:test, $res)
59
- $d1.add_result(:trimmed_reads)
55
+ dataset.add_result(:trimmed_reads)
60
56
  assert_equal(:trimmed_reads, $res)
61
57
  assert_equal(2, $counter)
62
58
  end
63
59
 
64
60
  def test_dataset_clear_run_counts
65
- $d1.metadata[:_try_something] = 1
66
- $d1.metadata[:_step] = 'Boop'
67
- $d1.metadata[:_not_a_counter] = 1
68
- $d1.save
69
- assert_equal(1, $d1.metadata[:_try_something])
70
- assert_equal('Boop', $d1.metadata[:_step])
71
- $d1.add_hook(:on_remove, :clear_run_counts)
72
- $d1.remove!
73
- assert_nil($d1.metadata[:_try_something])
74
- assert_nil($d1.metadata[:_step])
75
- assert_equal(1, $d1.metadata[:_not_a_counter])
61
+ dataset.metadata[:_try_something] = 1
62
+ dataset.metadata[:_step] = 'Boop'
63
+ dataset.metadata[:_not_a_counter] = 1
64
+ dataset.save
65
+ assert_equal(1, dataset.metadata[:_try_something])
66
+ assert_equal('Boop', dataset.metadata[:_step])
67
+ dataset.add_hook(:on_remove, :clear_run_counts)
68
+ dataset.remove!
69
+ assert_nil(dataset.metadata[:_try_something])
70
+ assert_nil(dataset.metadata[:_step])
71
+ assert_equal(1, dataset.metadata[:_not_a_counter])
76
72
  end
77
73
 
78
74
  def test_dataset_run_cmd
79
- f = File.expand_path('hook_ds_cmd', $tmp)
80
- $d1.metadata[:on_remove] = [[:run_cmd, "echo {{dataset}} > '#{f}'"]]
75
+ f = tmpfile('hook_ds_cmd')
76
+ dataset.metadata[:on_remove] = [[:run_cmd, "echo {{dataset}} > '#{f}'"]]
81
77
  assert_path_not_exist(f)
82
- $d1.remove!
78
+ dataset.remove!
83
79
  assert_path_exist(f)
84
- assert_equal($d1.name, File.read(f).chomp)
80
+ assert_equal(dataset.name, File.read(f).chomp)
85
81
  end
86
82
 
87
83
  def test_project_run_cmd
88
- f = File.expand_path('hook_pr_cmd', $tmp)
89
- $p1.add_hook(:on_save, :run_cmd, "echo {{project}} > '#{f}'")
84
+ f = tmpfile('hook_pr_cmd')
85
+ project.add_hook(:on_save, :run_cmd, "echo {{project}} > '#{f}'")
90
86
  assert_path_not_exist(f)
91
- $p1.save
87
+ project.save
92
88
  assert_path_exist(f)
93
- assert_equal($p1.path, File.read(f).chomp)
89
+ assert_equal(project.path, File.read(f).chomp)
94
90
  end
95
91
 
96
92
  def test_project_result_hooks
97
93
  $res = :test
98
94
  $counter = 1
99
- $p1.add_hook(
95
+ project.add_hook(
100
96
  :on_result_ready,
101
97
  :run_lambda,
102
98
  Proc.new { |r| $res = r }
103
99
  )
104
- $p1.add_hook(
100
+ project.add_hook(
105
101
  :on_result_ready_project_stats,
106
102
  :run_lambda,
107
103
  Proc.new { $counter += 1 }
108
104
  )
109
105
  %w[taxonomy.json metadata.db done].each do |ext|
110
- FileUtils.touch(File.expand_path(
111
- "data/90.stats/miga-project.#{ext}", $p1.path
112
- ))
106
+ FileUtils.touch(
107
+ File.join(project.path, 'data', '90.stats', "miga-project.#{ext}")
108
+ )
113
109
  end
114
- assert_equal(:project_stats, $p1.next_task(nil, false))
110
+ assert_equal(:project_stats, project.next_task(nil, false))
115
111
  assert_equal(:test, $res)
116
112
  assert_equal(1, $counter)
117
- assert_equal(:haai_distances, $p1.next_task)
113
+ assert_equal(:haai_distances, project.next_task)
118
114
  assert_equal(:project_stats, $res)
119
115
  assert_equal(2, $counter)
120
116
  end
121
-
122
117
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class JsonTest < Test::Unit::TestCase
4
-
5
4
  def test_parse
6
5
  assert_equal(
7
6
  { a: 1, b: 2 },
@@ -18,27 +17,27 @@ class JsonTest < Test::Unit::TestCase
18
17
  tmp1 = Tempfile.new('test-parse-1.json')
19
18
  tmp1.puts '{"a": 123, "k": false, "t": null}'
20
19
  tmp1.close
21
- assert_equal({a: 123, k: false, t: nil}, MiGA::Json.parse(tmp1.path))
20
+ assert_equal({ a: 123, k: false, t: nil }, MiGA::Json.parse(tmp1.path))
22
21
 
23
22
  tmp2 = Tempfile.new('test-parse-2.json')
24
23
  tmp2.puts '{"a": 456, "kb": false, "t": 10.0}'
25
24
  tmp2.close
26
- assert_equal({a: 456, kb: false, t: 10.0}, MiGA::Json.parse(tmp2.path))
25
+ assert_equal({ a: 456, kb: false, t: 10.0 }, MiGA::Json.parse(tmp2.path))
27
26
 
28
27
  assert_equal(
29
- {a: 123, k: false, kb: false, t: nil},
28
+ { a: 123, k: false, kb: false, t: nil },
30
29
  MiGA::Json.parse(tmp1.path, default: tmp2.path)
31
30
  )
32
31
  assert_equal(
33
- {a: 456, k: false, kb: false, t: 10.0},
32
+ { a: 456, k: false, kb: false, t: 10.0 },
34
33
  MiGA::Json.parse(tmp2.path, default: tmp1.path)
35
34
  )
36
35
  end
37
36
 
38
37
  def test_generate
39
- assert_equal("{\n \"a\": 1,\n \"b\": 2\n}",
40
- MiGA::Json.generate({a: 1, b: 2})
38
+ assert_equal(
39
+ "{\n \"a\": 1,\n \"b\": 2\n}",
40
+ MiGA::Json.generate({ a: 1, b: 2 })
41
41
  )
42
42
  end
43
-
44
43
  end