Skip to content

Commit

Permalink
[tools/RDFWriter] Exclude all subclass whitespace
Browse files Browse the repository at this point in the history
In hommage to the unknown DAU all whitespaces are excluded
from the custom RDF subclasses dict.
  • Loading branch information
mpsonntag committed Jul 16, 2020
1 parent ce5f196 commit 20add13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions odml/tools/rdf_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import string
import uuid
import warnings

Expand Down Expand Up @@ -338,9 +339,10 @@ def _parse_custom_subclasses(self, custom_subclasses):
otherwise.
"""

# Do not allow whitespaces in values
if " " in "".join(custom_subclasses.values()):
msg = "Custom RDF Subclass names must not contain any whitespaces."
# Do not allow any whitespace characters in values
vals = "".join(custom_subclasses.values()).encode()
if vals != vals.translate(None, string.whitespace.encode()):
msg = "Custom RDF Subclass names must not contain any whitespace characters."
raise ValueError(msg)

for k in custom_subclasses:
Expand Down
6 changes: 5 additions & 1 deletion test/test_rdf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ def test_rdf_custom_subclasses(self):
self.assertIn("odml:Cell", rdf_writer.get_rdf_str())

# Test value whitespace
invalid_dict = {"type_1": "Class 1", "type_2": "Class 2"}
inval_a = "This should"
inval_b = "fail\nin"
inval_c = "the\tmost"
inval_d = "complete\rway"
invalid_dict = {"type_1": inval_a, "type_2": inval_b, "type_3": inval_c, "type_4": inval_d}
with self.assertRaises(ValueError):
_ = RDFWriter([doc], custom_subclasses=invalid_dict)

Expand Down

0 comments on commit 20add13

Please # to comment.