ro-crate 0.4.11 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +5 -0
  3. data/.ruby-version +1 -1
  4. data/Gemfile.lock +7 -7
  5. data/README.md +2 -0
  6. data/lib/ro_crate/json_ld_hash.rb +5 -0
  7. data/lib/ro_crate/model/crate.rb +53 -6
  8. data/lib/ro_crate/model/data_entity.rb +20 -7
  9. data/lib/ro_crate/model/directory.rb +5 -5
  10. data/lib/ro_crate/model/entity.rb +43 -4
  11. data/lib/ro_crate/model/entry.rb +2 -2
  12. data/lib/ro_crate/model/file.rb +6 -2
  13. data/lib/ro_crate/model/remote_entry.rb +2 -13
  14. data/lib/ro_crate/reader.rb +11 -8
  15. data/lib/ro_crate/writer.rb +4 -4
  16. data/lib/ro_crate.rb +1 -1
  17. data/ro_crate.gemspec +2 -2
  18. data/test/crate_test.rb +74 -3
  19. data/test/directory_test.rb +21 -21
  20. data/test/entity_test.rb +117 -3
  21. data/test/fixtures/biobb_hpc_workflows-condapack.zip +0 -0
  22. data/test/fixtures/conflicting_data_directory/info.txt +1 -0
  23. data/test/fixtures/conflicting_data_directory/nested.txt +1 -0
  24. data/test/fixtures/misc_data_entity_crate/ro-crate-metadata.json +33 -0
  25. data/test/fixtures/ro-crate-galaxy-sortchangecase/ro-crate-metadata.json +10 -3
  26. data/test/fixtures/unlinked_entity_crate/LICENSE +176 -0
  27. data/test/fixtures/unlinked_entity_crate/README.md +2 -0
  28. data/test/fixtures/unlinked_entity_crate/ro-crate-metadata.json +150 -0
  29. data/test/fixtures/unlinked_entity_crate/sort-and-change-case.ga +118 -0
  30. data/test/fixtures/unlinked_entity_crate/test/test1/input.bed +3 -0
  31. data/test/fixtures/unlinked_entity_crate/test/test1/output_exp.bed +3 -0
  32. data/test/fixtures/unlinked_entity_crate/test/test1/sort-and-change-case-test.yml +8 -0
  33. data/test/fixtures/workflow-0.2.0/ro-crate-metadata.jsonld +5 -5
  34. data/test/fixtures/workflow-0.2.0.zip +0 -0
  35. data/test/reader_test.rb +86 -58
  36. data/test/test_helper.rb +5 -1
  37. data/test/writer_test.rb +48 -0
  38. metadata +24 -7
