Commit Graph

92 Commits

Author SHA1 Message Date
Shantanu
6ff5b88ca7 typeshed: remove crufty comments (#4699)
Co-authored-by: hauntsaninja <>
2020-10-23 09:40:06 +02:00
Utsav
6f943d43ea Added __class_getitem__ (#4695)
Resolves #4682

Co-authored-by: hauntsaninja <>
2020-10-22 14:05:04 -07:00
Shantanu
faf827bc36 mark some positional-only arguments (#4693)
https://github.com/python/mypy/pull/9626 will make stubtest a little bit
stricter about positional-only arguments for dunders like __init__

Co-authored-by: hauntsaninja <>
2020-10-22 13:31:23 +02:00
Sebastian Rittau
2157c4a448 Fix patch() used as decorator (#4592)
Closes: #4591
2020-10-02 09:05:25 +02:00
Sebastian Rittau
0cd7dd7009 Fix _patch.__call__() (#4568)
_patch.call() reused the type variable _T, which is generic over
_patch. It was meant to use a separate type variable for the argument,
which is returned.

Fixes #4566
2020-09-23 14:35:19 -07:00
Sebastian Rittau
f14d6eaa89 Improve unittest.mock.patch() types (#4277) 2020-09-21 15:26:39 +02:00
Jelle Zijlstra
5f9fd3d127 upgrade black version (#4486)
Manually removed a number of trailing commas to prevent black from unnecessarily
exploding some collections.
2020-08-26 18:36:01 +02:00
Eric Traut
f46fb7ff59 Added some missing type annotations in stdlib stubs. (#4418)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-08 20:49:37 +02:00
Eric Traut
2fa7a8d8c3 Added missing type annotations for mock.pyi. (#4415)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-08 11:33:01 +02:00
Eric Traut
439ea4bd8b Added missing import for case.pyi (#4403)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-06 19:51:52 -07:00
Eric Traut
04c74640f0 Removed imported symbols that are not accessed or re-exported (#4387)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-05 22:49:17 -07:00
Jaromir Latal
c96b1ae1bf [stdlib][unittest] Fix mock.call(...) types (#4374)
Co-authored-by: Jaromir Latal <jaro@fb.com>
2020-07-30 22:02:08 +02:00
Jelle Zijlstra
5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Milap Sheth
9b3edda33b Fix unittest stub issues reported by mypy stubtest (#4248)
Co-authored-by: Shantanu <>
2020-06-21 15:09:17 -07:00
karl ding
9c6e8fd240 Add undocumented unittest.TextTestResult attributes (#4052)
Add missing type hints for attributes in unittest.TextTestResult.
2020-05-21 12:11:59 +02:00
Shantanu
0630c4b1fd unittest.mock: fix MRO of Mock (#3990)
* unittest.mock: fix MRO of Mock

* Make consistent

Co-authored-by: hauntsaninja <>
2020-05-14 08:57:50 +02:00
Ivan Levkivskyi
5342d66dcc Fix assert_has_calls() signature (#3967)
See the docs https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_has_calls
2020-05-05 19:20:56 +01:00
Max R
31705fca7a Add misc types for mock and unittest.mock (#3923) 2020-04-24 08:51:34 +02:00
Rodrigo Castro
4b14e245d4 Mock and MagickMock subclassing NonCallableMock (#3871) 2020-03-24 15:32:57 +01:00
Rodrigo Castro
ef1d7853ee stdlib.3.unitest.mock.NonCallableMock signatures (#3846) 2020-03-20 14:37:18 +01:00
Benjamin Peterson
fe236ed8b2 Add unittest.result.failfast. (#3596) 2020-01-09 20:39:10 +01:00
dave-shawley
c44a556fb0 Add typestubs for the warnings module (#3543) 2019-12-21 12:29:34 -08:00
Jan Verbeek
a705d59479 Add undocumented methods and make types more specific in 2/unittest (#3550) 2019-12-19 18:17:14 +01:00
Denis Eliseev
74ac70bd28 Fix the signature of unittest.TestCase.assertLogs #3513 (#3514) 2019-11-29 06:00:16 -08:00
Diego Elio Pettenò
99a6fb3108 Add the (deprecated) assertDictContainsSubset() to TestCase. (#3437)
Until this is removed from the standard library, it probably should stay in the typing.

Also update both 2 and 3 definitions to use Mapping[Any, Any], rather than Dict[Any, Any].
2019-11-04 08:10:45 -08:00
Diego Elio Pettenò
7e27bf6bde Allow datetime() with a delta=timedelta() in assert(Not)AlmostEqual(s). (#3426)
While the documentation does not seem to make this particularly
obvious, it is allowed.
2019-11-02 22:35:09 -07:00
Jukka Lehtosalo
86135edb6d Fix signature of assertRaisesRegexp in unittest (#3434)
Fixes mypy false positive `"None" has noattribute "__enter__"` here:

```
class Foo(unittest.TestCase):
    def test_foo(self) -> None:
        with self.assertRaisesRegexp(Exception, "foo"):
            1 / 0
```

Fixes regression introduced in e6c467af82.
2019-11-01 15:48:35 +00:00
Diego Elio Pettenò
e6c467af82 Add missing expected_regex parameter to TestCase.assertRaisesRegexp(). (#3418)
This makes it match the signature of assertRaisesRegex() which is the modern name for the same function.
2019-10-29 16:16:53 +01:00
Sebastian Rittau
0501e2b329 Annotations for remaining Python 3.8 additions (#3358)
* Add os.add_dll_directory()
* Add memfd_create() and flags
* Add type annotation to flags
* Add stat_result.st_reparse_tag and flags
* Add ncurses_version
* Add Path.link_to()
* Add Picker.reducer_override()
* Add plistlib.UID
* Add has_dualstack_ipv6() and create_server()
* Add shlex.join()
* Add SSL methods and fields
* Add Python 3.8 statistics functions and classes
* Remove obsolete sys.subversion
* Add sys.unraisablehook
* Add threading.excepthook
* Add get_native_id() and Thread.native_id
* Add Python 3.8 tkinter methods
* Add CLOCK_UPTIME_RAW
* Add SupportsIndex
* Add typing.get_origin() and get_args()
* Add unicodedata.is_normalized
* Add unittest.mock.AsyncMock

Currently this is just an alias for Any like Mock and MagicMock. All of
these classes should probably be sub-classing Any and add their own
methods. See also #3224.

* Add unittest cleanup methods
* Add IsolatedAsyncioTestCase
* Add ElementTree.canonicalize() and C14NWriterTarget
* cProfile.Profile can be used as a context manager
* Add asyncio task name handling
* mmap.flush() now always returns None
* Add posonlyargcount to CodeType
2019-10-14 09:53:48 +02:00
Sebastian Rittau
256b3ce8ab Remove a bunch of unused imports (#3323) 2019-10-08 07:59:32 -07:00
Sebastian Rittau
c32e1e2280 Enable --disallow-any-generics for stubs (#3288) 2019-10-01 05:31:34 -07:00
Jaromir Latal
cd1a0c592a Add typestubs for unittest.util (#3186) 2019-08-27 15:34:22 +02:00
Shannon Zhu
72010bc5dc Update how mock classes alias to Any (#3182)
* Update how mock classes alias to Any

> First, the z: Any situation looks like a bug or accidental feature to me.
This is definitely meant (and works) as a variable declaration; that it
also allows using z as a type seems wrong. I can't find any evidence in
PEP 484 that this was intended; in mypy it's likely the accidental result
of other design choices meant to shut up errors about Any.

Ideally these classes could be declared as empty class stubs, but since the comments suggest this isn't possible yet, let's update these to be type aliases to Any rather than global variables of type Any. This would avoid invalid type errors when the implementation of type checkers respect the intention that `z: Any` does not make `z` a valid type.

* Update mock.pyi
2019-08-19 17:10:27 -07:00
Michael Lee
b294782183 Make most contextmanager __exit__ signatures return Optional[bool] (#3179)
This pull request is a follow-up to https://github.com/python/mypy/issues/7214.

In short, within that mypy issue, we found it would be helpful to
determine between contextmanagers that can "swallow" exceptions vs ones
that can't. This helps prevent some false positive when using flags that
analyze control flow such as `--warn-unreachable`. To do this,
Jelle proposed assuming that only contextmanagers where the `__exit__`
returns `bool` are assumed to swallow exceptions.

This unfortunately required the following typeshed changes:

1. The typing.IO, threading.Lock, and concurrent.futures.Executor
   were all modified so `__exit__` returns `Optional[None]` instead
   of None -- along with all of their subclasses.

   I believe these three types are meant to be subclassed, so I felt
   picking the more general type was correct.

2. There were also a few concrete types (e.g. see socketserver,
   subprocess, ftplib...) that I modified to return `None` -- I checked
   the source code, and these all seem to return None (and don't appear
   to be meant to be subclassable).

3. contextlib.suppress was changed to return bool. I also double-checked
   the unittest modules and modified a subset of those contextmanagers,
   leaving ones like `_AssertRaisesContext` alone.
2019-08-16 16:13:33 -07:00
Sebastian Rittau
9ccf9356bf Remove Python 3.4 support (#3147)
Closes #3123
2019-07-27 10:58:21 +02:00
Jennifer Taylor
36b28e5b97 Split unittest stubs and add a few field (#2973) 2019-05-08 17:46:45 +02:00
Jan Szopinski
bf2d51742b unittest: Add overloads to assert(Not)AlmostEqual(s) (#2901) 2019-05-05 15:15:17 -04:00
Stephen Thorne
97240083c4 Correct the type signature of assertRaisesRegexp (#2926)
assertRaisesRegexp is the old name of assertRaisesRegex, they are the
same, just that the old one is deprecated.
2019-04-18 20:31:00 -07:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Masashi SHIBATA
c85fed8d98 Fix TextTestResult and TextTestRunner in unittest (#2910)
Co-Authored-By: c-bata <c-bata@users.noreply.github.com>
2019-04-12 12:50:12 +02:00
Savo Kovačević
eb6dbe510d Fix unittest.TestCase assert methods' argument names (#2724)
And fix assertNotAlmostEqual overloads
2019-01-05 17:31:32 -08:00
Juan Gonzalez
76a334daeb Complete unittest.TextTestResult stubs (#2700) 2018-12-21 08:37:33 +01:00
Adam Simpkins
c1dbdc7e26 Fix the return type for unittest.TestCase.run() (#2603)
In Python 3 this method returns None if the test is skipped, and a
TestResult otherwise.
2018-11-16 10:32:42 +01:00
Peter Pentchev
f8e5222c46 unittest.TestCase.assertRaises(): BaseException (#2594)
In Python 3, just as in Python 2, the expected exception argument to
assertRaises() and assertRaisesRegex() must be a subtype of
BaseException, not just of Exception.

Closes #2593
2018-11-08 18:42:51 -08:00
PRAJWAL M
13e84dc004 unittest: Complete assertRaisesRegex (#2568)
fixes #2523
2018-10-30 09:11:16 -07:00
Sebastian Rittau
0730fe5fcb Fix return of patch() and patch.multiple() (#2520)
* Fix return of patch() and patch.multiple()

* Update third party mock as well
2018-10-25 20:55:11 -07:00
Richard Levasseur
4122a70648 Add some private methods to unittest (#2494)
This adds a few stubs that are used by absl-py, and, without them, cause
type checker errors under Pytype:
 * TestCase._formatMessage
 * TestCase._testMethodName
 * TestCase._getAssertEqualityFunc
 * TestProgram.runTests
2018-10-01 20:18:26 -07:00
Dmitry Shachnev
c6c8d7e540 unittest: make assertIn/assertNotIn accept iterables (#2447)
Fixes #2381.
2018-09-11 18:48:44 +02:00
Jelle Zijlstra
8b9e4c378a fix module argument to unittest.main (#2403) 2018-09-10 11:04:05 -07:00
Bruce Merry
c541077ffb Accept AnyStr in unittest.assertRegex (#2315)
And also in assertNotRegex, assertRegexpMatches.

Closes #2312.
2018-07-09 13:23:18 -07:00