Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions glom/test/test_regressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

def test_frictionless_compat():
'''
This was a subtle one involving the frictionless library.
https://github.com/mahmoud/glom/issues/233
'''
class Schema(dict):
'''minimal stand-in for frictionless.Schema'''
def __getattr__(self, name):
if name in self:
return [self[name]]
return []

from glom import glom, Assign

fields = [
{"name": "id", "type": "number"},
{"name": "foo", "type": "datetime"},
{"name": "bar", "type": "string"},
{"name": "baz", "type": "boolean"},
]
schema = Schema(fields=fields, missing_values="NA")

# access
assert schema.primary_key == []
assert glom(schema, "primary_key") == [] # fails with KeyError

# expected
try:
assert schema["primaryKey"]
except KeyError:
pass

# expected
try:
assert glom(schema, "primaryKey")
except KeyError:
pass

# assign
glom(schema, Assign("primary_key", "foo"))
assert schema.primary_key == ["foo"]
assert schema["primaryKey"] == "foo"

glom(schema, Assign("primaryKey", "id")) # fails with AttributeError
assert schema["primaryKey"] == "id"