Commit Graph

57 Commits

Author SHA1 Message Date
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
Sebastian Rittau
b05e99297c Drop Python 3.3 support from several stubs (#2266)
* Drop Python 3.3 support from importlib stubs

* Drop Python 3.3 support from html and symbol stubs
2018-06-20 16:46:11 -07:00
Jukka Lehtosalo
feeb4e71ef Change mock classes to Any values to avoid false positives (#2255)
The previous definitions in `mock` caused many false positives in
internal Dropbox repositories.

One source of problems was `List[Mock]` not being compatible with
`List[SomeClass]`, since `list` is invariant.
2018-06-19 16:28:19 +01:00
Guido van Rossum
af3b015aa8 mock.patch.object() attribute arg should be Text (#2210)
It works and is needed for code using the dreaded
'from __future__ import unicode_literals'.
2018-06-09 22:36:24 -07:00
Max R
34b926008e Remove Python 3.3 check in mock.pyi (#2201) 2018-06-05 15:30:28 -07:00
Jelle Zijlstra
eef0b1d562 fix type for TestCase.assertIn (#2186)
* fix type for TestCase.assertIn

This does essentially `assert member in container`, so we want a `Container`, not an `Iterable`.

This came up in 68e9d426a8..0bbee43d60 (r192525658).

* use any for assertIn
2018-06-04 15:34:09 -07:00
Robert Collins
98badb6eff Fix mock patch.dict stub and add mock stub (#2173)
The dict stub was referring to an instance, not the type, leading to
__call__ being considered when using as a decorator, rather than
__init__.

mock is a backport of the stdlib module and should be defined the same.
2018-05-31 21:45:54 -07:00
Jelle Zijlstra
37aba00fe8 fix using ZipFile as a ContextManager (#2043) 2018-04-12 12:29:22 -07:00
Jelle Zijlstra
7cfbc7d17f more 3.7 features (#2015) 2018-04-06 11:09:11 -07:00
rchen152
38dc8f5a6a Switch usages of mypy_extensions.NoReturn over to typing.NoReturn. (#1942)
* Change mypy_extensions.NoReturn to typing.NoReturn everywhere.
2018-03-05 12:42:29 -08:00
rchen152
066c434410 Improve the unittest stubs. (#1927)
* Improvements to stdlib/2/unittest.pyi

* Adds a bunch of missing things.
* Fixes the signatures of assertRaises and failUnlessRaises.
* Corrects the name of a TestCase subclass from CallableTestCase
  to FunctionTestCase.
* Makes defaultTestLoader an instance of TestLoader, as it should
  be, rather than an alias. Based on https://docs.python.org/2/library/unittest.html and
  https://github.com/python/cpython/tree/2.7/Lib/unittest.

* Improvements to stdlib/3/unittest/__init__.pyi

* The constructor arguments to TextTestResult are all required.
* There is a module-level load_tests() function.
* removeResult() returns a bool. Based on https://docs.python.org/3/library/unittest.html and
  https://github.com/python/cpython/tree/master/Lib/unittest.
2018-02-27 06:46:10 -08:00
Nick Gaya
3e85d6bb61 Add missing unittest.mock.patch attributes (#1882) 2018-02-16 09:13:33 -08:00
rchen152
66e5863ead Change the return type of unittest.TestCase.fail() to NoReturn (#1843)
* Change the return type of unittest.TestCase.fail() to NoReturn

* Import mypy_extensions.NoReturn instead of typing.NoReturn
2018-01-26 14:28:37 -08:00
Jelle Zijlstra
83ca997140 Change more defaults to ... (#1729)
* codemod ': Any = None' ': Any = ...'
* codemod ': (Union|Optional)([^=]+)\s+=\s+-?\d+' ': \1\2 = ...'
* codemod ': (Union|Optional)([^=]+)\s*=\s*-?(None|False|True)' ': \1\2 = ...'
* codemod ': (int|float|bool)\s*=\s*-?\d+' ': \1 = ...'
* codemod ': (bool)\s*=\s*(False|True)' ': \1 = ...'
* codemod ': Any\s*=\s*(False|True|None)' ': Any = ...'
2017-11-13 06:56:24 -08:00
Jelle Zijlstra
54dd6ba27c Change numerous default values to ... (#1722)
This is the convention, and some default values (e.g. strings) apparently
break pytype.
2017-11-09 06:28:40 -08:00
Sebastian Rittau
87ef6b8d53 Add stub for unittest.mock.patch.multiple() (#1686)
* Add stub for unittest.mock.patch.multiple()

* Use ... for default arguments in unittest.mock.patch() et al.

* Tighten type of create argument to patch() et al.
2017-10-26 00:57:56 -04:00
Jelle Zijlstra
78587dc895 Revert "make __class__ refer to the current object's class (#1549)" (#1632)
This reverts commit 1a164b630c.

Reverts python/typeshed#1549.

See Guido's comments in the original PR.
2017-09-29 11:37:54 -07:00
Jelle Zijlstra
1a164b630c make __class__ refer to the current object's class (#1549)
Fixes python/mypy#3061
2017-09-27 18:11:59 -07:00
Martin DeMello
d389ef3d85 Remove a few files from the pytype blacklist. (#1628)
Fixes the following issues:

* Literals rather than ... for default values
* None rather than ... for default value of typed variable
* Literals rather than ... # type for top level constants
* # Foo rather than # type: Foo
* return value of init not set to None
2017-09-27 07:57:13 -07:00
Guido van Rossum
76685480e0 Misc fixes found by running mypy against Dropbox internal codebase "C". (#1575) 2017-08-25 20:34:13 -07:00
toejough
f6b013ba52 ignore type for mock.pyi inheritance from Any (#1492)
It is currently required to shut up mypy when run with `--strict`
or `--disallow-subclassing-any`. The `Any` base class is currently
the only way to allow passing an instance of `Mock` to functions
expecting other classes (as is Mock's purpose).
2017-07-19 11:33:59 -07:00
Jelle Zijlstra
ac651d2f8c Fix a few TODOs (#1487)
* fix some easy TODOs

* fix io
2017-07-19 20:27:50 +03:00
Guido van Rossum
350563223f Add Optional[] for all remaining cases of x: <type> = None (#1424)
* Final round of adding Optional[] to type of arguments with default = None
* Update Travis to use --no-implicit-optionals and clarify CONTRIBUTING.md
2017-06-21 10:50:21 -07:00
Carl Meyer
802f3b21b3 Fix __init__ signature for unittest.mock.MagicMock. (#1388) 2017-06-04 10:08:56 -07:00
Benjamin Starling
9abbc0d392 Fix unittest.mock.Mock keyword arguments to address #1282 (#1300) 2017-05-22 23:30:40 -07:00
Jelle Zijlstra
7dd2f80194 Fixes to ContextManager (#1249)
* add typing.ContextManager for 3.6+ only

This fixes the easier part of #655.

Would it make sense to add a generic typing.ContextManager that exists in any Python version?

* update comment

* fix argument types for ContextManager.__exit__

* add AsyncContextManager

* add @asynccontextmanager

* typing.ContextManager now always exists

* back out async-related changes

Will submit those in a separate PR later

* fix import order

* AbstractContextManager only exists in 3.6+

* AbstractContextManager -> ContextManager
2017-05-08 16:21:51 -07:00
Roy Williams
452c1e1d78 Fix patch.object to return a _patch context manager. (#1142)
* Fix patch.object to return a _patch context manager.

This should fix https://github.com/python/typeshed/issues/914

* Prefer None over ... to be consistent with the rest of the file.
2017-04-06 18:47:28 -07:00
Guido van Rossum
1ea3d2de57 Make all single-constraint TypeVars use bound= insteads (plus hack) (#1118)
Another attempt for #804, to unblock python/mypy#2626.
There's a work-around here for python/mypy#1551.
2017-03-29 14:59:24 -07:00
jkleint
433b1b2ebc TestCase.assertSetEqual() should accept frozenset (#1063)
This declares the method to take the union of Set and FrozenSet
rather than AbstractSet since that is where `difference()`
(used by `assertSetEqual()`) is defined.
2017-03-21 23:10:19 -07:00
Jukka Lehtosalo
f296b37e80 Fixes to unittest stubs (#1024)
* Fixes to unittest stubs

* Make types more precise
2017-03-18 14:35:33 -07:00
jkleint
17be26165d Relax type of TestCase.assertCountEqual() params from Sequence to Iterable (#1006)
The stubs for `unittest.TestCase.assertCountEqual()` specify the parameters are Sequences; in fact the method works fine with Iterables, as the first thing the method does is convert them to lists.  [1]  The docs do say sequences, but it appears there is no reason they cannot be Iterables.

[1]: https://github.com/python/cpython/blob/master/Lib/unittest/case.py#L1156
2017-03-15 22:25:20 -07:00
Sebastian Meßmer
85866fe1b9 Fix unittest/mock.pyi (#973)
* Fix unittest/mock.pyi

Add a lot of missing types

* Fix formatting

* Make two and from_kall bool

* Further style fixes

* style fixes
2017-03-08 06:50:28 -08:00
Eric Moyer
62e57618d9 Match assertIsInstance signature with isinstance (#802) 2017-01-09 09:23:46 -08:00
Guido van Rossum
b78eb48b26 Make unittest.removeHandler() an overloaded function.
See https://docs.python.org/3/library/unittest.html#unittest.removeHandler

- Without args it removes the signal handler.
- With a function arg it is a test decorator that temporarily removes
  the handler while the test is running.
2017-01-03 10:15:30 -08:00
Guido van Rossum
94641f5a84 Revert "Make all single-constraint TypeVars to use bounds" (#806)
Reverts python/typeshed#804.

Reason: until python/mypy#1551 is fixed this gives an error whenever @skip() is used.

Specifically see https://github.com/python/typeshed/pull/804#issuecomment-269926655.
2017-01-01 16:35:50 -08:00
Michael Lee
b46366e77d Make all single-constraint TypeVars to use bounds
According to the documentation in the typing module, TypeVars cannot
have only a single constraint. Attempting to do so will actually result
in an exception at runtime. (However, this error is currently ignored
by mypy -- see https://github.com/python/mypy/pull/2626 for a related
pending pull request).

This commit changes all instances of TypeVars using a single constraint
(e.g. `T = TypeVar('T', Foo)`) to use bounds instead (e.g.
`T = TypeVar('T', bound=Foo)`.

This seems to be the correct fix for plistlib after reading the module
docs, but it's less obvious this is correct for unittest. The unittest
module originally had `_FT = TypeVar('_FT', Callable[[Any], Any])` -- an
alternative fix would have been to do `_FT = Callable[[Any], Any]`.

Although I'm not entirely sure what it means to have a bound be a
Callable, I decided to make the assumption that the original authors
probably meant to use TypeVars instead of type aliases for a reason
(possibly to handle classes implementing `__call__`?)
2017-01-01 11:34:19 -08:00