Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tetron authored and mr-c committed Jun 24, 2021
1 parent 21a01a8 commit debbc11
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion mypy_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mypy==0.910
types-pkg_resources
types-requests
pytest
2 changes: 1 addition & 1 deletion schema_salad/codegen_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def prologue(self) -> None:
@staticmethod
def safe_name(name: str) -> str:
"""Generate a safe version of the given name."""
return schema.avro_name(name)
return schema.avro_field_name(name)

def begin_class(
self, # pylint: disable=too-many-arguments
Expand Down
2 changes: 1 addition & 1 deletion schema_salad/java_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def prologue(self) -> None:

@staticmethod
def property_name(name: str) -> str:
avn = schema.avro_name(name)
avn = schema.avro_field_name(name)
return avn

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions schema_salad/makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def typefmt(
"https://w3id.org/cwl/salad#record",
"https://w3id.org/cwl/salad#enum",
):
frg = schema.avro_name(tp["name"])
frg = schema.avro_type_name(tp["name"])
if tp["name"] in redirects:
return """<a href="{}">{}</a>""".format(redirects[tp["name"]], frg)
if tp["name"] in self.typemap:
Expand All @@ -325,7 +325,7 @@ def typefmt(
and len(tp["symbols"]) == 1
):
return "constant value <code>{}</code>".format(
schema.avro_name(tp["symbols"][0])
schema.avro_field_name(tp["symbols"][0])
)
return frg
if isinstance(tp["type"], MutableMapping):
Expand All @@ -335,7 +335,7 @@ def typefmt(
return """<a href="{}">{}</a>""".format(redirects[tp], redirects[tp])
if str(tp) in basicTypes:
return """<a href="{}">{}</a>""".format(
self.primitiveType, schema.avro_name(str(tp))
self.primitiveType, schema.avro_type_name(str(tp))
)
frg2 = urldefrag(tp)[1]
if frg2 != "":
Expand Down Expand Up @@ -443,7 +443,7 @@ def extendsfrom(item: Dict[str, Any], ex: List[Dict[str, Any]]) -> None:

desc = i["doc"]

rfrg = schema.avro_name(i["name"])
rfrg = schema.avro_field_name(i["name"])
tr = """
<div class="row responsive-table-row">
<div class="col-xs-3 col-lg-2"><code>{}</code></div>
Expand Down Expand Up @@ -472,7 +472,7 @@ def extendsfrom(item: Dict[str, Any], ex: List[Dict[str, Any]]) -> None:
for e in ex:
for i in e.get("symbols", []):
doc += "<tr>"
efrg = schema.avro_name(i)
efrg = schema.avro_field_name(i)
doc += "<td><code>{}</code></td><td>{}</td>".format(
efrg, enumDesc.get(efrg, "")
)
Expand Down
10 changes: 6 additions & 4 deletions schema_salad/python_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pkg_resources import resource_stream

from . import schema
from . import schema, validate
from .codegen_base import CodeGenBase, TypeDef
from .exceptions import SchemaException
from .schema import shortname
Expand Down Expand Up @@ -56,7 +56,9 @@ def __init__(self, out: IO[str], copyright: Optional[str]) -> None:

@staticmethod
def safe_name(name): # type: (str) -> str
avn = schema.avro_name(name)
avn = schema.avro_field_name(name)
if avn.startswith("anon."):
avn = avn[5:]
if avn in ("class", "in"):
# reserved words
avn = avn + "_"
Expand Down Expand Up @@ -498,8 +500,8 @@ def typedsl_loader(self, inner, ref_scope):
# type: (TypeDef, Union[int, None]) -> TypeDef
return self.declare_type(
TypeDef(
f"typedsl_{inner.name}_{ref_scope}",
f"_TypeDSLLoader({inner.name}, {ref_scope})",
f"typedsl_{self.safe_name(inner.name)}_{ref_scope}",
f"_TypeDSLLoader({self.safe_name(inner.name)}, {ref_scope})",
)
)

Expand Down
4 changes: 2 additions & 2 deletions schema_salad/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ def validate_doc(
except ClassValidationException as exc1:
errors = [
ClassValidationException(
f"tried `{name}` but", sourceline, [exc1]
f"tried `{validate.friendly(name)}` but", sourceline, [exc1]
)
]
break
except ValidationException as exc2:
errors.append(
ValidationException(f"tried `{name}` but", sourceline, [exc2])
ValidationException(f"tried `{validate.friendly(name)}` but", sourceline, [exc2])
)

objerr = "Invalid"
Expand Down
10 changes: 6 additions & 4 deletions schema_salad/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ def validate(
LONG_MIN_VALUE = -(1 << 63)
LONG_MAX_VALUE = (1 << 63) - 1

def avro_shortname(name: str) -> str:
return name.split(".")[-1]

def friendly(v): # type: (Any) -> Any
if isinstance(v, avro.schema.NamedSchema):
return v.name
return avro_shortname(v.name)
if isinstance(v, avro.schema.ArraySchema):
return "array of <{}>".format(friendly(v.items))
elif isinstance(v, avro.schema.PrimitiveSchema):
return v.type
elif isinstance(v, avro.schema.UnionSchema):
return " or ".join([friendly(s) for s in v.schemas])
else:
return v
return avro_shortname(v)


def vpformat(datum): # type: (Any) -> str
Expand Down Expand Up @@ -139,7 +141,7 @@ def validate_ex(
"value is a {} but expected a string".format(type(datum).__name__)
)
return False
if expected_schema.name == "Expression":
if expected_schema.name == "w3id.org.cwl.cwl.Expression":
if "$(" in datum or "${" in datum:
return True
if raise_ex:
Expand Down Expand Up @@ -279,7 +281,7 @@ def validate_ex(
raise ValidationException(f"Missing '{f.name}' field")
else:
return False
if expected_schema.name != d:
if avro_shortname(expected_schema.name) != d:
if raise_ex:
raise ValidationException(
"Expected class '{}' but this is '{}'".format(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

setup(
name="schema-salad",
version="7.1", # update the VERSION prefix in the Makefile as well 🙂
version="8.0", # update the VERSION prefix in the Makefile as well 🙂
description="Schema Annotations for Linked Avro Data (SALAD)",
long_description=open(README).read(),
long_description_content_type="text/x-rst",
Expand Down

0 comments on commit debbc11

Please sign in to comment.