@@ -0,0 +1,118 @@
1
+ {
2
+ "uuid": "e2a8566c-c025-4181-9e90-7ed29d4e4df1",
3
+ "tags": [],
4
+ "format-version": "0.1",
5
+ "name": "sort-and-change-case",
6
+ "version": 0,
7
+ "steps": {
8
+ "0": {
9
+ "tool_id": null,
10
+ "tool_version": null,
11
+ "outputs": [],
12
+ "workflow_outputs": [],
13
+ "input_connections": {},
14
+ "tool_state": "{}",
15
+ "id": 0,
16
+ "uuid": "5a36fad2-66c7-4b9e-8759-0fbcae9b8541",
17
+ "errors": null,
18
+ "name": "Input dataset",
19
+ "label": "bed_input",
20
+ "inputs": [],
21
+ "position": {
22
+ "top": 200,
23
+ "left": 200
24
+ },
25
+ "annotation": "",
26
+ "content_id": null,
27
+ "type": "data_input"
28
+ },
29
+ "1": {
30
+ "tool_id": "sort1",
31
+ "tool_version": "1.1.0",
32
+ "outputs": [
33
+ {
34
+ "type": "input",
35
+ "name": "out_file1"
36
+ }
37
+ ],
38
+ "workflow_outputs": [
39
+ {
40
+ "output_name": "out_file1",
41
+ "uuid": "8237f71a-bc2a-494e-a63c-09c1e65ef7c8",
42
+ "label": "sorted_bed"
43
+ }
44
+ ],
45
+ "input_connections": {
46
+ "input": {
47
+ "output_name": "output",
48
+ "id": 0
49
+ }
50
+ },
51
+ "tool_state": "{\"__page__\": null, \"style\": \"\\\"alpha\\\"\", \"column\": \"\\\"1\\\"\", \"__rerun_remap_job_id__\": null, \"column_set\": \"[]\", \"input\": \"{\\\"__class__\\\": \\\"RuntimeValue\\\"}\", \"header_lines\": \"\\\"0\\\"\", \"order\": \"\\\"ASC\\\"\"}",
52
+ "id": 1,
53
+ "uuid": "0b6b3cda-c75f-452b-85b1-8ae4f3302ba4",
54
+ "errors": null,
55
+ "name": "Sort",
56
+ "post_job_actions": {},
57
+ "label": "sort",
58
+ "inputs": [
59
+ {
60
+ "name": "input",
61
+ "description": "runtime parameter for tool Sort"
62
+ }
63
+ ],
64
+ "position": {
65
+ "top": 200,
66
+ "left": 420
67
+ },
68
+ "annotation": "",
69
+ "content_id": "sort1",
70
+ "type": "tool"
71
+ },
72
+ "2": {
73
+ "tool_id": "ChangeCase",
74
+ "tool_version": "1.0.0",
75
+ "outputs": [
76
+ {
77
+ "type": "tabular",
78
+ "name": "out_file1"
79
+ }
80
+ ],
81
+ "workflow_outputs": [
82
+ {
83
+ "output_name": "out_file1",
84
+ "uuid": "c31cd733-dab6-4d50-9fec-b644d162397b",
85
+ "label": "uppercase_bed"
86
+ }
87
+ ],
88
+ "input_connections": {
89
+ "input": {
90
+ "output_name": "out_file1",
91
+ "id": 1
92
+ }
93
+ },
94
+ "tool_state": "{\"__page__\": null, \"casing\": \"\\\"up\\\"\", \"__rerun_remap_job_id__\": null, \"cols\": \"\\\"c1\\\"\", \"delimiter\": \"\\\"TAB\\\"\", \"input\": \"{\\\"__class__\\\": \\\"RuntimeValue\\\"}\"}",
95
+ "id": 2,
96
+ "uuid": "9698bcde-0729-48fe-b88d-ccfb6f6153b4",
97
+ "errors": null,
98
+ "name": "Change Case",
99
+ "post_job_actions": {},
100
+ "label": "change_case",
101
+ "inputs": [
102
+ {
103
+ "name": "input",
104
+ "description": "runtime parameter for tool Change Case"
105
+ }
106
+ ],
107
+ "position": {
108
+ "top": 200,
109
+ "left": 640
110
+ },
111
+ "annotation": "",
112
+ "content_id": "ChangeCase",
113
+ "type": "tool"
114
+ }
115
+ },
116
+ "annotation": "",
117
+ "a_galaxy_workflow": "true"
118
+ }
@@ -0,0 +1,3 @@
1
+ chr1 66999824 67210768
2
+ chr7 48998526 50489626
3
+ chr1 66874821 66010368
@@ -0,0 +1,3 @@
1
+ CHR1 66874821 66010368
2
+ CHR1 66999824 67210768
3
+ CHR7 48998526 50489626
@@ -0,0 +1,8 @@
1
+ - doc: test with a small input
2
+ job:
3
+ bed_input:
4
+ class: File
5
+ path: input.bed
6
+ outputs:
7
+ uppercase_bed:
8
+ path: output_exp.bed
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "@id": "workflow/workflow.knime",
126
- "@type": "SoftwareSourceCode",
126
+ "@type": ["File", "SoftwareSourceCode"],
127
127
  "additionalType": {
128
128
  "@id": "wfdesc:Workflow"
129
129
  },
