Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #384 from biolink/issue_381
Browse files Browse the repository at this point in the history
Issue 381
  • Loading branch information
hsolbrig authored Feb 26, 2021
2 parents 8ace358 + e510ce1 commit 087d029
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 17 deletions.
6 changes: 6 additions & 0 deletions biolinkml/generators/rdfgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import os
import urllib.parse as urlparse
from typing import Union, TextIO, Optional

import click
Expand Down Expand Up @@ -32,7 +33,12 @@ def _data(self, g: Graph) -> str:
def end_schema(self, output: Optional[str] = None, context: str = METAMODEL_CONTEXT_URI, **_) -> None:
gen = JSONLDGenerator(self, fmt=JSONLDGenerator.valid_formats[0], emit_metadata=self.emit_metadata,
importmap=self.importmap)
# Iterate over permissible text strings making them URI compatible
for e in gen.schema.enums.values():
for pv in e.permissible_values.values():
pv.text = urlparse.quote(pv.text)
jsonld_str = gen.serialize(context=context)

graph = Graph()
graph.parse(data=jsonld_str, format="json-ld", base=self.namespaces._base, prefix=True)
if output:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_issues/test_issue_167.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def test_issue_167b_python(self):
""" Annotations python example """
env.generate_single_file('issue_167b.py',
lambda: PythonGenerator(env.input_path('issue_167b.yaml'),
importmap=env.import_map).serialize(),
importmap=env.import_map, emit_metadata=False).serialize(),
comparator=lambda exp, act: compare_python(exp, act, self.env.expected_path('issue_167b.py')),
value_is_returned=True)
env.generate_single_file('issue_167b.py',
env.generate_single_file('issue_167b2.py',
lambda: PythonGenerator(env.input_path('issue_167b.yaml'),
importmap=env.import_map, mergeimports=False).serialize(),
importmap=env.import_map, mergeimports=False, emit_metadata=False).serialize(),
comparator=lambda exp, act: compare_python(exp, act, self.env.expected_path('issue_167b_nomerged.py')),
value_is_returned=True)

Expand Down
7 changes: 4 additions & 3 deletions tests/test_issues/test_issue_344.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
from tests.test_issues.environment import env


class Issue167TestCase(TestEnvironmentTestCase):
class Issue344TestCase(TestEnvironmentTestCase):
env = env

def test_issue_344(self):
""" Test to check if prefixes of CURIEs from granular mappings show up in the json-ld context """
x = env.generate_single_file('issue_344_context.json',
lambda: ContextGenerator(env.input_path('issue_344.yaml'),
importmap=env.import_map).serialize(), value_is_returned=True)
context = json.load(open(os.path.join(env.outdir, 'issue_344_context.json')))
importmap=env.import_map, emit_metadata=False).serialize(), value_is_returned=True)
with open(os.path.join(env.outdir, 'issue_344_context.json')) as f:
context = json.load(f)
self.assertIn('PCO', context['@context'])
self.assertIn('PATO', context['@context'])
self.assertIn('GO', context['@context'])
Expand Down
32 changes: 32 additions & 0 deletions tests/test_issues/test_issue_381.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest

from rdflib import Graph, Namespace

from biolinkml.generators.jsonldgen import JSONLDGenerator
from biolinkml.generators.rdfgen import RDFGenerator
from biolinkml.meta import META
from tests.utils.test_environment import TestEnvironmentTestCase
from tests.test_issues.environment import env

NS = Namespace('https://example.org/test/')

schema = f'''id: {NS}
enums:
test_enum:
permissible_values:
a b:
'''


class Issue381TestCase(TestEnvironmentTestCase):
""" Test URL generation w/ non-mangled values """
env = env

def test_non_url_pv(self):
g = Graph()
g.parse(data=RDFGenerator(schema).serialize(), format="ttl")
self.assertEqual('https://example.org/test/a%20b', str(g.value(NS.test_enum, META.permissible_values)))


if __name__ == '__main__':
unittest.main()
Binary file modified tests/test_scripts/output/gengraphviz/meta/alt_description.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions tests/test_scripts/output/gengraphviz/meta1/alt_description.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/test_scripts/output/gengraphviz/meta1/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/test_scripts/output/gengraphviz/meta1/local_name.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/test_scripts/output/gengraphviz/meta1/prefix.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 087d029

Please sign in to comment.