def test_filter_args_2(): assert filter_args(j, [], (1, 2), {"ee": 2}) == {"x": 1, "y": 2, "**": {"ee": 2}} ff = functools.partial(f, 1) # filter_args has to special-case partial assert filter_args(ff, [], (1,)) == {"*": [1], "**": {}} assert filter_args(ff, ["y"], (1,)) == {"*": [1], "**": {}}
def test_filter_args_error_msg(exception, regex, func, args): """ Make sure that filter_args returns decent error messages, for the sake of the user. """ with raises(exception) as excinfo: filter_args(func, *args) excinfo.match(regex)
def test_bound_methods(): """ Make sure that calling the same method on two different instances of the same class does resolv to different signatures. """ a = Klass() b = Klass() assert filter_args(a.f, [], (1, )) != filter_args(b.f, [], (1, ))
def test_filter_args_python_3(): nose.tools.assert_equal( filter_args(func_with_kwonly_args, [], (1, 2), { 'kw1': 3, 'kw2': 4 }), { 'a': 1, 'b': 2, 'kw1': 3, 'kw2': 4 }) # filter_args doesn't care about keyword-only arguments so you # can pass 'kw1' into *args without any problem assert_raises_regex( ValueError, "Keyword-only parameter 'kw1' was passed as positional parameter", filter_args, func_with_kwonly_args, [], (1, 2, 3), {'kw2': 2}) nose.tools.assert_equal( filter_args(func_with_kwonly_args, ['b', 'kw2'], (1, 2), { 'kw1': 3, 'kw2': 4 }), { 'a': 1, 'kw1': 3 }) nose.tools.assert_equal( filter_args(func_with_signature, ['b'], (1, 2)), {'a': 1})
def test_filter_args_python_3(): assert (filter_args(func_with_kwonly_args, [], (1, 2), { 'kw1': 3, 'kw2': 4 }) == { 'a': 1, 'b': 2, 'kw1': 3, 'kw2': 4 }) # filter_args doesn't care about keyword-only arguments so you # can pass 'kw1' into *args without any problem with raises(ValueError) as excinfo: filter_args(func_with_kwonly_args, [], (1, 2, 3), {'kw2': 2}) excinfo.match("Keyword-only parameter 'kw1' was passed as positional " "parameter") assert (filter_args(func_with_kwonly_args, ['b', 'kw2'], (1, 2), { 'kw1': 3, 'kw2': 4 }) == { 'a': 1, 'kw1': 3 }) assert (filter_args(func_with_signature, ['b'], (1, 2)) == {'a': 1})
def test_bound_methods(): """ Make sure that calling the same method on two different instances of the same class does resolv to different signatures. """ a = Klass() b = Klass() nose.tools.assert_not_equal(filter_args(a.f, [], (1,)), filter_args(b.f, [], (1,)))
def test_bound_methods(): """ Make sure that calling the same method on two different instances of the same class does resolv to different signatures. """ a = Klass() b = Klass() nose.tools.assert_not_equal(filter_args(a.f, [], (1, )), filter_args(b.f, [], (1, )))
def test_filter_args_2(): assert (filter_args(j, [], (1, 2), {'ee': 2}) == {'x': 1, 'y': 2, '**': {'ee': 2}}) ff = functools.partial(f, 1) # filter_args has to special-case partial assert filter_args(ff, [], (1, )) == {'*': [1], '**': {}} assert filter_args(ff, ['y'], (1, )) == {'*': [1], '**': {}}
def test_bound_cached_methods_hash(tmpdir): """ Make sure that calling the same _cached_ method on two different instances of the same class does resolve to the same hashes. """ a = KlassWithCachedMethod(tmpdir.strpath) b = KlassWithCachedMethod(tmpdir.strpath) assert (hash(filter_args(a.f.func, [], (1, ))) == hash(filter_args(b.f.func, [], (1, ))))
def test_bound_cached_methods_hash(): """ Make sure that calling the same _cached_ method on two different instances of the same class does resolve to the same hashes. """ a = KlassWithCachedMethod() b = KlassWithCachedMethod() nose.tools.assert_equal(hash(filter_args(a.f.func, [], (1, ))), hash(filter_args(b.f.func, [], (1, ))))
def test_bound_methods_hash(): """ Make sure that calling the same method on two different instances of the same class does resolve to the same hashes. """ a = Klass() b = Klass() assert (hash(filter_args(a.f, [], (1, ))) == hash(filter_args(b.f, [], (1, ))))
def test_bound_cached_methods_hash(tmpdir_path): """ Make sure that calling the same _cached_ method on two different instances of the same class does resolve to the same hashes. """ a = KlassWithCachedMethod(tmpdir_path) b = KlassWithCachedMethod(tmpdir_path) assert (hash(filter_args(a.f.func, [], (1, ))) == hash(filter_args(b.f.func, [], (1, ))))
def test_filter_varargs(): yield assert_equal, filter_args(h, [], (1, )), \ {'x': 1, 'y': 0, '*': [], '**': {}} yield assert_equal, filter_args(h, [], (1, 2, 3, 4)), \ {'x': 1, 'y': 2, '*': [3, 4], '**': {}} yield assert_equal, filter_args(h, [], (1, 25), dict(ee=2)), \ {'x': 1, 'y': 25, '*': [], '**': {'ee': 2}} yield assert_equal, filter_args(h, ['*'], (1, 2, 25), dict(ee=2)), \ {'x': 1, 'y': 2, '**': {'ee': 2}}
def test_filter_args_2(): nose.tools.assert_equal(filter_args(j, [], (1, 2), dict(ee=2)), {"x": 1, "y": 2, "**": {"ee": 2}}) nose.tools.assert_raises(ValueError, filter_args, f, "a", (None,)) # Check that we capture an undefined argument nose.tools.assert_raises(ValueError, filter_args, f, ["a"], (None,)) ff = functools.partial(f, 1) # filter_args has to special-case partial nose.tools.assert_equal(filter_args(ff, [], (1,)), {"*": [1], "**": {}}) nose.tools.assert_equal(filter_args(ff, ["y"], (1,)), {"*": [1], "**": {}})
def test_filter_args_no_kwargs_mutation(): """None-regression test against 0.12.0 changes. https://github.com/joblib/joblib/pull/75 Make sure filter args doesn't mutate the kwargs dict that gets passed in. """ kwargs = {'x': 0} filter_args(g, [], [], kwargs) assert kwargs == {'x': 0}
def test_filter_kwargs(): nose.tools.assert_equal(filter_args(k, [], (1, 2), dict(ee=2)), { '*': [1, 2], '**': { 'ee': 2 } }) nose.tools.assert_equal(filter_args(k, [], (3, 4)), { '*': [3, 4], '**': {} })
def test_filter_varargs(): yield nose.tools.assert_equal, filter_args(h, [], (1, )), \ {'x': 1, 'y': 0, '*': [], '**': {}} yield nose.tools.assert_equal, filter_args(h, [], (1, 2, 3, 4)), \ {'x': 1, 'y': 2, '*': [3, 4], '**': {}} yield nose.tools.assert_equal, filter_args(h, [], (1, 25), dict(ee=2)), \ {'x': 1, 'y': 25, '*': [], '**': {'ee': 2}} yield nose.tools.assert_equal, filter_args(h, ['*'], (1, 2, 25), dict(ee=2)), \ {'x': 1, 'y': 2, '**': {'ee': 2}}
def test_filter_args_2(): assert (filter_args(j, [], (1, 2), dict(ee=2)) == {'x': 1, 'y': 2, '**': {'ee': 2}}) assert_raises(ValueError, filter_args, f, 'a', (None, )) # Check that we capture an undefined argument assert_raises(ValueError, filter_args, f, ['a'], (None, )) ff = functools.partial(f, 1) # filter_args has to special-case partial assert filter_args(ff, [], (1, )) == {'*': [1], '**': {}} assert filter_args(ff, ['y'], (1, )) == {'*': [1], '**': {}}
def test_filter_args(): yield nose.tools.assert_equal, filter_args(f, [], (1,)), {"x": 1, "y": 0} yield nose.tools.assert_equal, filter_args(f, ["x"], (1,)), {"y": 0} yield nose.tools.assert_equal, filter_args(f, ["y"], (0,)), {"x": 0} yield nose.tools.assert_equal, filter_args(f, ["y"], (0,), dict(y=1)), {"x": 0} yield nose.tools.assert_equal, filter_args(f, ["x", "y"], (0,)), {} yield nose.tools.assert_equal, filter_args(f, [], (0,), dict(y=1)), {"x": 0, "y": 1} yield nose.tools.assert_equal, filter_args(f, ["y"], (), dict(x=2, y=1)), {"x": 2} yield nose.tools.assert_equal, filter_args(i, [], (2,)), {"x": 2} yield nose.tools.assert_equal, filter_args(f2, [], (), dict(x=1)), {"x": 1}
def test_filter_args(): yield assert_equal, filter_args(f, [], (1, )), {'x': 1, 'y': 0} yield assert_equal, filter_args(f, ['x'], (1, )), {'y': 0} yield assert_equal, filter_args(f, ['y'], (0, )), {'x': 0} yield assert_equal, filter_args(f, ['y'], (0, ), dict(y=1)), {'x': 0} yield assert_equal, filter_args(f, ['x', 'y'], (0, )), {} yield assert_equal, filter_args(f, [], (0,), dict(y=1)), {'x': 0, 'y': 1} yield assert_equal, filter_args(f, ['y'], (), dict(x=2, y=1)), {'x': 2} yield assert_equal, filter_args(i, [], (2, )), {'x': 2} yield assert_equal, filter_args(f2, [], (), dict(x=1)), {'x': 1}
def test_filter_args_python_3(): assert filter_args(func_with_kwonly_args, [], (1, 2), {"kw1": 3, "kw2": 4}) == { "a": 1, "b": 2, "kw1": 3, "kw2": 4, } # filter_args doesn't care about keyword-only arguments so you # can pass 'kw1' into *args without any problem with raises(ValueError) as excinfo: filter_args(func_with_kwonly_args, [], (1, 2, 3), {"kw2": 2}) excinfo.match("Keyword-only parameter 'kw1' was passed as positional " "parameter") assert filter_args(func_with_kwonly_args, ["b", "kw2"], (1, 2), {"kw1": 3, "kw2": 4}) == {"a": 1, "kw1": 3} assert filter_args(func_with_signature, ["b"], (1, 2)) == {"a": 1}
def test_filter_args_2(): nose.tools.assert_equal(filter_args(j, [], (1, 2), dict(ee=2)), { 'x': 1, 'y': 2, '**': { 'ee': 2 } }) nose.tools.assert_raises(ValueError, filter_args, f, 'a', (None, )) # Check that we capture an undefined argument nose.tools.assert_raises(ValueError, filter_args, f, ['a'], (None, )) ff = functools.partial(f, 1) # filter_args has to special-case partial nose.tools.assert_equal(filter_args(ff, [], (1, )), {'*': [1], '**': {}}) nose.tools.assert_equal(filter_args(ff, ['y'], (1, )), { '*': [1], '**': {} })
def test_filter_args_python_3(): assert ( filter_args(func_with_kwonly_args, [], (1, 2), {'kw1': 3, 'kw2': 4}) == {'a': 1, 'b': 2, 'kw1': 3, 'kw2': 4}) # filter_args doesn't care about keyword-only arguments so you # can pass 'kw1' into *args without any problem with raises(ValueError) as excinfo: filter_args(func_with_kwonly_args, [], (1, 2, 3), {'kw2': 2}) excinfo.match("Keyword-only parameter 'kw1' was passed as positional " "parameter") assert ( filter_args(func_with_kwonly_args, ['b', 'kw2'], (1, 2), {'kw1': 3, 'kw2': 4}) == {'a': 1, 'kw1': 3}) assert (filter_args(func_with_signature, ['b'], (1, 2)) == {'a': 1})
def submit(self, func, *args, **kwargs): if not hasattr(func, 'version_info'): raise ValueError('func does not have @versioned decorator') # Compute hashes to find target job path args_dict = filter_args(func, func.version_info['ignore_args'], *args, **kwargs) future = self._create_future(func, args, kwargs, args_dict, should_submit=True) return future
def test_filter_args_python_3(): nose.tools.assert_equal( filter_args(func_with_kwonly_args, [], (1, 2), {"kw1": 3, "kw2": 4}), {"a": 1, "b": 2, "kw1": 3, "kw2": 4} ) # filter_args doesn't care about keyword-only arguments so you # can pass 'kw1' into *args without any problem assert_raises_regex( ValueError, "Keyword-only parameter 'kw1' was passed as positional parameter", filter_args, func_with_kwonly_args, [], (1, 2, 3), {"kw2": 2}, ) nose.tools.assert_equal( filter_args(func_with_kwonly_args, ["b", "kw2"], (1, 2), {"kw1": 3, "kw2": 4}), {"a": 1, "kw1": 3} ) nose.tools.assert_equal(filter_args(func_with_signature, ["b"], (1, 2)), {"a": 1})
def test_filter_args(): yield nose.tools.assert_equal, filter_args(f, [], (1, )),\ {'x': 1, 'y': 0} yield nose.tools.assert_equal, filter_args(f, ['x'], (1, )),\ {'y': 0} yield nose.tools.assert_equal, filter_args(f, ['y'], (0, )),\ {'x': 0} yield nose.tools.assert_equal, filter_args(f, ['y'], (0, ), dict(y=1)), { 'x': 0 } yield nose.tools.assert_equal, filter_args(f, ['x', 'y'], (0, )), {} yield nose.tools.assert_equal, filter_args(f, [], (0, ), dict(y=1)), { 'x': 0, 'y': 1 } yield nose.tools.assert_equal, filter_args(f, ['y'], (), dict(x=2, y=1)), { 'x': 2 } yield nose.tools.assert_equal, filter_args(i, [], (2, )), {'x': 2} yield nose.tools.assert_equal, filter_args(f2, [], (), dict(x=1)), {'x': 1}
def test_filter_args_method(): obj = Klass() assert filter_args(obj.f, [], (1, )) == {'x': 1, 'self': obj}
def test_filter_args_method(): obj = Klass() assert filter_args(obj.f, [], (1,)) == {"x": 1, "self": obj}
def test_filter_args_method(): obj = Klass() nose.tools.assert_equal(filter_args(obj.f, [], (1,)), {"x": 1, "self": obj})
def test_filter_args(func, args, filtered_args): assert filter_args(func, *args) == filtered_args
def test_filter_kwargs(): nose.tools.assert_equal(filter_args(k, [], (1, 2), dict(ee=2)), {'*': [1, 2], '**': {'ee': 2}}) nose.tools.assert_equal(filter_args(k, [], (3, 4)), {'*': [3, 4], '**': {}})
def test_filter_kwargs(): assert (filter_args(k, [], (1, 2), dict(ee=2)) == {'*': [1, 2], '**': {'ee': 2}}) assert filter_args(k, [], (3, 4)) == {'*': [3, 4], '**': {}}
def test_filter_kwargs(): nose.tools.assert_equal(filter_args(k, [], (1, 2), dict(ee=2)), {"*": [1, 2], "**": {"ee": 2}}) nose.tools.assert_equal(filter_args(k, [], (3, 4)), {"*": [3, 4], "**": {}})
def test_filter_varargs(): yield nose.tools.assert_equal, filter_args(h, [], (1,)), {"x": 1, "y": 0, "*": [], "**": {}} yield nose.tools.assert_equal, filter_args(h, [], (1, 2, 3, 4)), {"x": 1, "y": 2, "*": [3, 4], "**": {}} yield nose.tools.assert_equal, filter_args(h, [], (1, 25), dict(ee=2)), {"x": 1, "y": 25, "*": [], "**": {"ee": 2}} yield nose.tools.assert_equal, filter_args(h, ["*"], (1, 2, 25), dict(ee=2)), {"x": 1, "y": 2, "**": {"ee": 2}}
def test_filter_varargs(func, args, filtered_args): assert filter_args(func, *args) == filtered_args
def test_filter_args_method(): obj = Klass() nose.tools.assert_equal(filter_args(obj.f, [], (1, )), {'x': 1, 'self': obj})
def test_filter_args_method(): obj = Klass() nose.tools.assert_equal(filter_args(obj.f, [], (1, )), { 'x': 1, 'self': obj })