Skip to content

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
konradmalik committed Sep 13, 2021
1 parent 5c9c545 commit 2609851
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Forked repo

## Changed

- License to private
- mypy to 0.910
- mypy config and more strict checks

### Fixed

## [0.0.2] - 2021-05-01
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $(VENV_NAME)/bin/activate: test-requirements.txt requirements.txt setup.py
python -m virtualenv -p python3 $(VENV_NAME)
${PYTHON} -m pip install -U pip
${PYTHON} -m pip install -r test-requirements.txt -r requirements.txt
${PYTHON} -m mypy --install-types --non-interactive ${LINTED}
touch $(VENV_NAME)/bin/activate

clean:
Expand All @@ -23,7 +24,7 @@ clean:
lint: venv
${PYTHON} -m black ${LINTED}
${PYTHON} -m autoflake --in-place --recursive --remove-all-unused-imports ${LINTED}
${PYTHON} -m mypy --ignore-missing-imports --follow-imports=skip ${LINTED}
${PYTHON} -m mypy ${LINTED}

test: venv
${PYTHON} -m pytest tests --capture=no --verbose
Expand Down
10 changes: 10 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mypy]
follow_imports = skip
strict_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
disallow_any_generics = False
check_untyped_defs = True
no_implicit_reexport = True
disallow_untyped_defs = False
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pytest-cov>=2.8.1
black>=20.8b1
mypy>=0.790
mypy>=0.910
pytest>=6.2.0
autoflake>=1.4
twine>=3.4.1
5 changes: 4 additions & 1 deletion tests/test_scenes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import tempfile
from unittest.mock import patch, Mock
from typing import Callable
Expand Down Expand Up @@ -29,6 +30,7 @@ def test_get_redirection():
redirection = scenes._get_redirection(
"fake token", 1, "some artifact", scene_api_fun=_gen_mocked_scene_api(200)
)
assert redirection is not None
assert redirection.status == 200
assert redirection.geturl().startswith("http")

Expand Down Expand Up @@ -63,6 +65,7 @@ def test_download_scene_artifact():
bts = "abcd1234_%$#".encode()

with tempfile.TemporaryDirectory() as dir:
pdir = Path(dir)
with patch("py4envi.util.requests.get") as mock_get:
# Configure the mock to return a proper response
mock_get.return_value.ok = True
Expand All @@ -73,5 +76,5 @@ def test_download_scene_artifact():
}

# Call the service, which will send a request to the server.
path = scenes.download_scene_artifact(sa, dir)
path = scenes.download_scene_artifact(sa, pdir)
assert str(path).endswith(sa.file_name)
7 changes: 3 additions & 4 deletions tests/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,20 @@ def test_get_or_request_token():
tkn = token.get_or_request_token(
"", "", auth_api_fun=_gen_mocked_auth_api(test_token), force=True
)
assert tkn is not None
assert tkn == test_token

# we should get error because we are forcing
try:
tkn = token.get_or_request_token(
"", "", auth_api_fun=_gen_mocked_auth_api(None), force=True
)
failed = False
except BaseException:
tkn = None
assert tkn is None
failed = True
assert failed

# now just read that cached one
tkn = token.get_or_request_token(
"", "", auth_api_fun=_gen_mocked_auth_api(None), force=False
)
assert tkn is not None
assert tkn == test_token
6 changes: 4 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
import tempfile
from unittest.mock import patch, Mock
from py4envi import util
Expand All @@ -16,6 +17,7 @@ def test_filename_from_url():
def test_download():
bts = "abcd1234_%$#".encode()
with tempfile.TemporaryDirectory() as dir:
pdir = Path(dir)

with patch("py4envi.util.requests.get") as mock_get:
# Configure the mock to return a proper response
Expand All @@ -27,7 +29,7 @@ def test_download():
}

# Call the service, which will send a request to the server.
path = util.download("http://fake.pl/file.zip", dir)
path = util.download("http://fake.pl/file.zip", pdir)

assert str(path).endswith("file.zip")
with open(path, "rb") as f:
Expand All @@ -40,7 +42,7 @@ def test_download():
with open(path, "wb") as f:
f.write(bts[:2])

path = util.download("http://fake.pl/file.zip", dir)
path = util.download("http://fake.pl/file.zip", pdir)
assert str(path).endswith("file.zip")
with open(path, "rb") as f:
read_bts = f.read()
Expand Down

0 comments on commit 2609851

Please sign in to comment.