Skip to content

Commit

Permalink
Safer test for class vs string
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Van Dam committed Sep 14, 2023
1 parent 6c1a7d8 commit a75e6fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spidermon/contrib/scrapy/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_validators(loader, schema):
if type(schema) in (list, tuple):
schema = {Item: schema}
for obj, paths in schema.items():
key = obj if type(obj) in (str) else obj.__name__
key = obj.__name__ if hasattr(obj, "__name__") else str(obj)
paths = paths if type(paths) in (list, tuple) else [paths]
objects = [loader(v) for v in paths]
validators[key].extend(objects)
Expand Down
4 changes: 3 additions & 1 deletion tests/contrib/scrapy/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class PipelineJSONSchemaValidator(PipelineTest):
DataTest(
name="validators specified by str rather than class",
item=TreeItem(),
settings={SETTING_SCHEMAS: {"TestItem": test_schema, "TreeItem": tree_schema}},
settings={
SETTING_SCHEMAS: {"TestItem": test_schema, "TreeItem": tree_schema}
},
cases=[
f"{{stats}}['{STATS_MISSINGS}'] is 1",
assert_type_in_stats(TestItem),
Expand Down

0 comments on commit a75e6fb

Please sign in to comment.