From 2eee51f06ba8866ac675454a799732be463652f7 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 13:03:33 +0100 Subject: [PATCH 01/12] Add simple test which checks type annotations are correct. --- setup.py | 8 +++++++- tests/type-hinting/test_test_types.yml | 5 ----- tests/type-hinting/test_types.yml | 10 ++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) delete mode 100644 tests/type-hinting/test_test_types.yml create mode 100644 tests/type-hinting/test_types.yml diff --git a/setup.py b/setup.py index e9dfa39a..9f1bdef0 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,13 @@ def read(fname): assert __version__ is not None REQUIREMENTS_DOCS = ["sphinx~=3.0", "alabaster~=0.7"] -TESTS_BASIC = ["pytest>=5.0", "pytest-sugar", "coverage"] +TESTS_BASIC = [ + "pytest>=5.0", + "pytest-sugar", + "coverage", + "pytest-mypy-plugins; python_version<'3.10'", + "types-mock", +] TESTS_NUMPY = ["numpy"] DEV_TOOLS = [ "towncrier", diff --git a/tests/type-hinting/test_test_types.yml b/tests/type-hinting/test_test_types.yml deleted file mode 100644 index cfe99854..00000000 --- a/tests/type-hinting/test_test_types.yml +++ /dev/null @@ -1,5 +0,0 @@ -- case: equal_to_ignoring_case - main: | - from hamcrest.library.text.isequal_ignoring_case import equal_to_ignoring_case - - reveal_type(equal_to_ignoring_case("")) # N: Revealed type is "hamcrest.core.matcher.Matcher[builtins.str]" diff --git a/tests/type-hinting/test_types.yml b/tests/type-hinting/test_types.yml new file mode 100644 index 00000000..8a61a390 --- /dev/null +++ b/tests/type-hinting/test_types.yml @@ -0,0 +1,10 @@ +- case: equal_to_ignoring_case + main: | + from hamcrest import equal_to_ignoring_case + + reveal_type(equal_to_ignoring_case("")) + equal_to_ignoring_case("") + equal_to_ignoring_case(99) + out: | + main:3: note: Revealed type is "hamcrest.core.matcher.Matcher[builtins.str]" + main:5: error: Argument 1 to "equal_to_ignoring_case" has incompatible type "int"; expected "str" From bdf1d7e395d782ac153289d2cb7479ed65d78bb4 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 13:23:15 +0100 Subject: [PATCH 02/12] Add type annotation test for assert_that() --- tests/type-hinting/test_types.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/type-hinting/test_types.yml b/tests/type-hinting/test_types.yml index 8a61a390..5a2b5514 100644 --- a/tests/type-hinting/test_types.yml +++ b/tests/type-hinting/test_types.yml @@ -1,3 +1,13 @@ +- case: assert_that + main: | + from hamcrest import assert_that, instance_of, starts_with + + assert_that("string", starts_with("str")) + assert_that("str", instance_of(str)) + assert_that(99, starts_with("str")) + out: | + main:5: error: Cannot infer type argument 1 of "assert_that" + - case: equal_to_ignoring_case main: | from hamcrest import equal_to_ignoring_case From 2c6bb9fef79b8bdcda1238aeb3b1a09675d3cb77 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 13:26:21 +0100 Subject: [PATCH 03/12] Apply some organisation to type annotation tests --- tests/type-hinting/test_assert_that.yml | 9 +++++++++ .../test_equal_to_ignoring_case.yml} | 10 ---------- 2 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 tests/type-hinting/test_assert_that.yml rename tests/type-hinting/{test_types.yml => text/test_equal_to_ignoring_case.yml} (56%) diff --git a/tests/type-hinting/test_assert_that.yml b/tests/type-hinting/test_assert_that.yml new file mode 100644 index 00000000..1a8f8a3d --- /dev/null +++ b/tests/type-hinting/test_assert_that.yml @@ -0,0 +1,9 @@ +- case: assert_that + main: | + from hamcrest import assert_that, instance_of, starts_with + + assert_that("string", starts_with("str")) + assert_that("str", instance_of(str)) + assert_that(99, starts_with("str")) + out: | + main:5: error: Cannot infer type argument 1 of "assert_that" diff --git a/tests/type-hinting/test_types.yml b/tests/type-hinting/text/test_equal_to_ignoring_case.yml similarity index 56% rename from tests/type-hinting/test_types.yml rename to tests/type-hinting/text/test_equal_to_ignoring_case.yml index 5a2b5514..8a61a390 100644 --- a/tests/type-hinting/test_types.yml +++ b/tests/type-hinting/text/test_equal_to_ignoring_case.yml @@ -1,13 +1,3 @@ -- case: assert_that - main: | - from hamcrest import assert_that, instance_of, starts_with - - assert_that("string", starts_with("str")) - assert_that("str", instance_of(str)) - assert_that(99, starts_with("str")) - out: | - main:5: error: Cannot infer type argument 1 of "assert_that" - - case: equal_to_ignoring_case main: | from hamcrest import equal_to_ignoring_case From c6fd725f2674cdde0847cf801116fc580aa258ae Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 13:44:16 +0100 Subject: [PATCH 04/12] Add type annotation test for empty() --- tests/type-hinting/{ => core}/test_assert_that.yml | 0 tests/type-hinting/library/collection/test_empty.yml | 8 ++++++++ .../{ => library}/text/test_equal_to_ignoring_case.yml | 0 3 files changed, 8 insertions(+) rename tests/type-hinting/{ => core}/test_assert_that.yml (100%) create mode 100644 tests/type-hinting/library/collection/test_empty.yml rename tests/type-hinting/{ => library}/text/test_equal_to_ignoring_case.yml (100%) diff --git a/tests/type-hinting/test_assert_that.yml b/tests/type-hinting/core/test_assert_that.yml similarity index 100% rename from tests/type-hinting/test_assert_that.yml rename to tests/type-hinting/core/test_assert_that.yml diff --git a/tests/type-hinting/library/collection/test_empty.yml b/tests/type-hinting/library/collection/test_empty.yml new file mode 100644 index 00000000..77cb2d2a --- /dev/null +++ b/tests/type-hinting/library/collection/test_empty.yml @@ -0,0 +1,8 @@ +- case: empty + main: | + from hamcrest import assert_that, empty + + assert_that([], empty()) + assert_that(99, empty()) + out: | + main:4: error: Cannot infer type argument 1 of "assert_that" diff --git a/tests/type-hinting/text/test_equal_to_ignoring_case.yml b/tests/type-hinting/library/text/test_equal_to_ignoring_case.yml similarity index 100% rename from tests/type-hinting/text/test_equal_to_ignoring_case.yml rename to tests/type-hinting/library/text/test_equal_to_ignoring_case.yml From affebb9d6d7f116e82685c6934225da3fa1f10f3 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 14:26:51 +0100 Subject: [PATCH 05/12] Recreated #178 --- tests/type-hinting/library/collection/test_empty.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/type-hinting/library/collection/test_empty.yml b/tests/type-hinting/library/collection/test_empty.yml index 77cb2d2a..62442e44 100644 --- a/tests/type-hinting/library/collection/test_empty.yml +++ b/tests/type-hinting/library/collection/test_empty.yml @@ -1,8 +1,12 @@ - case: empty main: | - from hamcrest import assert_that, empty + from hamcrest import assert_that, is_, empty assert_that([], empty()) assert_that(99, empty()) + assert_that([], is_(empty())) + assert_that(99, is_(empty())) + is_(empty()) out: | main:4: error: Cannot infer type argument 1 of "assert_that" + main:6: error: Cannot infer type argument 1 of "assert_that" From 379aa114881e5df64d9946ae81b20c25bc883928 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 15:39:35 +0100 Subject: [PATCH 06/12] Skip #178 test, since we know if fails for now. --- tests/type-hinting/library/collection/test_empty.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/type-hinting/library/collection/test_empty.yml b/tests/type-hinting/library/collection/test_empty.yml index 62442e44..a2f75ece 100644 --- a/tests/type-hinting/library/collection/test_empty.yml +++ b/tests/type-hinting/library/collection/test_empty.yml @@ -1,4 +1,5 @@ - case: empty + skip: True main: | from hamcrest import assert_that, is_, empty From bce1ec8e3ea3596e799888813adeaae818176e77 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Wed, 11 Aug 2021 10:53:41 +0100 Subject: [PATCH 07/12] Use comment assertions, and pin versions. Add test for is_() --- setup.py | 2 +- tests/type-hinting/core/core/test_is.yml | 10 ++++++++++ tests/type-hinting/library/collection/test_empty.yml | 9 +-------- 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 tests/type-hinting/core/core/test_is.yml diff --git a/setup.py b/setup.py index 9f1bdef0..6f23aebc 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ def read(fname): "pytest>=5.0", "pytest-sugar", "coverage", - "pytest-mypy-plugins; python_version<'3.10'", + "pytest-mypy-plugins~=1.7; python_version<'3.10'", "types-mock", ] TESTS_NUMPY = ["numpy"] diff --git a/tests/type-hinting/core/core/test_is.yml b/tests/type-hinting/core/core/test_is.yml new file mode 100644 index 00000000..559be681 --- /dev/null +++ b/tests/type-hinting/core/core/test_is.yml @@ -0,0 +1,10 @@ +- case: is + main: | + from hamcrest import assert_that, is_, empty + from typing import Any, Sequence + + a: Sequence[Any] = [] + b = 99 + + assert_that(a, is_(empty())) + assert_that(b, is_(empty())) # E: Cannot infer type argument 1 of "assert_that" diff --git a/tests/type-hinting/library/collection/test_empty.yml b/tests/type-hinting/library/collection/test_empty.yml index a2f75ece..3c10c43a 100644 --- a/tests/type-hinting/library/collection/test_empty.yml +++ b/tests/type-hinting/library/collection/test_empty.yml @@ -1,13 +1,6 @@ - case: empty - skip: True main: | from hamcrest import assert_that, is_, empty assert_that([], empty()) - assert_that(99, empty()) - assert_that([], is_(empty())) - assert_that(99, is_(empty())) - is_(empty()) - out: | - main:4: error: Cannot infer type argument 1 of "assert_that" - main:6: error: Cannot infer type argument 1 of "assert_that" + assert_that(99, empty()) # E: Cannot infer type argument 1 of "assert_that" \ No newline at end of file From c72201de190d1da553ac40da77c9230f3c21f98e Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Wed, 11 Aug 2021 11:03:18 +0100 Subject: [PATCH 08/12] Fix is_() type annotations. --- tests/type-hinting/test_test_types.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/type-hinting/test_test_types.yml diff --git a/tests/type-hinting/test_test_types.yml b/tests/type-hinting/test_test_types.yml new file mode 100644 index 00000000..e69de29b From abbd9b045f85cdf564a78e787a47b87e3d4bac64 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 13:03:33 +0100 Subject: [PATCH 09/12] Add simple test which checks type annotations are correct. --- setup.py | 8 +------- tests/type-hinting/test_types.yml | 10 ++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 tests/type-hinting/test_types.yml diff --git a/setup.py b/setup.py index 6f23aebc..e9dfa39a 100755 --- a/setup.py +++ b/setup.py @@ -32,13 +32,7 @@ def read(fname): assert __version__ is not None REQUIREMENTS_DOCS = ["sphinx~=3.0", "alabaster~=0.7"] -TESTS_BASIC = [ - "pytest>=5.0", - "pytest-sugar", - "coverage", - "pytest-mypy-plugins~=1.7; python_version<'3.10'", - "types-mock", -] +TESTS_BASIC = ["pytest>=5.0", "pytest-sugar", "coverage"] TESTS_NUMPY = ["numpy"] DEV_TOOLS = [ "towncrier", diff --git a/tests/type-hinting/test_types.yml b/tests/type-hinting/test_types.yml new file mode 100644 index 00000000..8a61a390 --- /dev/null +++ b/tests/type-hinting/test_types.yml @@ -0,0 +1,10 @@ +- case: equal_to_ignoring_case + main: | + from hamcrest import equal_to_ignoring_case + + reveal_type(equal_to_ignoring_case("")) + equal_to_ignoring_case("") + equal_to_ignoring_case(99) + out: | + main:3: note: Revealed type is "hamcrest.core.matcher.Matcher[builtins.str]" + main:5: error: Argument 1 to "equal_to_ignoring_case" has incompatible type "int"; expected "str" From 6fa9df178f7b14eca0d175494b30a3bbb509d48f Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 16 Jul 2021 13:03:33 +0100 Subject: [PATCH 10/12] Add simple test which checks type annotations are correct. --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e9dfa39a..9f1bdef0 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,13 @@ def read(fname): assert __version__ is not None REQUIREMENTS_DOCS = ["sphinx~=3.0", "alabaster~=0.7"] -TESTS_BASIC = ["pytest>=5.0", "pytest-sugar", "coverage"] +TESTS_BASIC = [ + "pytest>=5.0", + "pytest-sugar", + "coverage", + "pytest-mypy-plugins; python_version<'3.10'", + "types-mock", +] TESTS_NUMPY = ["numpy"] DEV_TOOLS = [ "towncrier", From dc1ae8d6c5dfbd683bc87fdb7dcf982e384e184a Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Wed, 11 Aug 2021 15:31:37 +0100 Subject: [PATCH 11/12] Remove duplicate and empty tests. --- tests/type-hinting/test_test_types.yml | 0 tests/type-hinting/test_types.yml | 10 ---------- 2 files changed, 10 deletions(-) delete mode 100644 tests/type-hinting/test_test_types.yml delete mode 100644 tests/type-hinting/test_types.yml diff --git a/tests/type-hinting/test_test_types.yml b/tests/type-hinting/test_test_types.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/type-hinting/test_types.yml b/tests/type-hinting/test_types.yml deleted file mode 100644 index 8a61a390..00000000 --- a/tests/type-hinting/test_types.yml +++ /dev/null @@ -1,10 +0,0 @@ -- case: equal_to_ignoring_case - main: | - from hamcrest import equal_to_ignoring_case - - reveal_type(equal_to_ignoring_case("")) - equal_to_ignoring_case("") - equal_to_ignoring_case(99) - out: | - main:3: note: Revealed type is "hamcrest.core.matcher.Matcher[builtins.str]" - main:5: error: Argument 1 to "equal_to_ignoring_case" has incompatible type "int"; expected "str" From 9ad6f466cae86de294cbfc6c714ccb9d82a281dd Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Wed, 11 Aug 2021 16:01:32 +0100 Subject: [PATCH 12/12] Works on Python 3.10 now, I think. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9f1bdef0..45bac846 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ def read(fname): "pytest>=5.0", "pytest-sugar", "coverage", - "pytest-mypy-plugins; python_version<'3.10'", + "pytest-mypy-plugins", "types-mock", ] TESTS_NUMPY = ["numpy"]