-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reformatting, cleanup, and coverage #193
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,13 @@ | |
|
||
import pytest | ||
|
||
from glom import glom, SKIP, STOP, Path, Inspect, Coalesce, CoalesceError, Val, Call, T, S, Invoke, Spec, Ref | ||
from glom import Auto, Fill, Iter, A, Vars, Val, Literal, GlomError, Pipe | ||
from glom import glom, SKIP, STOP, Inspect, Coalesce, Val, Call, T, S, Invoke, Spec, Ref | ||
from glom import Fill, Iter, Literal, Pipe | ||
|
||
import glom.core as glom_core | ||
from glom.core import UP, ROOT, bbformat, bbrepr | ||
from glom.mutation import PathAssignError | ||
from glom.core import UP, bbformat, bbrepr | ||
|
||
from glom import OMIT, Let, Literal # backwards compat | ||
from glom import OMIT # backwards compat | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with the backwards compat ones here. they can probably move up close to the other public ones, but keep the comment. |
||
|
||
|
||
def test_initial_integration(): | ||
|
@@ -101,7 +100,6 @@ def test_coalesce(): | |
Coalesce(bad_kwarg=True) | ||
|
||
|
||
|
||
def test_skip(): | ||
assert OMIT is SKIP # backwards compat | ||
|
||
|
@@ -197,6 +195,7 @@ def __init__(s, a, b, c): s.a, s.b, s.c = a, b, c | |
assert repr(call_f) | ||
val = glom(1, call_f) | ||
assert (val.a, val.b, val.c) == (1, 1, 1) | ||
|
||
class F(object): | ||
def __init__(s, a): s.a = a | ||
val = glom({'one': F('two')}, Call(F, args=(T['one'].a,))) | ||
|
@@ -219,6 +218,7 @@ def __init__(s, a): s.a = a | |
|
||
def test_invoke(): | ||
args = [] | ||
|
||
def test(*a, **kw): | ||
args.append(a) | ||
args.append(kw) | ||
|
@@ -231,9 +231,9 @@ def test(*a, **kw): | |
'kwargs': {'a': 'a'}, | ||
'c': 'C', | ||
} | ||
spec = Invoke(test).star(args='args' | ||
).constants(3, b='b').specs(c='c' | ||
).star(args='args2', kwargs='kwargs') | ||
spec = (Invoke(test).star(args='args') | ||
.constants(3, b='b').specs(c='c') | ||
.star(args='args2', kwargs='kwargs')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is better than the one before, but i think one per line might read nice here. |
||
repr(spec) # no exceptions | ||
assert repr(Invoke(len).specs(T)) == 'Invoke(len).specs(T)' | ||
assert (repr(Invoke.specfunc(next).constants(len).constants(1)) | ||
|
@@ -245,9 +245,9 @@ def test(*a, **kw): | |
args = [] | ||
assert glom(test, Invoke.specfunc(T)) == 'test' | ||
assert args == [(), {}] | ||
repr_spec = Invoke.specfunc(T).star(args='args' | ||
).constants(3, b='b').specs(c='c' | ||
).star(args='args2', kwargs='kwargs') | ||
repr_spec = (Invoke.specfunc(T).star(args='args') | ||
.constants(3, b='b').specs(c='c') | ||
.star(args='args2', kwargs='kwargs')) | ||
assert repr(eval(repr(repr_spec), locals(), globals())) == repr(repr_spec) | ||
|
||
with pytest.raises(TypeError, match='expected func to be a callable or Spec instance'): | ||
|
@@ -281,7 +281,6 @@ def ret_args(*a, **kw): | |
assert glom(target, spec) == 'hi' | ||
|
||
|
||
|
||
def test_spec_and_recursion(): | ||
assert repr(Spec('a.b.c')) == "Spec('a.b.c')" | ||
|
||
|
@@ -350,7 +349,6 @@ def test_python_native(): | |
target = {'system': {'planets': [{'name': 'earth', 'moons': 1}, | ||
{'name': 'jupiter', 'moons': 69}]}} | ||
|
||
|
||
output = glom(target, {'moon_count': ('system.planets', ['moons'], sum)}) | ||
assert output == {'moon_count': 70} | ||
|
||
|
@@ -409,7 +407,7 @@ def test_ref(): | |
assert repr(Ref('item', (T[1], Ref('item')))) == "Ref('item', (T[1], Ref('item')))" | ||
|
||
etree2dicts = Ref('ElementTree', | ||
{"tag": "tag", "text": "text", "attrib": "attrib", "children": (iter, [Ref('ElementTree')])}) | ||
{"tag": "tag", "text": "text", "attrib": "attrib", "children": (iter, [Ref('ElementTree')])}) | ||
etree2tuples = Fill(Ref('ElementTree', (T.tag, Iter(Ref('ElementTree')).all()))) | ||
etree = ElementTree.fromstring(''' | ||
<html> | ||
|
@@ -430,6 +428,8 @@ def test_pipe(): | |
|
||
|
||
_IS_PYPY = '__pypy__' in sys.builtin_module_names | ||
|
||
|
||
@pytest.mark.skipif(_IS_PYPY, reason='pypy othertype.__repr__ is never object.__repr__') | ||
def test_api_repr(): | ||
import glom | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, these imports are to ensure we don't regress the init of the module itself, I don't think we want to remove them.