A tuple for holding the results of a call to a mock, either in the form `(args, kwargs)` or `(name, args, kwargs)`. If args or kwargs are empty then a call tuple will compare equal to a tuple without those values. This makes comparisons less verbose:: _Call(('name', (), {}
| 2551 | |
| 2552 | |
| 2553 | class _Call(tuple): |
| 2554 | """ |
| 2555 | A tuple for holding the results of a call to a mock, either in the form |
| 2556 | `(args, kwargs)` or `(name, args, kwargs)`. |
| 2557 | |
| 2558 | If args or kwargs are empty then a call tuple will compare equal to |
| 2559 | a tuple without those values. This makes comparisons less verbose:: |
| 2560 | |
| 2561 | _Call(('name', (), {})) == ('name',) |
| 2562 | _Call(('name', (1,), {})) == ('name', (1,)) |
| 2563 | _Call(((), {'a': 'b'})) == ({'a': 'b'},) |
| 2564 | |
| 2565 | The `_Call` object provides a useful shortcut for comparing with call:: |
| 2566 | |
| 2567 | _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) |
| 2568 | _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) |
| 2569 | |
| 2570 | If the _Call has no name then it will match any name. |
| 2571 | """ |
| 2572 | def __new__(cls, value=(), name='', parent=None, two=False, |
| 2573 | from_kall=True): |
| 2574 | args = () |
| 2575 | kwargs = {} |
| 2576 | _len = len(value) |
| 2577 | if _len == 3: |
| 2578 | name, args, kwargs = value |
| 2579 | elif _len == 2: |
| 2580 | first, second = value |
| 2581 | if isinstance(first, str): |
| 2582 | name = first |
| 2583 | if isinstance(second, tuple): |
| 2584 | args = second |
| 2585 | else: |
| 2586 | kwargs = second |
| 2587 | else: |
| 2588 | args, kwargs = first, second |
| 2589 | elif _len == 1: |
| 2590 | value, = value |
| 2591 | if isinstance(value, str): |
| 2592 | name = value |
| 2593 | elif isinstance(value, tuple): |
| 2594 | args = value |
| 2595 | else: |
| 2596 | kwargs = value |
| 2597 | |
| 2598 | if two: |
| 2599 | return tuple.__new__(cls, (args, kwargs)) |
| 2600 | |
| 2601 | return tuple.__new__(cls, (name, args, kwargs)) |
| 2602 | |
| 2603 | |
| 2604 | def __init__(self, value=(), name=None, parent=None, two=False, |
| 2605 | from_kall=True): |
| 2606 | self._mock_name = name |
| 2607 | self._mock_parent = parent |
| 2608 | self._mock_from_kall = from_kall |
| 2609 | |
| 2610 |
no outgoing calls