Skip to content

Commit

Permalink
strict mypy for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Jan 18, 2021
1 parent 32f2ab4 commit 4d3f186
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
additional_dependencies: [-e, 'git+git://github.com/pycqa/pyflakes.git@1911c20#egg=pyflakes']

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.781
rev: v0.790
hooks:
- id: mypy
args: [--strict]
1 change: 0 additions & 1 deletion .stubs/pytest.pyi

This file was deleted.

2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ black
coveralls
flake8
isort~=5.0
mypy==0.781
mypy==0.790
nox
pre-commit
pyflakes
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from omegaconf.basecontainer import BaseContainer


@pytest.fixture(scope="function") # type: ignore
@pytest.fixture(scope="function")
def restore_resolvers() -> Any:
"""
A fixture to restore singletons state after this the function.
Expand Down
4 changes: 2 additions & 2 deletions tests/examples/test_postponed_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import pytest


@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7") # type: ignore
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7")
def test_simple_types_class_postponed() -> None:
# import from a module which has `from __future__ import annotations`
from .dataclass_postponed_annotations import simple_types_class

simple_types_class()


@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7") # type: ignore
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7")
def test_conversions_postponed() -> None:
# import from a module which has `from __future__ import annotations`
from .dataclass_postponed_annotations import conversions
Expand Down
18 changes: 9 additions & 9 deletions tests/structured_conf/test_structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def validate(cfg: DictConfig) -> None:
conf = OmegaConf.structured(module.ConfigWithDict())
validate(conf)

@pytest.mark.parametrize( # type:ignore
@pytest.mark.parametrize(
"tested_type,assignment_data, init_dict",
[
# Use class to build config
Expand Down Expand Up @@ -331,7 +331,7 @@ def validate(input_: Any, expected: Any) -> None:
validate(input_class, input_class())
validate(input_class(**init_dict), input_class(**init_dict))

@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"input_init, expected_init",
[
# attr class as class
Expand Down Expand Up @@ -403,7 +403,7 @@ def test_interpolation(self, class_type: str) -> Any:
assert type(conf.z1) == int
assert type(conf.z2) == str

@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"tested_type",
[
"BoolOptional",
Expand Down Expand Up @@ -575,9 +575,7 @@ def test_typed_list_value_error(self, class_type: str) -> None:
with pytest.raises(ValidationError):
OmegaConf.structured(input_)

@pytest.mark.parametrize( # type: ignore
"example", ["ListExamples", "TupleExamples"]
)
@pytest.mark.parametrize("example", ["ListExamples", "TupleExamples"])
def test_list_examples(self, class_type: str, example: str) -> None:
module: Any = import_module(class_type)
input_ = getattr(module, example)
Expand Down Expand Up @@ -783,7 +781,9 @@ def test_set_list_correct_type(self, class_type: str) -> None:
assert cfg.list == value
assert cfg.tuple == value

@pytest.mark.parametrize("value", [1, True, "str", 3.1415, ["foo", True, 1.2], User()]) # type: ignore
@pytest.mark.parametrize(
"value", [1, True, "str", 3.1415, ["foo", True, 1.2], User()]
)
def test_assign_wrong_type_to_list(self, class_type: str, value: Any) -> None:
module: Any = import_module(class_type)
cfg = OmegaConf.structured(module.ListClass)
Expand All @@ -793,7 +793,7 @@ def test_assign_wrong_type_to_list(self, class_type: str, value: Any) -> None:
cfg.tuple = value
assert cfg == OmegaConf.structured(module.ListClass)

@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"value",
[
1,
Expand Down Expand Up @@ -1090,7 +1090,7 @@ def test_merge_into_none_dict(self, class_type: str) -> None:

assert OmegaConf.merge(cfg, cfg) == cfg

@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"update_value,expected",
[
pytest.param([], {"list": []}, id="empty"),
Expand Down
46 changes: 23 additions & 23 deletions tests/test_base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from . import Color, StructuredWithMissing, User, does_not_raise


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"input_, key, value, expected",
[
# dict
Expand All @@ -49,7 +49,7 @@ def test_set_value(
assert c == expected


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"input_, key, value",
[
# dict
Expand All @@ -64,7 +64,7 @@ def test_set_value_validation_fail(input_: Any, key: Any, value: Any) -> None:
c[key] = value


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"input_, key, value",
[
# dict
Expand All @@ -82,7 +82,7 @@ def test_replace_value_node_type_with_another(
assert c[key] == value._value()


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"input_",
[
pytest.param([1, 2, 3], id="list"),
Expand Down Expand Up @@ -112,7 +112,7 @@ def assert_container_with_primitives(item: Any) -> None:
assert_container_with_primitives(res)


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"cfg,ex_false,ex_true",
[
pytest.param(
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_exclude_structured_configs(cfg: Any, ex_false: Any, ex_true: Any) -> No
assert ret1 == ex_true


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src, expected, expected_with_resolve",
[
pytest.param([], None, None, id="empty_list"),
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_string_interpolation_with_readonly_parent() -> None:
}


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src,expected",
[
pytest.param(DictConfig(content="${bar}"), "${bar}", id="DictConfig"),
Expand All @@ -235,7 +235,7 @@ def test_to_container_missing_inter_no_resolve(src: Any, expected: Any) -> None:
assert res == expected


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"input_, is_empty",
[
([], True),
Expand All @@ -249,8 +249,8 @@ def test_empty(input_: Any, is_empty: bool) -> None:
assert c.is_empty() == is_empty


@pytest.mark.parametrize("func", [str, repr]) # type: ignore
@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize("func", [str, repr])
@pytest.mark.parametrize(
"input_, expected",
[
pytest.param([], "[]", id="list"),
Expand All @@ -277,7 +277,7 @@ def test_str(func: Any, input_: Any, expected: str) -> None:
assert string == expected


@pytest.mark.parametrize("flag", ["readonly", "struct"]) # type: ignore
@pytest.mark.parametrize("flag", ["readonly", "struct"])
def test_flag_dict(flag: str) -> None:
c = OmegaConf.create()
assert c._get_flag(flag) is None
Expand All @@ -289,7 +289,7 @@ def test_flag_dict(flag: str) -> None:
assert c._get_flag(flag) is None


@pytest.mark.parametrize("flag", ["readonly", "struct"]) # type: ignore
@pytest.mark.parametrize("flag", ["readonly", "struct"])
def test_freeze_nested_dict(flag: str) -> None:
c = OmegaConf.create(dict(a=dict(b=2)))
assert not c._get_flag(flag)
Expand Down Expand Up @@ -393,15 +393,15 @@ def test_deepcopy_and_merge_and_flags() -> None:
OmegaConf.merge(c2, OmegaConf.from_dotlist(["dataset.bad_key=yes"]))


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"cfg", [ListConfig(element_type=int, content=[]), DictConfig(content={})]
)
def test_deepcopy_preserves_container_type(cfg: Container) -> None:
cp: Container = copy.deepcopy(cfg)
assert cp._metadata.element_type == cfg._metadata.element_type


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src, flag_name, func, expectation",
[
pytest.param(
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_multiple_flags_override() -> None:
c.foo = 20


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src, func, expectation",
[
({}, lambda c: c.__setitem__("foo", 1), raises(ReadonlyConfigError)),
Expand All @@ -477,7 +477,7 @@ def test_read_write_override(src: Any, func: Any, expectation: Any) -> None:
func(c)


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"string, tokenized",
[
("dog,cat", ["dog", "cat"]),
Expand All @@ -497,7 +497,7 @@ def test_tokenize_with_escapes(string: str, tokenized: List[str]) -> None:
assert OmegaConf._tokenize_args(string) == tokenized


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src, func, expectation",
[({}, lambda c: c.__setattr__("foo", 1), raises(AttributeError))],
)
Expand All @@ -513,7 +513,7 @@ def test_struct_override(src: Any, func: Any, expectation: Any) -> None:
func(c)


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"flag_name,ctx", [("struct", open_dict), ("readonly", read_write)]
)
def test_open_dict_restore(flag_name: str, ctx: Any) -> None:
Expand All @@ -532,7 +532,7 @@ def test_open_dict_restore(flag_name: str, ctx: Any) -> None:

@pytest.mark.parametrize("copy_method", [lambda x: copy.copy(x), lambda x: x.copy()])
class TestCopy:
@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src", [[], [1, 2], ["a", "b", "c"], {}, {"a": "b"}, {"a": {"b": []}}]
)
def test_copy(self, copy_method: Any, src: Any) -> None:
Expand All @@ -541,7 +541,7 @@ def test_copy(self, copy_method: Any, src: Any) -> None:
assert id(src) != id(cp)
assert src == cp

@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"src,interpolating_key,interpolated_key",
[([1, 2, "${0}"], 2, 0), ({"a": 10, "b": "${a}"}, "b", "a")],
)
Expand Down Expand Up @@ -575,7 +575,7 @@ def test_not_implemented() -> None:
OmegaConf()


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"query, result",
[
("a", "a"),
Expand Down Expand Up @@ -605,7 +605,7 @@ def test_omegaconf_create() -> None:
assert OmegaConf.create(10) # type: ignore


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"parent, key, value, expected",
[
([10, 11], 0, ["a", "b"], [["a", "b"], 11]),
Expand All @@ -622,7 +622,7 @@ def test_assign(parent: Any, key: Union[str, int], value: Any, expected: Any) ->
assert c == expected


@pytest.mark.parametrize( # type: ignore
@pytest.mark.parametrize(
"cfg, key, expected",
[
# dict
Expand Down
Loading

0 comments on commit 4d3f186

Please sign in to comment.