Skip to content

Commit

Permalink
Merge pull request #117 from SteffenBrinckmann/sb_repairPytests
Browse files Browse the repository at this point in the history
Repair github actions
  • Loading branch information
SteffenBrinckmann authored Feb 5, 2025
2 parents 3196fc2 + 08e31cb commit d1245ea
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest rocrate jsonschema roc-validator
pip install -r tests/requirements.txt
- name: Test with pytest
run: |
pytest --tb=short -s
continue-on-error: true
- name: Create action summary
run: |
cat tests/logging.md >> $GITHUB_STEP_SUMMARY
if: always()
4 changes: 4 additions & 0 deletions tests/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jsonschema
pytest
rocrate
roc-validator
46 changes: 46 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
arcp==0.2.1
attrs==25.1.0
cattrs==24.1.2
certifi==2025.1.31
charset-normalizer==3.4.1
click==8.1.8
colorlog==6.9.0
enum-tools==0.12.0
html5lib==1.1
idna==3.10
iniconfig==2.0.0
inquirerpy==0.3.4
Jinja2==3.1.5
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdurl==0.1.2
owlrl==6.0.2
packaging==24.2
pfzy==0.3.4
platformdirs==4.3.6
pluggy==1.5.0
prettytable==3.14.0
prompt_toolkit==3.0.50
Pygments==2.19.1
pyparsing==3.2.1
pyshacl==0.26.0
pytest==8.3.4
python-dateutil==2.9.0.post0
rdflib==7.1.3
referencing==0.36.2
requests==2.32.3
requests-cache==1.2.1
rich==13.9.4
rich-click==1.8.5
roc-validator==0.5.0
rocrate==0.13.0
rpds-py==0.22.3
six==1.17.0
toml==0.10.2
typing_extensions==4.12.2
url-normalize==1.4.3
urllib3==2.3.0
wcwidth==0.2.13
webencodings==0.5.1
2 changes: 1 addition & 1 deletion tests/test_00_pypi_rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_main(self):
if not name.endswith('.eln'):
continue
fileName = os.path.join(root, name)
print(f'\n\nTry to parse: {fileName}')
print(f'\n\nTest 00: {fileName}')
with ZipFile(fileName, 'r', compression=ZIP_DEFLATED) as elnFile:
dirName = os.path.splitext(os.path.basename(fileName))[0]
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_01_params_metadata_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def processNode(graph, nodeID):
if not name.endswith('.eln'):
continue
fileName = os.path.join(root, name)
print(f'\n\nParse: {fileName}')
print(f'\n\nTest 01: {fileName}')
with ZipFile(fileName, 'r', compression=ZIP_DEFLATED) as elnFile:
success = True
metadataJsonFile = [i for i in elnFile.namelist() if i.endswith(METADATA_FILE)][0]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_02_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_main(self):
if not name.endswith('.eln'):
continue
fileName = os.path.join(root, name)
print(f'\nInspect: {name}')
print(f'\nTest 02: {name}')
with ZipFile(fileName, 'r', compression=ZIP_DEFLATED) as elnFile:
metadataJsonFile = [i for i in elnFile.namelist() if i.endswith(METADATA_FILE)][0]
metadataContent = json.loads(elnFile.read(metadataJsonFile))
Expand Down
34 changes: 16 additions & 18 deletions tests/test_03_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
"""
import os
import json
import logging
import tempfile
import unittest
from pathlib import Path
from zipfile import ZIP_DEFLATED
from zipfile import ZipFile
import rocrate_validator
from rocrate_validator.errors import ValidationError
import rocrate_validator.services as rvs
from rocrate_validator import services, models

LABEL = 'validator'
METADATA_FILE = 'ro-crate-metadata.json'
Expand All @@ -26,6 +25,7 @@ def test_main(self):
main function
"""
# log-file
logging.getLogger('rdflib').setLevel(logging.ERROR) # get rid of verbose rdflib warnings, we concentrate on validator directly
if Path('tests/logging.json').exists():
logJson = json.load(open('tests/logging.json'))
else:
Expand All @@ -36,30 +36,28 @@ def test_main(self):
if not name.endswith('.eln'):
continue
fileName = os.path.join(root, name)
print(f'\n\nTry to parse: {fileName}')
print(f'\n\nTest 03: {fileName}')
with ZipFile(fileName, 'r', compression=ZIP_DEFLATED) as elnFile:
dirpath = Path(tempfile.mkdtemp())/Path(fileName).parent.name
dirpath.mkdir(parents=True, exist_ok=True)
elnFile.extractall(dirpath)
rocrate_dir= [i for i in dirpath.iterdir() if i.is_dir()][0]
result = rvs.validate({
"profiles_path": rocrate_validator.utils.get_profiles_path(),
"profile_identifier": "ro-crate",
"requirement_severity": rocrate_validator.models.Severity.REQUIRED.name,
"requirement_severity_only": False,
"inherit_profiles": True,
"verbose": True,
"data_path": rocrate_dir,
"ontology_path": None,
"abort_on_first": False
})
result_dict = result.to_dict()
if result_dict['issues'] == [] and result_dict['passed']:

# start validation
settings = services.ValidationSettings(
rocrate_uri=rocrate_dir,
profile_identifier='ro-crate-1.1',
requirement_severity=models.Severity.REQUIRED,
)
result = services.validate(settings)
if not result.has_issues():
success = True
else:
print(f'{fileName} is not valid')
print(result_dict)
for issue in result.get_issues():
print(f"Detected issue of severity {issue.severity.name} with check \"{issue.check.identifier}\": {issue.message}")
success = False

logJson[fileName] = logJson.get(fileName,{}) | {LABEL: success}
json.dump(logJson, open('tests/logging.json', 'w'))
assert success
2 changes: 1 addition & 1 deletion tests/test_99_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_main(self):
individualFileName = Path(filename).parts[2]
if len(individualFileName)>30:
individualFileName=individualFileName[:24]+'...eln'
resultStr = ' | '.join([':white_check_mark:' if result[col] else ':x:' for col in COLUMNS])
resultStr = ' | '.join([':white_check_mark:' if col in result and result[col] else ':x:' for col in COLUMNS])
output.write(f'| {software} | {individualFileName} | {resultStr} |\n')
output.write("\n\nDefinition of tests\n")
output.write("- **pypi_rocrate**: tests if eln-file can be opened by pypi's rocrate; if eln file can be easily opened by that library.\n")
Expand Down

0 comments on commit d1245ea

Please sign in to comment.