Skip to content

Commit 7bf5116

Browse files
authored
Merge pull request #204 from simleo/dont_auto_add_hash
Do not auto-preprend a hash to contextual entity ids
2 parents 619ba5e + 90fb470 commit 7bf5116

File tree

7 files changed

+20
-63
lines changed

7 files changed

+20
-63
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ Now the workflow has a type of `["File", "SoftwareSourceCode", "ComputationalWor
404404
To add [workflow testing metadata](https://crs4.github.io/life_monitor/workflow_testing_ro_crate) to the crate:
405405

406406
```bash
407-
rocrate add test-suite -i test1
408-
rocrate add test-instance test1 http://example.com -r jobs -i test1_1
409-
rocrate add test-definition test1 test/test1/sort-and-change-case-test.yml -e planemo -v '>=0.70'
407+
rocrate add test-suite -i '#test1'
408+
rocrate add test-instance '#test1' http://example.com -r jobs -i '#test1_1'
409+
rocrate add test-definition '#test1' test/test1/sort-and-change-case-test.yml -e planemo -v '>=0.70'
410410
```
411411

412412
To add files or directories after crate initialization:

rocrate/cli.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from .model.computerlanguage import LANG_MAP
2626
from .model.testservice import SERVICE_MAP
2727
from .model.softwareapplication import APP_MAP
28-
from .model.contextentity import add_hash
2928

3029

3130
LANG_CHOICES = list(LANG_MAP)
@@ -175,7 +174,7 @@ def workflow(crate_dir, path, language, property):
175174
def suite(crate_dir, identifier, name, main_entity, property):
176175
crate = ROCrate(crate_dir, init=False, gen_preview=False)
177176
suite = crate.add_test_suite(
178-
identifier=add_hash(identifier),
177+
identifier=identifier,
179178
name=name,
180179
main_entity=main_entity,
181180
properties=dict(property),
@@ -196,11 +195,11 @@ def suite(crate_dir, identifier, name, main_entity, property):
196195
def instance(crate_dir, suite, url, resource, service, identifier, name, property):
197196
crate = ROCrate(crate_dir, init=False, gen_preview=False)
198197
instance_ = crate.add_test_instance(
199-
add_hash(suite),
198+
suite,
200199
url,
201200
resource=resource,
202201
service=service,
203-
identifier=add_hash(identifier),
202+
identifier=identifier,
204203
name=name,
205204
properties=dict(property),
206205
)
@@ -224,7 +223,7 @@ def definition(crate_dir, suite, path, engine, engine_version, property):
224223
# For now, only support marking an existing file as a test definition
225224
raise ValueError(f"{source} is not in the crate dir {crate_dir}")
226225
crate.add_test_definition(
227-
add_hash(suite),
226+
suite,
228227
source=source,
229228
dest_path=dest_path,
230229
engine=engine,

rocrate/model/contextentity.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,8 @@
1919
# See the License for the specific language governing permissions and
2020
# limitations under the License.
2121

22-
from ..utils import is_url
2322
from .entity import Entity
2423

2524

26-
def add_hash(id_):
27-
if id_ is None or "#" in id_ or is_url(id_):
28-
return id_
29-
return "#" + id_
30-
31-
3225
class ContextEntity(Entity):
33-
34-
def __init__(self, crate, identifier=None, properties=None):
35-
super(ContextEntity, self).__init__(crate, identifier, properties)
36-
37-
def format_id(self, identifier):
38-
return add_hash(identifier)
26+
pass

test/test_cli.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ def test_cli_add_test_metadata(test_data_dir, helpers, monkeypatch, cwd):
279279
assert set(TESTING_EXTRA_TERMS.items()).issubset(extra_terms.items())
280280

281281

282-
@pytest.mark.parametrize("hash_", [False, True])
283-
def test_cli_add_test_metadata_explicit_ids(test_data_dir, helpers, monkeypatch, hash_):
282+
def test_cli_add_test_metadata_explicit_ids(test_data_dir, helpers, monkeypatch):
284283
# init
285284
crate_dir = test_data_dir / "ro-crate-galaxy-sortchangecase"
286285
runner = CliRunner()
@@ -290,17 +289,15 @@ def test_cli_add_test_metadata_explicit_ids(test_data_dir, helpers, monkeypatch,
290289
assert runner.invoke(cli, ["add", "workflow", "-c", str(crate_dir), "-l", "galaxy", str(wf_path)]).exit_code == 0
291290
# add test suite
292291
suite_id = "#foo"
293-
cli_suite_id = suite_id if hash_ else suite_id[1:]
294-
result = runner.invoke(cli, ["add", "test-suite", "-c", str(crate_dir), "-i", cli_suite_id])
292+
result = runner.invoke(cli, ["add", "test-suite", "-c", str(crate_dir), "-i", suite_id])
295293
assert result.exit_code == 0
296294
assert result.output.strip() == suite_id
297295
json_entities = helpers.read_json_entities(crate_dir)
298296
assert suite_id in json_entities
299297
# add test instance
300298
instance_id = "#bar"
301-
cli_instance_id = instance_id if hash_ else instance_id[1:]
302299
args = [
303-
"add", "test-instance", cli_suite_id, "http://example.com", "-c", str(crate_dir), "-r", "jobs", "-i", cli_instance_id
300+
"add", "test-instance", suite_id, "http://example.com", "-c", str(crate_dir), "-r", "jobs", "-i", instance_id
304301
]
305302
result = runner.invoke(cli, args)
306303
assert result.exit_code == 0
@@ -310,7 +307,7 @@ def test_cli_add_test_metadata_explicit_ids(test_data_dir, helpers, monkeypatch,
310307
# add test definition
311308
def_id = "test/test1/sort-and-change-case-test.yml"
312309
def_path = crate_dir / def_id
313-
args = ["add", "test-definition", "-c", str(crate_dir), "-e", "planemo", "-v", ">=0.70", cli_suite_id, str(def_path)]
310+
args = ["add", "test-definition", "-c", str(crate_dir), "-e", "planemo", "-v", ">=0.70", suite_id, str(def_path)]
314311
result = runner.invoke(cli, args)
315312
assert result.exit_code == 0
316313
json_entities = helpers.read_json_entities(crate_dir)

test/test_model.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -155,32 +155,6 @@ def test_contextual_entities():
155155
assert person_dereference is new_person
156156

157157

158-
def test_contextual_entities_hash(test_data_dir):
159-
crate = ROCrate()
160-
john = crate.add(Person(crate, "john", properties={"name": "John Doe"}))
161-
assert john.id == "#john"
162-
id_ = "https://orcid.org/0000-0002-1825-0097"
163-
josiah = crate.add(Person(crate, id_, properties={"name": "Josiah Carberry"}))
164-
assert josiah.id == id_
165-
wf_path = test_data_dir / "ro-crate-galaxy-sortchangecase" / "sort-and-change-case.ga"
166-
wf_dest_path = wf_path.name
167-
wf = crate.add_workflow(wf_path, wf_dest_path, main=True, lang="galaxy")
168-
step_id = f"{wf_dest_path}#sort"
169-
step = crate.add(ContextEntity(crate, step_id, properties={
170-
"@type": "HowToStep",
171-
}))
172-
wf["hasPart"] = [step]
173-
assert step.id == step_id
174-
175-
email_uri = f"mailto:{email}"
176-
contact_point = crate.add(ContextEntity(crate, email_uri, properties={
177-
"@type": "ContactPoint",
178-
"email": email
179-
}))
180-
crate.root_dataset["contactPoint"] = contact_point
181-
assert contact_point.id == email_uri
182-
183-
184158
def test_properties():
185159
crate = ROCrate()
186160

test/test_test_metadata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,20 @@ def test_add_test_suite(test_data_dir):
159159
assert s1["mainEntity"] is wf
160160
suites.add(s1)
161161
assert suites == set(crate.test_suites)
162-
s2 = crate.add_test_suite(identifier="test1")
162+
s2 = crate.add_test_suite(identifier="#test1")
163163
assert s2["mainEntity"] is wf
164164
assert s2.id == "#test1"
165165
suites.add(s2)
166166
assert suites == set(crate.test_suites)
167-
s3 = crate.add_test_suite(identifier="test2", name="Test 2")
167+
s3 = crate.add_test_suite(identifier="#test2", name="Test 2")
168168
assert s3["mainEntity"] is wf
169169
assert s3.id == "#test2"
170170
assert s3.name == "Test 2"
171171
suites.add(s3)
172172
assert suites == set(crate.test_suites)
173173
wf2_path = top_dir / "README.md"
174174
wf2 = crate.add(ComputationalWorkflow(crate, wf2_path, wf2_path.name))
175-
s4 = crate.add_test_suite(identifier="test3", name="Foo", main_entity=wf2)
175+
s4 = crate.add_test_suite(identifier="#test3", name="Foo", main_entity=wf2)
176176
assert s4["mainEntity"] is wf2
177177
assert s4.id == "#test3"
178178
assert s4.name == "Foo"
@@ -215,7 +215,7 @@ def test_add_test_instance(test_data_dir):
215215
assert i4.service is crate.dereference(TRAVIS)
216216
instances.add(i4)
217217
assert instances == set(suite.instance)
218-
i5 = crate.add_test_instance(suite, "http://example.com", identifier="test_1_1")
218+
i5 = crate.add_test_instance(suite, "http://example.com", identifier="#test_1_1")
219219
assert i5.url == "http://example.com"
220220
assert i5.id == "#test_1_1"
221221
instances.add(i5)

test/test_write.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_file_writing(test_data_dir, tmpdir, helpers, gen_preview, to_zip):
3636
crate = ROCrate(gen_preview=gen_preview)
3737
crate_name = 'Test crate'
3838
crate.name = crate_name
39-
creator_id = '001'
39+
creator_id = '#001'
4040
creator_name = 'Lee Ritenour'
4141
new_person = Person(crate, creator_id, {'name': creator_name})
4242
crate.add(new_person)
@@ -93,10 +93,9 @@ def test_file_writing(test_data_dir, tmpdir, helpers, gen_preview, to_zip):
9393
root = json_entities["./"]
9494
assert root["name"] == crate_name
9595
assert "datePublished" in root
96-
formatted_creator_id = f"#{creator_id}"
97-
assert root["creator"] == {"@id": formatted_creator_id}
98-
assert formatted_creator_id in json_entities
99-
assert json_entities[formatted_creator_id]["name"] == creator_name
96+
assert root["creator"] == {"@id": creator_id}
97+
assert creator_id in json_entities
98+
assert json_entities[creator_id]["name"] == creator_name
10099
if gen_preview:
101100
assert helpers.PREVIEW_FILE_NAME in json_entities
102101
file_entity = json_entities[sample_file_id]

0 commit comments

Comments
 (0)