Commit Graph

69 Commits

Author SHA1 Message Date
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
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