miga-base 0.7.4.0 → 0.7.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/miga/cli.rb +10 -8
- data/lib/miga/cli/action.rb +2 -3
- data/lib/miga/cli/action/about.rb +5 -6
- data/lib/miga/cli/action/add.rb +18 -12
- data/lib/miga/cli/action/add_result.rb +2 -3
- data/lib/miga/cli/action/archive.rb +1 -2
- data/lib/miga/cli/action/classify_wf.rb +8 -6
- data/lib/miga/cli/action/console.rb +0 -1
- data/lib/miga/cli/action/daemon.rb +7 -7
- data/lib/miga/cli/action/date.rb +0 -1
- data/lib/miga/cli/action/derep_wf.rb +5 -4
- data/lib/miga/cli/action/doctor.rb +28 -20
- data/lib/miga/cli/action/doctor/base.rb +29 -6
- data/lib/miga/cli/action/edit.rb +1 -2
- data/lib/miga/cli/action/files.rb +8 -8
- data/lib/miga/cli/action/find.rb +5 -6
- data/lib/miga/cli/action/generic.rb +7 -7
- data/lib/miga/cli/action/get.rb +20 -17
- data/lib/miga/cli/action/get_db.rb +8 -2
- data/lib/miga/cli/action/index_wf.rb +1 -1
- data/lib/miga/cli/action/init.rb +34 -29
- data/lib/miga/cli/action/init/daemon_helper.rb +65 -43
- data/lib/miga/cli/action/lair.rb +7 -7
- data/lib/miga/cli/action/ln.rb +6 -6
- data/lib/miga/cli/action/ls.rb +1 -2
- data/lib/miga/cli/action/ncbi_get.rb +11 -3
- data/lib/miga/cli/action/new.rb +4 -4
- data/lib/miga/cli/action/next_step.rb +0 -1
- data/lib/miga/cli/action/preproc_wf.rb +3 -3
- data/lib/miga/cli/action/quality_wf.rb +1 -1
- data/lib/miga/cli/action/rm.rb +2 -3
- data/lib/miga/cli/action/run.rb +8 -8
- data/lib/miga/cli/action/stats.rb +3 -3
- data/lib/miga/cli/action/summary.rb +7 -6
- data/lib/miga/cli/action/tax_dist.rb +8 -4
- data/lib/miga/cli/action/tax_index.rb +3 -4
- data/lib/miga/cli/action/tax_set.rb +7 -6
- data/lib/miga/cli/action/tax_test.rb +6 -5
- data/lib/miga/cli/action/wf.rb +21 -19
- data/lib/miga/cli/base.rb +34 -32
- data/lib/miga/cli/objects_helper.rb +24 -17
- data/lib/miga/cli/opt_helper.rb +3 -2
- data/lib/miga/common.rb +2 -5
- data/lib/miga/common/base.rb +15 -16
- data/lib/miga/common/format.rb +8 -5
- data/lib/miga/common/hooks.rb +1 -4
- data/lib/miga/common/path.rb +4 -9
- data/lib/miga/common/with_daemon.rb +5 -2
- data/lib/miga/common/with_daemon_class.rb +1 -1
- data/lib/miga/common/with_result.rb +2 -1
- data/lib/miga/daemon.rb +51 -35
- data/lib/miga/daemon/base.rb +0 -2
- data/lib/miga/dataset.rb +47 -37
- data/lib/miga/dataset/base.rb +52 -37
- data/lib/miga/dataset/hooks.rb +3 -4
- data/lib/miga/dataset/result.rb +17 -1
- data/lib/miga/json.rb +5 -7
- data/lib/miga/lair.rb +4 -0
- data/lib/miga/metadata.rb +4 -3
- data/lib/miga/project.rb +29 -20
- data/lib/miga/project/base.rb +52 -37
- data/lib/miga/project/dataset.rb +27 -13
- data/lib/miga/project/hooks.rb +0 -3
- data/lib/miga/project/result.rb +14 -5
- data/lib/miga/remote_dataset.rb +85 -72
- data/lib/miga/remote_dataset/base.rb +11 -13
- data/lib/miga/remote_dataset/download.rb +33 -12
- data/lib/miga/result.rb +34 -25
- data/lib/miga/result/base.rb +0 -2
- data/lib/miga/result/dates.rb +1 -3
- data/lib/miga/result/source.rb +15 -16
- data/lib/miga/result/stats.rb +36 -25
- data/lib/miga/tax_dist.rb +6 -3
- data/lib/miga/tax_index.rb +17 -17
- data/lib/miga/taxonomy.rb +6 -1
- data/lib/miga/taxonomy/base.rb +19 -15
- data/lib/miga/version.rb +19 -16
- data/test/common_test.rb +3 -11
- data/test/daemon_helper.rb +38 -0
- data/test/daemon_test.rb +73 -101
- data/test/dataset_test.rb +58 -59
- data/test/format_test.rb +3 -11
- data/test/hook_test.rb +50 -55
- data/test/json_test.rb +7 -8
- data/test/lair_test.rb +22 -28
- data/test/metadata_test.rb +6 -14
- data/test/project_test.rb +33 -39
- data/test/remote_dataset_test.rb +20 -28
- data/test/result_stats_test.rb +17 -27
- data/test/result_test.rb +41 -34
- data/test/tax_dist_test.rb +0 -2
- data/test/tax_index_test.rb +4 -10
- data/test/taxonomy_test.rb +7 -9
- data/test/test_helper.rb +42 -1
- data/test/with_daemon_test.rb +14 -22
- data/utils/cleanup-databases.rb +6 -5
- data/utils/distance/base.rb +0 -1
- data/utils/distance/commands.rb +19 -12
- data/utils/distance/database.rb +24 -21
- data/utils/distance/pipeline.rb +12 -9
- data/utils/distance/runner.rb +14 -13
- data/utils/distance/temporal.rb +1 -3
- data/utils/distances.rb +1 -1
- data/utils/domain-ess-genes.rb +7 -7
- data/utils/index_metadata.rb +4 -2
- data/utils/mytaxa_scan.rb +18 -16
- data/utils/representatives.rb +5 -4
- data/utils/requirements.txt +1 -1
- data/utils/subclade/base.rb +0 -1
- data/utils/subclade/pipeline.rb +7 -6
- data/utils/subclade/runner.rb +9 -9
- data/utils/subclade/temporal.rb +0 -2
- data/utils/subclades-compile.rb +39 -37
- data/utils/subclades.rb +1 -1
- metadata +3 -2
data/test/dataset_test.rb
CHANGED
@@ -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
|
-
|
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?(
|
28
|
-
assert { !MiGA::Dataset.exist?(
|
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(
|
38
|
-
assert_equal(
|
39
|
-
assert_equal('
|
40
|
-
assert_predicate(
|
41
|
-
assert_equal(MiGA::Metadata,
|
42
|
-
assert_equal(:incomplete,
|
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 =
|
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 =
|
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(
|
59
|
+
assert_equal(dataset.name, dataset.info.first)
|
68
60
|
end
|
69
61
|
|
70
62
|
def test_add_result
|
71
|
-
d2 =
|
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.
|
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.
|
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 =
|
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(
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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 =
|
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(
|
123
|
-
|
124
|
-
)
|
125
|
-
Dir.mkdir(
|
126
|
-
|
127
|
-
)
|
128
|
-
FileUtils.touch(
|
129
|
-
|
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 =
|
137
|
-
Dir.mkdir(
|
138
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
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,
|
174
|
-
FileUtils.touch(
|
175
|
-
|
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 =
|
185
|
+
d = dataset
|
187
186
|
assert_equal(:incomplete, d.status)
|
188
187
|
assert_predicate(d, :active?)
|
189
188
|
d.inactivate!
|
data/test/format_test.rb
CHANGED
@@ -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 =
|
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
|
data/test/hook_test.rb
CHANGED
@@ -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
|
-
|
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(
|
22
|
-
|
23
|
-
assert_equal(1,
|
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
|
-
|
16
|
+
dataset.save
|
26
17
|
assert_equal(2, $counter)
|
27
18
|
end
|
28
19
|
|
29
20
|
def test_missing_action
|
30
|
-
|
31
|
-
assert_raise
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
FileUtils.touch(
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
assert_equal(1,
|
70
|
-
assert_equal('Boop',
|
71
|
-
|
72
|
-
|
73
|
-
assert_nil(
|
74
|
-
assert_nil(
|
75
|
-
assert_equal(1,
|
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 =
|
80
|
-
|
75
|
+
f = tmpfile('hook_ds_cmd')
|
76
|
+
dataset.metadata[:on_remove] = [[:run_cmd, "echo {{dataset}} > '#{f}'"]]
|
81
77
|
assert_path_not_exist(f)
|
82
|
-
|
78
|
+
dataset.remove!
|
83
79
|
assert_path_exist(f)
|
84
|
-
assert_equal(
|
80
|
+
assert_equal(dataset.name, File.read(f).chomp)
|
85
81
|
end
|
86
82
|
|
87
83
|
def test_project_run_cmd
|
88
|
-
f =
|
89
|
-
|
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
|
-
|
87
|
+
project.save
|
92
88
|
assert_path_exist(f)
|
93
|
-
assert_equal(
|
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
|
-
|
95
|
+
project.add_hook(
|
100
96
|
:on_result_ready,
|
101
97
|
:run_lambda,
|
102
98
|
Proc.new { |r| $res = r }
|
103
99
|
)
|
104
|
-
|
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(
|
111
|
-
|
112
|
-
)
|
106
|
+
FileUtils.touch(
|
107
|
+
File.join(project.path, 'data', '90.stats', "miga-project.#{ext}")
|
108
|
+
)
|
113
109
|
end
|
114
|
-
assert_equal(:project_stats,
|
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,
|
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
|
data/test/json_test.rb
CHANGED
@@ -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(
|
40
|
-
|
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
|
data/test/lair_test.rb
CHANGED
@@ -2,31 +2,26 @@ require 'test_helper'
|
|
2
2
|
require 'miga/lair'
|
3
3
|
|
4
4
|
class LairTest < Test::Unit::TestCase
|
5
|
+
include TestHelper
|
5
6
|
|
6
7
|
def setup
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
"var":"{{key}}={{value}}","cmd":"echo {{task_name}} >/dev/null",
|
15
|
-
"alive":"echo 1 # {{pid}}","type":"bash","format_version":1}'
|
16
|
-
end
|
17
|
-
Dir.mkdir(File.join($tmp, 'sub'))
|
18
|
-
$p1 = MiGA::Project.new(File.join($tmp, 'project1'))
|
19
|
-
$p2 = MiGA::Project.new(File.join($tmp, 'project2'))
|
20
|
-
$p3 = MiGA::Project.new(File.join($tmp, 'sub/project3'))
|
21
|
-
end
|
8
|
+
initialize_miga_home(
|
9
|
+
<<~DAEMON
|
10
|
+
{ "maxjobs": 1, "ppn": 1, "latency": 1, "varsep": " ",
|
11
|
+
"var": "{{key}}={{value}}", "cmd": "echo {{task_name}} >/dev/null",
|
12
|
+
"alive": "echo 1 # {{pid}}", "type": "bash", "format_version": 1 }
|
13
|
+
DAEMON
|
14
|
+
)
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
# Make sure projects already exist
|
17
|
+
Dir.mkdir(tmpfile('sub'))
|
18
|
+
project(1)
|
19
|
+
project(2)
|
20
|
+
project('sub/project3')
|
26
21
|
end
|
27
|
-
|
22
|
+
|
28
23
|
def test_lair_init
|
29
|
-
path =
|
24
|
+
path = tmpdir
|
30
25
|
lair = MiGA::Lair.new(path, name: 'Alt-X')
|
31
26
|
assert_equal(MiGA::Lair, lair.class)
|
32
27
|
assert_equal(path, lair.path)
|
@@ -36,9 +31,8 @@ class LairTest < Test::Unit::TestCase
|
|
36
31
|
end
|
37
32
|
|
38
33
|
def test_in_loop
|
39
|
-
|
40
|
-
lair = MiGA::Lair.new(
|
41
|
-
omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
|
34
|
+
declare_forks
|
35
|
+
lair = MiGA::Lair.new(tmpdir, name: 'Oh')
|
42
36
|
child = lair.start(['--shush'])
|
43
37
|
assert_not_nil(child)
|
44
38
|
assert_gt(child, 0, 'The daemon process should have non-zero PID')
|
@@ -53,13 +47,13 @@ class LairTest < Test::Unit::TestCase
|
|
53
47
|
end
|
54
48
|
|
55
49
|
def test_first_loop
|
56
|
-
lair = MiGA::Lair.new(
|
50
|
+
lair = MiGA::Lair.new(tmpdir, name: 'Ew')
|
57
51
|
out = capture_stderr { lair.daemon_first_loop }.string
|
58
52
|
assert_match(/-{20}/, out)
|
59
53
|
end
|
60
54
|
|
61
55
|
def test_loop
|
62
|
-
lair = MiGA::Lair.new(
|
56
|
+
lair = MiGA::Lair.new(tmpdir, name: 'Ew', latency: 1, dry: true)
|
63
57
|
out = capture_stderr { assert { !lair.daemon_loop } }.string
|
64
58
|
assert_match(/Launching daemon: \S*project1/, out)
|
65
59
|
assert_match(/Launching daemon: \S*project2/, out)
|
@@ -67,13 +61,13 @@ class LairTest < Test::Unit::TestCase
|
|
67
61
|
end
|
68
62
|
|
69
63
|
def test_daemon_launch
|
70
|
-
lair = MiGA::Lair.new(
|
64
|
+
lair = MiGA::Lair.new(tmpfile('sub'), latency: 1)
|
71
65
|
p = MiGA::Project.load(File.join(lair.path, 'project3'))
|
72
66
|
d = MiGA::Daemon.new(p)
|
73
67
|
assert_not_predicate(d, :active?)
|
74
68
|
assert_path_exist(d.daemon_home)
|
75
69
|
|
76
|
-
|
70
|
+
declare_forks
|
77
71
|
capture_stdout do
|
78
72
|
FileUtils.touch(d.output_file) # <- To prevent test racing
|
79
73
|
out = capture_stderr { lair.check_directories }.string
|
@@ -92,7 +86,7 @@ class LairTest < Test::Unit::TestCase
|
|
92
86
|
end
|
93
87
|
|
94
88
|
def test_each_project
|
95
|
-
lair = MiGA::Lair.new(
|
89
|
+
lair = MiGA::Lair.new(tmpdir)
|
96
90
|
y = []
|
97
91
|
lair.each_project { |p| y << p }
|
98
92
|
assert_equal(3, y.size)
|