def test_generate_calls_simple(): f = mock.Mock() f.__name__ = "f" f.some_prop = 42 call_specs = [{"abc": 1}, {"abc": 2}, {"abc": 3}] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == "(abc=1)" assert calls[1].session_signature == "(abc=2)" assert calls[2].session_signature == "(abc=3)" calls[0]() f.assert_called_with(abc=1) calls[1]() f.assert_called_with(abc=2) calls[2]() f.assert_called_with(abc=3) # Make sure wrapping was done correctly. for call in calls: assert call.some_prop == 42 assert call.__name__ == "f"
def test_generate_calls_multiple_args(): f = mock.Mock() f.__name__ = 'f' call_specs = [{ 'abc': 1, 'foo': 'a' }, { 'abc': 2, 'foo': 'b' }, { 'abc': 3, 'foo': 'c' }] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == '(abc=1, foo=\'a\')' assert calls[1].session_signature == '(abc=2, foo=\'b\')' assert calls[2].session_signature == '(abc=3, foo=\'c\')' calls[0]() f.assert_called_with(abc=1, foo='a') calls[1]() f.assert_called_with(abc=2, foo='b') calls[2]() f.assert_called_with(abc=3, foo='c')
def make_session(self, name, func): """Create a session object from the session function. Args: name (str): The name of the session. func (function): The session function. Returns: Sequence[~nox.session.Session]: A sequence of Session objects bound to this manifest and configuration. """ # Simple case: If this function is not parametrized, then make # a simple session if not hasattr(func, 'parametrize'): session = Session(name, None, func, self._config, self) return (session, ) # Since this function is parametrized, we need to add a distinct # session for each permutation. sessions = [] calls = generate_calls(func, func.parametrize) for call in calls: long_name = name + call.session_signature sessions.append(Session(name, long_name, call, self._config, self)) # Edge case: If the parameters made it such that there were no valid # calls, add an empty, do-nothing session. if not calls: sessions.append( Session(name, None, _null_session_func, self._config, self), ) # Return the list of sessions. return sessions
def test_generate_calls_simple(): f = mock.Mock() f.__name__ = "f" f.some_prop = 42 arg_names = ("abc", ) call_specs = [ _parametrize.Param(1, arg_names=arg_names), _parametrize.Param(2, arg_names=arg_names), _parametrize.Param(3, arg_names=arg_names), ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == "(abc=1)" assert calls[1].session_signature == "(abc=2)" assert calls[2].session_signature == "(abc=3)" calls[0]() f.assert_called_with(abc=1) calls[1]() f.assert_called_with(abc=2) calls[2]() f.assert_called_with(abc=3) # Make sure wrapping was done correctly. for call in calls: assert call.some_prop == 42 assert call.__name__ == "f"
def test_generate_calls_multiple_args(): f = mock.Mock() f.__name__ = "f" arg_names = ("abc", "foo") call_specs = [ _parametrize.Param(1, "a", arg_names=arg_names), _parametrize.Param(2, "b", arg_names=arg_names), _parametrize.Param(3, "c", arg_names=arg_names), ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == "(abc=1, foo='a')" assert calls[1].session_signature == "(abc=2, foo='b')" assert calls[2].session_signature == "(abc=3, foo='c')" calls[0]() f.assert_called_with(abc=1, foo="a") calls[1]() f.assert_called_with(abc=2, foo="b") calls[2]() f.assert_called_with(abc=3, foo="c")
def test_generate_calls_multiple_args(): f = mock.Mock() f.__name__ = "f" call_specs = [ { "abc": 1, "foo": "a" }, { "abc": 2, "foo": "b" }, { "abc": 3, "foo": "c" }, ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == "(abc=1, foo='a')" assert calls[1].session_signature == "(abc=2, foo='b')" assert calls[2].session_signature == "(abc=3, foo='c')" calls[0]() f.assert_called_with(abc=1, foo="a") calls[1]() f.assert_called_with(abc=2, foo="b") calls[2]() f.assert_called_with(abc=3, foo="c")
def make_session(self, name, func): """Create a session object from the session function. Args: name (str): The name of the session. func (function): The session function. Returns: Sequence[~nox.session.Session]: A sequence of Session objects bound to this manifest and configuration. """ sessions = [] # If the func has the python attribute set to a list, we'll need # to expand them. if isinstance(func.python, (list, tuple, set)): for python in func.python: single_func = _copy_func(func) single_func.python = python sessions.extend(self.make_session(name, single_func)) return sessions # Simple case: If this function is not parametrized, then make # a simple session if not hasattr(func, 'parametrize'): if func.python: long_name = '{}-{}'.format(name, func.python) else: long_name = name session = SessionRunner(name, long_name, func, self._config, self) return [session] # Since this function is parametrized, we need to add a distinct # session for each permutation. calls = generate_calls(func, func.parametrize) for call in calls: if func.python: long_name = '{}-{}{}'.format(name, func.python, call.session_signature) else: long_name = '{}{}'.format(name, call.session_signature) sessions.append( SessionRunner(name, long_name, call, self._config, self)) # Edge case: If the parameters made it such that there were no valid # calls, add an empty, do-nothing session. if not calls: sessions.append( SessionRunner(name, None, _null_session_func, self._config, self), ) # Return the list of sessions. return sessions
def make_sessions(session_functions, global_config): sessions = [] for name, func in session_functions: if not hasattr(func, 'parametrize'): sessions.append(Session(name, None, func, global_config)) else: for call in generate_calls(func, func.parametrize): session = Session(name, name + call.session_signature, call, global_config) sessions.append(session) return sessions
def make_sessions(session_functions, global_config): sessions = [] for name, func in session_functions: if not hasattr(func, 'parametrize'): sessions.append(Session(name, None, func, global_config)) else: for call in generate_calls(func, func.parametrize): session = Session( name, name + call.session_signature, call, global_config) sessions.append(session) return sessions
def make_sessions(session_functions, global_config): sessions = [] for name, func in session_functions: if not hasattr(func, 'parametrize'): sessions.append(Session(name, None, func, global_config)) else: calls = generate_calls(func, func.parametrize) for call in calls: session = Session( name, name + call.session_signature, call, global_config) sessions.append(session) if not calls: # Add an empty, do-nothing session. sessions.append(Session( name, None, _null_session_func, global_config)) return sessions
def test_generate_calls_ids(): f = mock.Mock() f.__name__ = "f" arg_names = ("foo", ) call_specs = [ _parametrize.Param(1, arg_names=arg_names, id="a"), _parametrize.Param(2, arg_names=arg_names, id="b"), ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 2 assert calls[0].session_signature == "(a)" assert calls[1].session_signature == "(b)" calls[0]() f.assert_called_with(foo=1) calls[1]() f.assert_called_with(foo=2)
def test_generate_calls_simple(): f = mock.Mock() f.__name__ = 'f' call_specs = [{'abc': 1}, {'abc': 2}, {'abc': 3}] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == '(abc=1)' assert calls[1].session_signature == '(abc=2)' assert calls[2].session_signature == '(abc=3)' calls[0]() f.assert_called_with(abc=1) calls[1]() f.assert_called_with(abc=2) calls[2]() f.assert_called_with(abc=3)
def test_generate_calls_multiple_args(): f = mock.Mock() f.__name__ = "f" call_specs = [ {"abc": 1, "foo": "a"}, {"abc": 2, "foo": "b"}, {"abc": 3, "foo": "c"}, ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == "(abc=1, foo='a')" assert calls[1].session_signature == "(abc=2, foo='b')" assert calls[2].session_signature == "(abc=3, foo='c')" calls[0]() f.assert_called_with(abc=1, foo="a") calls[1]() f.assert_called_with(abc=2, foo="b") calls[2]() f.assert_called_with(abc=3, foo="c")
def test_generate_calls_simple(): f = mock.Mock() f.__name__ = 'f' call_specs = [ {'abc': 1}, {'abc': 2}, {'abc': 3} ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == '(abc=1)' assert calls[1].session_signature == '(abc=2)' assert calls[2].session_signature == '(abc=3)' calls[0]() f.assert_called_with(abc=1) calls[1]() f.assert_called_with(abc=2) calls[2]() f.assert_called_with(abc=3)
def test_generate_calls_multiple_args(): f = mock.Mock() f.__name__ = 'f' call_specs = [ {'abc': 1, 'foo': 'a'}, {'abc': 2, 'foo': 'b'}, {'abc': 3, 'foo': 'c'} ] calls = _parametrize.generate_calls(f, call_specs) assert len(calls) == 3 assert calls[0].session_signature == '(abc=1, foo=\'a\')' assert calls[1].session_signature == '(abc=2, foo=\'b\')' assert calls[2].session_signature == '(abc=3, foo=\'c\')' calls[0]() f.assert_called_with(abc=1, foo='a') calls[1]() f.assert_called_with(abc=2, foo='b') calls[2]() f.assert_called_with(abc=3, foo='c')
def make_session(self, name, func, multi=False): """Create a session object from the session function. Args: name (str): The name of the session. func (function): The session function. multi (bool): Whether the function is a member of a set of sessions with different interpreters. Returns: Sequence[~nox.session.Session]: A sequence of Session objects bound to this manifest and configuration. """ sessions = [] # If the func has the python attribute set to a list, we'll need # to expand them. if isinstance(func.python, (list, tuple, set)): for python in func.python: single_func = _copy_func(func) single_func.python = python session = self.make_session(name, single_func, multi=True) sessions.extend(session) return sessions # Simple case: If this function is not parametrized, then make # a simple session if not hasattr(func, "parametrize"): long_names = [] if not multi: long_names.append(name) if func.python: long_names.append("{}-{}".format(name, func.python)) session = SessionRunner(name, long_names, func, self._config, self) return [session] # Since this function is parametrized, we need to add a distinct # session for each permutation. calls = generate_calls(func, func.parametrize) for call in calls: long_names = [] if not multi: long_names.append("{}{}".format(name, call.session_signature)) if func.python: long_names.append("{}-{}{}".format(name, func.python, call.session_signature)) # Ensure that specifying session-python will run all parameterizations. long_names.append("{}-{}".format(name, func.python)) sessions.append( SessionRunner(name, long_names, call, self._config, self)) # Edge case: If the parameters made it such that there were no valid # calls, add an empty, do-nothing session. if not calls: sessions.append( SessionRunner(name, [], _null_session_func, self._config, self)) # Return the list of sessions. return sessions
def make_session(self, name, func, multi=False): """Create a session object from the session function. Args: name (str): The name of the session. func (function): The session function. multi (bool): Whether the function is a member of a set of sessions with different interpreters. Returns: Sequence[~nox.session.Session]: A sequence of Session objects bound to this manifest and configuration. """ sessions = [] # If the func has the python attribute set to a list, we'll need # to expand them. if isinstance(func.python, (list, tuple, set)): for python in func.python: single_func = _copy_func(func) single_func.python = python session = self.make_session(name, single_func, multi=True) sessions.extend(session) return sessions # Simple case: If this function is not parametrized, then make # a simple session if not hasattr(func, "parametrize"): long_names = [] if not multi: long_names.append(name) if func.python: long_names.append("{}-{}".format(name, func.python)) session = SessionRunner(name, long_names, func, self._config, self) return [session] # Since this function is parametrized, we need to add a distinct # session for each permutation. calls = generate_calls(func, func.parametrize) for call in calls: long_names = [] if not multi: long_names.append("{}{}".format(name, call.session_signature)) if func.python: long_names.append( "{}-{}{}".format(name, func.python, call.session_signature) ) # Ensure that specifying session-python will run all parameterizations. long_names.append("{}-{}".format(name, func.python)) sessions.append(SessionRunner(name, long_names, call, self._config, self)) # Edge case: If the parameters made it such that there were no valid # calls, add an empty, do-nothing session. if not calls: sessions.append( SessionRunner(name, [], _null_session_func, self._config, self) ) # Return the list of sessions. return sessions