@@ -161,7 +161,7 @@
161
161
  },
162
162
  {
163
163
  "@id": "tools/RetroPath2.cwl",
164
- "@type": "SoftwareSourceCode",
164
+ "@type": ["File", "SoftwareSourceCode"],
165
165
  "additionalType": {
166
166
  "@id": "wfdesc:Workflow"
167
167
  },
@@ -188,7 +188,7 @@
188
188
  },
189
189
  {
190
190
  "@id": "workflow/workflow.svg",
191
- "@type": "ImageObject",
191
+ "@type": ["File", "ImageObject"],
192
192
  "additionalType": {"@id": "roterms:Sketch"},
193
193
  "encodingFormat": "image/svg+xml",
194
194
  "description": "Diagram of RetroPath2.0 workflow",
@@ -201,7 +201,7 @@
201
201
  },
202
202
  {
203
203
  "@id": "Dockerfile",
204
- "@type": "SoftwareSourceCode",
204
+ "@type": ["File", "SoftwareSourceCode"],
205
205
  "url": {
206
206
  "@id": "https://hub.docker.com/r/ibisba/retropath2/"
207
207
  },
@@ -220,7 +220,7 @@
220
220
  },
221
221
  {
222
222
  "@id": "test/test.sh",
223
- "@type": "SoftwareSourceCode",
223
+ "@type": ["File", "SoftwareSourceCode"],
224
224
  "additionalType": {
225
225
  "@id": "wf4ever:Script"
226
226
  },
Binary file
data/test/reader_test.rb CHANGED
@@ -4,12 +4,13 @@ class ReaderTest < Test::Unit::TestCase
4
4
  test 'reading from directory' do
5
5
  crate = ROCrate::Reader.read(fixture_file('workflow-0.2.0').path)
6
6
 
7
- refute crate.dereference('.ssh/id_rsa')
7
+ refute crate.dereference('~/.ssh/id_rsa')
8
8
 
9
9
  entity = crate.dereference('workflow/workflow.knime')
10
10
  assert_not_nil entity
11
11
  assert entity.is_a?(ROCrate::File)
12
- assert_equal 'SoftwareSourceCode', entity.type
12
+ assert entity.has_type?('SoftwareSourceCode')
13
+ assert entity.has_type?('File')
13
14
 
14
15
  entity = crate.dereference('workflow/')
15
16
  assert_not_nil entity
@@ -19,22 +20,26 @@ class ReaderTest < Test::Unit::TestCase
19
20
  entity = crate.dereference('tools/RetroPath2.cwl')
20
21
  assert_not_nil entity
21
22
  assert entity.is_a?(ROCrate::File)
22
- assert_equal 'SoftwareSourceCode', entity.type
23
+ assert entity.has_type?('SoftwareSourceCode')
24
+ assert entity.has_type?('File')
23
25
 
24
26
  entity = crate.dereference('workflow/workflow.svg')
25
27
  assert_not_nil entity
26
28
  assert entity.is_a?(ROCrate::File)
27
- assert_equal 'ImageObject', entity.type
29
+ assert entity.has_type?('ImageObject')
30
+ assert entity.has_type?('File')
28
31
 
29
32
  entity = crate.dereference('Dockerfile')
30
33
  assert_not_nil entity
31
34
  assert entity.is_a?(ROCrate::File)
32
- assert_equal 'SoftwareSourceCode', entity.type
35
+ assert entity.has_type?('SoftwareSourceCode')
36
+ assert entity.has_type?('File')
33
37
 
34
38
  entity = crate.dereference('test/test.sh')
35
39
  assert_not_nil entity
36
40
  assert entity.is_a?(ROCrate::File)
37
- assert_equal 'SoftwareSourceCode', entity.type
41
+ assert entity.has_type?('SoftwareSourceCode')
42
+ assert entity.has_type?('File')
38
43
 
39
44
  # Example is broken
40
45
  # entity = crate.dereference('README.md')
@@ -46,12 +51,13 @@ class ReaderTest < Test::Unit::TestCase
46
51
  test 'reading from zip' do
47
52
  crate = ROCrate::Reader.read(fixture_file('workflow-0.2.0.zip'))
48
53
 
49
- refute crate.dereference('.ssh/id_rsa')
54
+ refute crate.dereference('~/.ssh/id_rsa')
50
55
 
51
56
  entity = crate.dereference('workflow/workflow.knime')
52
57
  assert_not_nil entity
53
58
  assert entity.is_a?(ROCrate::File)
54
- assert_equal 'SoftwareSourceCode', entity.type
59
+ assert entity.has_type?('SoftwareSourceCode')
60
+ assert entity.has_type?('File')
55
61
 
56
62
  entity = crate.dereference('workflow/')
57
63
  assert_not_nil entity
@@ -61,22 +67,26 @@ class ReaderTest < Test::Unit::TestCase
61
67
  entity = crate.dereference('tools/RetroPath2.cwl')
62
68
  assert_not_nil entity
63
69
  assert entity.is_a?(ROCrate::File)
64
- assert_equal 'SoftwareSourceCode', entity.type
70
+ assert entity.has_type?('SoftwareSourceCode')
71
+ assert entity.has_type?('File')
65
72
 
66
73
  entity = crate.dereference('workflow/workflow.svg')
67
74
  assert_not_nil entity
68
75
  assert entity.is_a?(ROCrate::File)
69
- assert_equal 'ImageObject', entity.type
76
+ assert entity.has_type?('ImageObject')
77
+ assert entity.has_type?('File')
70
78
 
71
79
  entity = crate.dereference('Dockerfile')
72
80
  assert_not_nil entity
73
81
  assert entity.is_a?(ROCrate::File)
74
- assert_equal 'SoftwareSourceCode', entity.type
82
+ assert entity.has_type?('SoftwareSourceCode')
83
+ assert entity.has_type?('File')
75
84
 
76
85
  entity = crate.dereference('test/test.sh')
77
86
  assert_not_nil entity
78
87
  assert entity.is_a?(ROCrate::File)
79
- assert_equal 'SoftwareSourceCode', entity.type
88
+ assert entity.has_type?('SoftwareSourceCode')
89
+ assert entity.has_type?('File')
80
90
 
81
91
  # Example is broken
82
92
  # entity = crate.dereference('README.md')
@@ -88,12 +98,12 @@ class ReaderTest < Test::Unit::TestCase
88
98
  test 'reading from zip with directories' do
89
99
  crate = ROCrate::Reader.read_zip(fixture_file('directory.zip'))
90
100
 
91
- assert crate.entries['fish/info.txt']
92
- assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
93
- assert crate.entries['fish/root.txt']
94
- assert crate.entries['fish/data/info.txt']
95
- assert crate.entries['fish/data/nested.txt']
96
- assert crate.entries['fish/data/binary.jpg']
101
+ assert crate.payload['fish/info.txt']
102
+ assert_equal '1234', crate.payload['fish/info.txt'].source.read.chomp
103
+ assert crate.payload['fish/root.txt']
104
+ assert crate.payload['fish/data/info.txt']
105
+ assert crate.payload['fish/data/nested.txt']
106
+ assert crate.payload['fish/data/binary.jpg']
97
107
  assert_equal ['./', 'fish/', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
98
108
  end
99
109
 
@@ -101,22 +111,22 @@ class ReaderTest < Test::Unit::TestCase
101
111
  Dir.mktmpdir('test-1234-banana') do |dir|
102
112
  crate = ROCrate::Reader.read_zip(fixture_file('directory.zip'), target_dir: dir)
103
113
 
104
- assert crate.entries['fish/info.txt']
105
- assert crate.entries['fish/info.txt'].source.to_s.include?('/test-1234-banana')
114
+ assert crate.payload['fish/info.txt']
115
+ assert crate.payload['fish/info.txt'].source.to_s.include?('/test-1234-banana')
106
116
  end
107
117
  end
108
118
 
109
119
  test 'reading from directory with directories' do
110
120
  crate = ROCrate::Reader.read_directory(fixture_file('directory_crate').path)
111
121
 
112
- assert crate.entries.values.all? { |e| e.is_a?(ROCrate::Entry) }
113
- assert crate.entries['fish/info.txt']
114
- assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
115
- refute crate.entries['fish/root.txt'].directory?
116
- assert crate.entries['fish/data'].directory?
117
- assert crate.entries['fish/data/info.txt']
118
- refute crate.entries['fish/data/nested.txt'].remote?
119
- assert crate.entries['fish/data/binary.jpg']
122
+ assert crate.payload.values.all? { |e| e.is_a?(ROCrate::Entry) }
123
+ assert crate.payload['fish/info.txt']
124
+ assert_equal '1234', crate.payload['fish/info.txt'].source.read.chomp
125
+ refute crate.payload['fish/root.txt'].directory?
126
+ assert crate.payload['fish/data'].directory?
127
+ assert crate.payload['fish/data/info.txt']
128
+ refute crate.payload['fish/data/nested.txt'].remote?
129
+ assert crate.payload['fish/data/binary.jpg']
120
130
  assert_equal ['./', 'fish/', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
121
131
  end
122
132
 
@@ -162,37 +172,38 @@ class ReaderTest < Test::Unit::TestCase
162
172
  assert ext_file.source.is_a?(ROCrate::RemoteEntry)
163
173
  assert_equal 'http://example.com/external_ref.txt', ext_file.id
164
174
  assert_equal 'file contents', ext_file.source.read
175
+ assert crate.preview.source.source.is_a?(ROCrate::PreviewGenerator)
165
176
  end
166
177
 
167
178
  test 'reading from directory with unlisted files' do
168
179
  crate = ROCrate::Reader.read_directory(fixture_file('sparse_directory_crate').path)
169
180
 
170
- assert_equal 11, crate.entries.count
171
- assert crate.entries['listed_file.txt']
172
- assert crate.entries['unlisted_file.txt']
173
- assert crate.entries['fish']
174
- assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
175
- refute crate.entries['fish/root.txt'].directory?
176
- assert crate.entries['fish/data'].directory?
177
- assert crate.entries['fish/data/info.txt']
178
- refute crate.entries['fish/data/nested.txt'].remote?
179
- assert crate.entries['fish/data/binary.jpg']
181
+ assert_equal 11, crate.payload.count
182
+ assert crate.payload['listed_file.txt']
183
+ assert crate.payload['unlisted_file.txt']
184
+ assert crate.payload['fish']
185
+ assert_equal '1234', crate.payload['fish/info.txt'].source.read.chomp
186
+ refute crate.payload['fish/root.txt'].directory?
187
+ assert crate.payload['fish/data'].directory?
188
+ assert crate.payload['fish/data/info.txt']
189
+ refute crate.payload['fish/data/nested.txt'].remote?
190
+ assert crate.payload['fish/data/binary.jpg']
180
191
  assert_equal ['./', 'listed_file.txt', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
181
192
  end
182
193
 
183
194
  test 'reading from a zip with unlisted files' do
184
195
  crate = ROCrate::Reader.read_zip(fixture_file('sparse_directory_crate.zip').path)
185
196
 
186
- assert_equal 11, crate.entries.count
187
- assert crate.entries['listed_file.txt']
188
- assert crate.entries['unlisted_file.txt']
189
- assert crate.entries['fish']
190
- assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
191
- refute crate.entries['fish/root.txt'].directory?
192
- assert crate.entries['fish/data'].directory?
193
- assert crate.entries['fish/data/info.txt']
194
- refute crate.entries['fish/data/nested.txt'].remote?
195
- assert crate.entries['fish/data/binary.jpg']
197
+ assert_equal 11, crate.payload.count
198
+ assert crate.payload['listed_file.txt']
199
+ assert crate.payload['unlisted_file.txt']
200
+ assert crate.payload['fish']
201
+ assert_equal '1234', crate.payload['fish/info.txt'].source.read.chomp
202
+ refute crate.payload['fish/root.txt'].directory?
203
+ assert crate.payload['fish/data'].directory?
204
+ assert crate.payload['fish/data/info.txt']
205
+ refute crate.payload['fish/data/nested.txt'].remote?
206
+ assert crate.payload['fish/data/binary.jpg']
196
207
  assert_equal ['./', 'listed_file.txt', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
197
208
  end
198
209
 
@@ -201,30 +212,30 @@ class ReaderTest < Test::Unit::TestCase
201
212
  string_io.write(::File.read(fixture_file('sparse_directory_crate.zip').path))
202
213
  string_io.rewind
203
214
  assert string_io.is_a?(StringIO)
204
- assert_equal 11, ROCrate::Reader.read_zip(string_io).entries.count
215
+ assert_equal 11, ROCrate::Reader.read_zip(string_io).payload.count
205
216
 
206
217
  path = Pathname.new(fixture_file('sparse_directory_crate.zip').path)
207
218
  assert path.is_a?(Pathname)
208
- assert_equal 11, ROCrate::Reader.read_zip(path).entries.count
219
+ assert_equal 11, ROCrate::Reader.read_zip(path).payload.count
209
220
 
210
221
  file = ::File.open(fixture_file('sparse_directory_crate.zip').path)
211
222
  assert file.is_a?(::File)
212
- assert_equal 11, ROCrate::Reader.read_zip(file).entries.count
223
+ assert_equal 11, ROCrate::Reader.read_zip(file).payload.count
213
224
 
214
225
  string = fixture_file('sparse_directory_crate.zip').path
215
226
  assert string.is_a?(String)
216
- assert_equal 11, ROCrate::Reader.read_zip(string).entries.count
227
+ assert_equal 11, ROCrate::Reader.read_zip(string).payload.count
217
228
  end
218
229
 
219
230
  test 'reading from zip where the crate root is nested somewhere within' do
220
231
  crate = ROCrate::Reader.read_zip(fixture_file('nested_directory.zip'))
221
232
 
222
- assert crate.entries['fish/info.txt']
223
- assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
224
- assert crate.entries['fish/root.txt']
225
- assert crate.entries['fish/data/info.txt']
226
- assert crate.entries['fish/data/nested.txt']
227
- assert crate.entries['fish/data/binary.jpg']
233
+ assert crate.payload['fish/info.txt']
234
+ assert_equal '1234', crate.payload['fish/info.txt'].source.read.chomp
235
+ assert crate.payload['fish/root.txt']
236
+ assert crate.payload['fish/data/info.txt']
237
+ assert crate.payload['fish/data/nested.txt']
238
+ assert crate.payload['fish/data/binary.jpg']
228
239
  assert_equal ['./', 'fish/', 'ro-crate-metadata.json', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
229
240
  end
230
241
 
@@ -251,4 +262,21 @@ class ReaderTest < Test::Unit::TestCase
251
262
  }
252
263
  ], context
253
264
  end
265
+
266
+ test 'existing preview is used even if not mentioned in metadata' do
267
+ crate = ROCrate::Reader.read_zip(fixture_file('biobb_hpc_workflows-condapack.zip').path)
268
+ assert crate.preview.source.source.is_a?(Pathname)
269
+ assert_equal 80526, crate.preview.source.read.length
270
+ end
271
+
272
+ test 'read crate with data entity that is neither file or directory' do
273
+ crate = ROCrate::Reader.read_directory(fixture_file('misc_data_entity_crate').path)
274
+
275
+ entity = crate.get('#collection')
276
+ assert entity.is_a?(ROCrate::DataEntity)
277
+ refute entity.is_a?(ROCrate::File)
278
+ refute entity.is_a?(ROCrate::Directory)
279
+ assert entity.has_type?('RepositoryCollection')
280
+ assert entity.payload.empty?
281
+ end
254
282
  end
data/test/test_helper.rb CHANGED
@@ -6,5 +6,9 @@ require 'ro_crate'
6
6
  require 'webmock/test_unit'
7
7
 
8
8
  def fixture_file(name, *args)
9
- ::File.open(::File.join(::File.dirname(__FILE__), 'fixtures', name), *args)
9
+ ::File.open(::File.join(fixture_dir, name), *args)
10
+ end
11
+
12
+ def fixture_dir
13
+ ::File.join(::File.dirname(__FILE__), 'fixtures')
10
14
  end
data/test/writer_test.rb CHANGED
@@ -47,8 +47,12 @@ class WriterTest < Test::Unit::TestCase
47
47
  end
48
48
 
49
49
  test 'writing to zip' do
50
+ # Remote entries should not be written, so this 500 error should not affect anything.
51
+ stub_request(:get, 'http://example.com/external_ref.txt').to_return(status: 500)
52
+
50
53
  crate = ROCrate::Crate.new
51
54
  crate.add_file(fixture_file('info.txt'))
55
+ crate.add_file('http://example.com/external_ref.txt')
52
56
  crate.add_file(fixture_file('data.csv'), 'directory/data.csv')
53
57
 
54
58
  Tempfile.create do |file|
@@ -57,6 +61,7 @@ class WriterTest < Test::Unit::TestCase
57
61
  Zip::File.open(file) do |zipfile|
58
62
  assert zipfile.file.exist?(ROCrate::Metadata::IDENTIFIER)
59
63
  assert zipfile.file.exist?(ROCrate::Preview::IDENTIFIER)
64
+ refute zipfile.file.exist?('external_ref.txt')
60
65
  assert_equal 6, zipfile.file.size('info.txt')
61
66
  assert_equal 20, zipfile.file.size('directory/data.csv')
62
67
  end
@@ -152,4 +157,47 @@ class WriterTest < Test::Unit::TestCase
152
157
  end
153
158
  end
154
159
  end
160
+
161
+ test 'writing with conflicting paths in payload obeys specificity rules' do
162
+ crate = ROCrate::Crate.new
163
+
164
+ # Payload from crate
165
+ crate.add_all(fixture_file('directory').path, false)
166
+ Dir.mktmpdir do |dir|
167
+ ROCrate::Writer.new(crate).write(dir)
168
+
169
+ assert_equal "5678\n", ::File.read(::File.join(dir, 'data', 'info.txt'))
170
+ end
171
+
172
+ # Payload from crate + directory
173
+ crate.add_directory(fixture_file('conflicting_data_directory').path.to_s, 'data')
174
+ Dir.mktmpdir do |dir|
175
+ ROCrate::Writer.new(crate).write(dir)
176
+
177
+ assert_equal 'abcd', ::File.read(::File.join(dir, 'data', 'info.txt')), 'Directory payload should take priority over Crate.'
178
+ assert_equal "No, I am nested!\n", ::File.read(::File.join(dir, 'data', 'nested.txt')), 'Directory payload should take priority over Crate.'
179
+ assert ::File.exist?(::File.join(dir, 'data', 'binary.jpg'))
180
+ end
181
+
182
+ # Payload from crate + directory + file
183
+ crate.add_file(StringIO.new('xyz'), 'data/info.txt')
184
+ Dir.mktmpdir do |dir|
185
+ ROCrate::Writer.new(crate).write(dir)
186
+
187
+ assert_equal 'xyz', ::File.read(::File.join(dir, 'data', 'info.txt')), 'File payload should take priority over Crate and Directory.'
188
+ assert_equal "No, I am nested!\n", ::File.read(::File.join(dir, 'data', 'nested.txt')), 'Directory payload should take priority over Crate.'
189
+ assert ::File.exist?(::File.join(dir, 'data', 'binary.jpg'))
190
+ end
191
+ end
192
+
193
+ test 'write crate with data entity that is neither file or directory' do
194
+ crate = ROCrate::Reader.read_directory(fixture_file('misc_data_entity_crate').path)
195
+ Dir.mktmpdir do |dir|
196
+ ROCrate::Writer.new(crate).write(dir)
197
+ Dir.chdir(dir) do
198
+ file_list = Dir.glob('*').sort
199
+ assert_equal ["ro-crate-metadata.json", "ro-crate-preview.html"], file_list
200
+ end
201
+ end
202
+ end
155
203
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ro-crate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn Bacall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 2.7.0
22
+ version: '2.9'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.7'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 2.7.0
32
+ version: '2.9'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rubyzip
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +152,9 @@ files:
146
152
  - test/crate_test.rb
147
153
  - test/directory_test.rb
148
154
  - test/entity_test.rb
155
+ - test/fixtures/biobb_hpc_workflows-condapack.zip
156
+ - test/fixtures/conflicting_data_directory/info.txt
157
+ - test/fixtures/conflicting_data_directory/nested.txt
149
158
  - test/fixtures/crate-spec1.1/file with spaces.txt
150
159
  - test/fixtures/crate-spec1.1/ro-crate-metadata.json
151
160
  - test/fixtures/data.csv
@@ -166,6 +175,7 @@ files:
166
175
  - test/fixtures/directory_crate/ro-crate-preview.html
167
176
  - test/fixtures/file with spaces.txt
168
177
  - test/fixtures/info.txt
178
+ - test/fixtures/misc_data_entity_crate/ro-crate-metadata.json
169
179
  - test/fixtures/nested_directory.zip
170
180
  - test/fixtures/ro-crate-galaxy-sortchangecase/LICENSE
171
181
  - test/fixtures/ro-crate-galaxy-sortchangecase/README.md
@@ -186,6 +196,13 @@ files:
186
196
  - test/fixtures/sparse_directory_crate/ro-crate-metadata.jsonld
187
197
  - test/fixtures/sparse_directory_crate/ro-crate-preview.html
188
198
  - test/fixtures/sparse_directory_crate/unlisted_file.txt
199
+ - test/fixtures/unlinked_entity_crate/LICENSE
200
+ - test/fixtures/unlinked_entity_crate/README.md
201
+ - test/fixtures/unlinked_entity_crate/ro-crate-metadata.json
202
+ - test/fixtures/unlinked_entity_crate/sort-and-change-case.ga
203
+ - test/fixtures/unlinked_entity_crate/test/test1/input.bed
204
+ - test/fixtures/unlinked_entity_crate/test/test1/output_exp.bed
205
+ - test/fixtures/unlinked_entity_crate/test/test1/sort-and-change-case-test.yml
189
206
  - test/fixtures/workflow-0.2.0.zip
190
207
  - test/fixtures/workflow-0.2.0/Dockerfile
191
208
  - test/fixtures/workflow-0.2.0/README.md
@@ -2433,7 +2450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2433
2450
  - !ruby/object:Gem::Version
2434
2451
  version: '0'
2435
2452
  requirements: []
2436
- rubygems_version: 3.0.8
2453
+ rubygems_version: 3.1.6
2437
2454
  signing_key:
2438
2455
  specification_version: 4
2439
2456
  summary: Create, manipulate, read RO-Crates.