|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | import inspect |
5 | | -import warnings |
6 | 5 | from typing import Any, Dict, NamedTuple, Optional, Tuple, Type |
7 | 6 |
|
8 | 7 | from decoy.spy_core import SpyCore, BoundArgs |
9 | | -from decoy.warnings import IncorrectCallWarning, MissingSpecAttributeWarning |
| 8 | +from decoy.warnings import IncorrectCallWarning |
10 | 9 | from .fixtures import ( |
11 | 10 | SomeClass, |
12 | 11 | SomeAsyncClass, |
@@ -151,6 +150,14 @@ class GetSignatureSpec(NamedTuple): |
151 | 150 | ), |
152 | 151 | expected_signature=None, |
153 | 152 | ), |
| 153 | + GetSignatureSpec( |
| 154 | + subject=( |
| 155 | + SpyCore(source=SomeNestedClass, name=None) |
| 156 | + .create_child_core("union_child", is_async=False) |
| 157 | + .create_child_core("foo", is_async=False) |
| 158 | + ), |
| 159 | + expected_signature=None, |
| 160 | + ), |
154 | 161 | GetSignatureSpec( |
155 | 162 | subject=( |
156 | 163 | SpyCore(source=SomeNestedClass, name=None) |
@@ -256,6 +263,40 @@ class GetSignatureSpec(NamedTuple): |
256 | 263 | return_annotation=None, |
257 | 264 | ), |
258 | 265 | ), |
| 266 | + GetSignatureSpec( |
| 267 | + subject=( |
| 268 | + SpyCore(source=SomeNestedClass, name=None) |
| 269 | + .create_child_core("optional_child", is_async=False) |
| 270 | + .create_child_core("foo", is_async=False) |
| 271 | + ), |
| 272 | + expected_signature=inspect.Signature( |
| 273 | + parameters=[ |
| 274 | + inspect.Parameter( |
| 275 | + name="val", |
| 276 | + kind=inspect.Parameter.POSITIONAL_OR_KEYWORD, |
| 277 | + annotation=str, |
| 278 | + ) |
| 279 | + ], |
| 280 | + return_annotation=str, |
| 281 | + ), |
| 282 | + ), |
| 283 | + GetSignatureSpec( |
| 284 | + subject=( |
| 285 | + SpyCore(source=SomeNestedClass, name=None) |
| 286 | + .create_child_core("union_none_child", is_async=False) |
| 287 | + .create_child_core("foo", is_async=False) |
| 288 | + ), |
| 289 | + expected_signature=inspect.Signature( |
| 290 | + parameters=[ |
| 291 | + inspect.Parameter( |
| 292 | + name="val", |
| 293 | + kind=inspect.Parameter.POSITIONAL_OR_KEYWORD, |
| 294 | + annotation=str, |
| 295 | + ) |
| 296 | + ], |
| 297 | + return_annotation=str, |
| 298 | + ), |
| 299 | + ), |
259 | 300 | ], |
260 | 301 | ) |
261 | 302 | def test_get_signature( |
@@ -440,70 +481,3 @@ def test_warn_if_called_incorrectly() -> None: |
440 | 481 |
|
441 | 482 | with pytest.warns(IncorrectCallWarning, match="missing a required argument"): |
442 | 483 | subject.bind_args(wrong_arg_name="1") |
443 | | - |
444 | | - |
445 | | -def test_warn_if_spec_does_not_have_method() -> None: |
446 | | - """It should trigger a warning if bound_args is called incorrectly.""" |
447 | | - class_subject = SpyCore(source=SomeClass, name=None) |
448 | | - nested_class_subject = SpyCore(source=SomeNestedClass, name=None) |
449 | | - func_subject = SpyCore(source=some_func, name=None) |
450 | | - specless_subject = SpyCore(source=None, name="anonymous") |
451 | | - |
452 | | - # specless mocks and correct usage should not warn |
453 | | - with warnings.catch_warnings(): |
454 | | - warnings.simplefilter("error") |
455 | | - specless_subject.create_child_core("foo", False) |
456 | | - |
457 | | - # proper class usage should not warn |
458 | | - with warnings.catch_warnings(): |
459 | | - warnings.simplefilter("error") |
460 | | - class_subject.create_child_core("foo", False) |
461 | | - |
462 | | - # property access without types should not warn |
463 | | - with warnings.catch_warnings(): |
464 | | - warnings.simplefilter("error") |
465 | | - class_subject.create_child_core("mystery_property", False) |
466 | | - |
467 | | - # property access should be allowed through optionals |
468 | | - with warnings.catch_warnings(): |
469 | | - warnings.simplefilter("error") |
470 | | - parent = nested_class_subject.create_child_core("optional_child", False) |
471 | | - parent.create_child_core("primitive_property", False) |
472 | | - |
473 | | - # property access should be allowed through None unions |
474 | | - with warnings.catch_warnings(): |
475 | | - warnings.simplefilter("error") |
476 | | - parent = nested_class_subject.create_child_core("union_none_child", False) |
477 | | - parent.create_child_core("primitive_property", False) |
478 | | - |
479 | | - # property access should not be checked through unions |
480 | | - with warnings.catch_warnings(): |
481 | | - warnings.simplefilter("error") |
482 | | - parent = nested_class_subject.create_child_core("union_child", False) |
483 | | - parent.create_child_core("who_knows", False) |
484 | | - |
485 | | - # incorrect class usage should warn |
486 | | - with pytest.warns( |
487 | | - MissingSpecAttributeWarning, match="has no attribute 'this_is_wrong'" |
488 | | - ): |
489 | | - class_subject.create_child_core("this_is_wrong", False) |
490 | | - |
491 | | - # incorrect function usage should warn |
492 | | - with pytest.warns( |
493 | | - MissingSpecAttributeWarning, match="has no attribute 'this_is_wrong'" |
494 | | - ): |
495 | | - func_subject.create_child_core("this_is_wrong", False) |
496 | | - |
497 | | - # incorrect nested property usage should warn |
498 | | - with pytest.warns( |
499 | | - MissingSpecAttributeWarning, match="has no attribute 'this_is_wrong'" |
500 | | - ): |
501 | | - parent = nested_class_subject.create_child_core("optional_child", False) |
502 | | - parent.create_child_core("this_is_wrong", False) |
503 | | - |
504 | | - # incorrect nested property usage should warn |
505 | | - with pytest.warns( |
506 | | - MissingSpecAttributeWarning, match="has no attribute 'this_is_wrong'" |
507 | | - ): |
508 | | - parent = nested_class_subject.create_child_core("union_none_child", False) |
509 | | - parent.create_child_core("this_is_wrong", False) |
0 commit comments