Skip to content

Commit ebebca4

Browse files
author
notactuallyfinn
committed
added first tests
1 parent 248ae33 commit ebebca4

3 files changed

Lines changed: 106 additions & 3 deletions

File tree

src/hermes/commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
# from hermes.commands.init.base import HermesInitCommand
1515
# from hermes.commands.curate.base import HermesCurateCommand
1616
from hermes.commands.harvest.base import HermesHarvestCommand
17-
# from hermes.commands.process.base import HermesProcessCommand
17+
from hermes.commands.process.base import HermesProcessCommand
1818
from hermes.commands.deposit.base import HermesDepositCommand
1919
# from hermes.commands.postprocess.base import HermesPostprocessCommand

src/hermes/commands/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# from hermes.commands import (HermesHelpCommand, HermesVersionCommand, HermesCleanCommand,
1717
# HermesHarvestCommand, HermesProcessCommand, HermesCurateCommand,
1818
# HermesDepositCommand, HermesPostprocessCommand, HermesInitCommand)
19-
from hermes.commands import HermesDepositCommand, HermesHarvestCommand
19+
from hermes.commands import HermesDepositCommand, HermesHarvestCommand, HermesProcessCommand
2020
from hermes.commands.base import HermesCommand
2121

2222

@@ -43,7 +43,7 @@ def main() -> None:
4343
# HermesInitCommand(parser),
4444
# HermesCleanCommand(parser),
4545
HermesHarvestCommand(parser),
46-
# HermesProcessCommand(parser),
46+
HermesProcessCommand(parser),
4747
# HermesCurateCommand(parser),
4848
HermesDepositCommand(parser),
4949
# HermesPostprocessCommand(parser),

test/hermes_test/model/test_api_e2e.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,106 @@ def test_invenio_deposit(tmp_path, monkeypatch, sandbox_auth, metadata, invenio_
475475

476476
# TODO: compare to actually expected value
477477
assert result == invenio_metadata
478+
479+
480+
@pytest.mark.parametrize(
481+
"metadata_in, metadata_out",
482+
[
483+
(
484+
{
485+
"cff": SoftwareMetadata({
486+
"@type": ["http://schema.org/SoftwareSourceCode"],
487+
"http://schema.org/description": [{"@value": "for testing"}],
488+
"http://schema.org/name": [{"@value": "Test"}],
489+
"http://schema.org/author": [{
490+
"@type": "http://schema.org/Person",
491+
"http://schema.org/familyName": [{"@value": "Test"}],
492+
"http://schema.org/givenName": [{"@value": "Testi"}]
493+
}],
494+
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}]
495+
})
496+
},
497+
SoftwareMetadata({
498+
"@type": ["http://schema.org/SoftwareSourceCode"],
499+
"http://schema.org/description": [{"@value": "for testing"}],
500+
"http://schema.org/name": [{"@value": "Test"}],
501+
"http://schema.org/author": [{
502+
"@type": "http://schema.org/Person",
503+
"http://schema.org/familyName": [{"@value": "Test"}],
504+
"http://schema.org/givenName": [{"@value": "Testi"}]
505+
}],
506+
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}]
507+
})
508+
),
509+
(
510+
{
511+
"cff": SoftwareMetadata({
512+
"@type": ["http://schema.org/SoftwareSourceCode"],
513+
"http://schema.org/name": [{"@value": "Test"}],
514+
"http://schema.org/author": [{
515+
"@type": "http://schema.org/Person",
516+
"http://schema.org/familyName": [{"@value": "Test"}],
517+
"http://schema.org/givenName": [{"@value": "Testi"}],
518+
"http://schema.org/email": [{"@value": "test.testi@testis.tests"}]
519+
}],
520+
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}]
521+
}),
522+
"codemeta": SoftwareMetadata({
523+
"@type": ["http://schema.org/SoftwareSourceCode"],
524+
"http://schema.org/description": [{"@value": "for testing"}],
525+
"http://schema.org/name": [{"@value": "Test"}],
526+
"http://schema.org/author": [{
527+
"@type": "http://schema.org/Person",
528+
"http://schema.org/familyName": [{"@value": "Test"}],
529+
"http://schema.org/givenName": [{"@value": "Testi"}],
530+
"http://schema.org/email": [{"@value": "test.testi@testis.tests"}]
531+
}]
532+
})
533+
},
534+
SoftwareMetadata({
535+
"@type": ["http://schema.org/SoftwareSourceCode"],
536+
"http://schema.org/description": [{"@value": "for testing"}],
537+
"http://schema.org/name": [{"@value": "Test"}],
538+
"http://schema.org/author": [{
539+
"@type": "http://schema.org/Person",
540+
"http://schema.org/familyName": [{"@value": "Test"}],
541+
"http://schema.org/givenName": [{"@value": "Testi"}],
542+
"http://schema.org/email": [{"@value": "test.testi@testis.tests"}]
543+
}],
544+
"http://schema.org/license": [{"@id": "https://spdx.org/licenses/Apache-2.0"}]
545+
})
546+
)
547+
]
548+
)
549+
def test_process(tmp_path, monkeypatch, metadata_in, metadata_out):
550+
monkeypatch.chdir(tmp_path)
551+
552+
manager = context_manager.HermesContext(tmp_path)
553+
manager.prepare_step("harvest")
554+
for harvester, result in metadata_in.items():
555+
with manager[harvester] as cache:
556+
cache["codemeta"] = result.compact()
557+
cache["context"] = {"@context": result.full_context}
558+
cache["expanded"] = result.ld_value
559+
manager.finalize_step("harvest")
560+
561+
config_file = tmp_path / "hermes.toml"
562+
config_file.write_text(f"[harvest]\nsources = [{", ".join(f"\"{harvester}\"" for harvester in metadata_in)}]")
563+
564+
orig_argv = sys.argv[:]
565+
sys.argv = ["hermes", "process", "--path", str(tmp_path), "--config", str(config_file)]
566+
result = {}
567+
try:
568+
monkeypatch.setattr(context_manager.HermesContext.__init__, "__defaults__", (tmp_path.cwd(),))
569+
cli.main()
570+
except SystemExit as e:
571+
if e.code != 0:
572+
raise e
573+
finally:
574+
manager.prepare_step("process")
575+
result = SoftwareMetadata.load_from_cache(manager, "result")
576+
manager.finalize_step("process")
577+
sys.argv = orig_argv
578+
579+
assert result.ld_value == metadata_out.ld_value
580+
assert result == metadata_out

0 commit comments

Comments
 (0)