Skip to content

Commit

Permalink
Move/refactor map tests
Browse files Browse the repository at this point in the history
- Move and refactor test_map.py
- Bump Python dependency to 3.9
- Use latest flake8 revision
  • Loading branch information
argysamo committed Apr 17, 2024
1 parent 6cc4666 commit 9af693c
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 469 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 7.0.0
hooks:
- id: flake8
args: ['--select=E501']
Expand Down
Empty file removed flask_googlemaps/tests/__init__.py
Empty file.
44 changes: 0 additions & 44 deletions flask_googlemaps/tests/test_map.py

This file was deleted.

576 changes: 178 additions & 398 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ packages = [
include = ["flask_googlemaps/py.typed"]

[tool.poetry.dependencies]
python = ">=3.8"
python = ">=3.9"
flask = ">=3.0.3"
pre-commit = "3.7.0"
mkdocs = "^1.5.3"
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7
3.9
51 changes: 51 additions & 0 deletions tests/test_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import Dict, List, Any

import pytest

from flask_googlemaps import Map


@pytest.fixture
def map_properties() -> Dict[str, Any]:
return dict(identifier="gmap",
varname="gmap",
lat=37.4419,
lng=-122.1419)


@pytest.fixture
def markers() -> List[Dict]:
return [
{
"content": {"icon_url": "http://maps.google.com/"
"mapfiles/ms/icons/green-dot.png"},
"latitude": 37.4419,
"longitude": -122.1419,
"infobox": "<b>Hello World</b>",
},
{
"latitude": 37.4300,
"longitude": -122.1400,
"infobox": "<b>Hello World from other place</b>",
"content": {
"border_color": "",
"glyph_colors": "",
"background": "",
"glyph": "",
"scale": 2.0,
}
},
]


def test_map_markers(markers: List[Dict], map_properties):
assert len(Map(markers=markers, **map_properties).markers) == 2


def test_map_markers_expected_errors(markers: List[Dict], map_properties):
markers.append({"latitude": -1, "longitude": 250})
with pytest.raises(AttributeError) as exception_info:
Map(markers=markers, **map_properties)
assert str(exception_info.value) == (
"Longitude must be between -180 and 180 degrees inclusive."
)
28 changes: 4 additions & 24 deletions tests/test_marker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List, Dict

import pytest

from flask_googlemaps.marker import Marker
Expand All @@ -23,31 +21,13 @@ def marker_pin_url() -> Marker:
longitude=-122.1419,
content={
"icon_url": "https://developers.google.com/maps/"
"documentation/javascript/examples/"
"full/images/beachflag.png"
"documentation/javascript/examples/"
"full/images/beachflag.png"
},
infobox="<b>Hello World</b>",
)


@pytest.fixture
def markers() -> List[Dict]:
return [
{
"icon": "http://maps.google.com/mapfiles/ms/icons/green-dot.png",
"latitude": 37.4419,
"longitude": -122.1419,
"infobox": "<b>Hello World</b>",
},
{
"latitude": 37.4300,
"longitude": -122.1400,
"infobox": "<b>Hello World from other place</b>",
"label": "1",
},
]


def test_marker_without_lat_long():
with pytest.raises(TypeError):
Marker()
Expand All @@ -57,15 +37,15 @@ def test_marker_with_wrong_latitude():
with pytest.raises(AttributeError) as exception_info:
Marker(latitude=150, longitude=150)
assert str(exception_info.value) == (
"Latitude must be between " "-90 and 90 degrees inclusive."
"Latitude must be between -90 and 90 degrees inclusive."
)


def test_marker_with_wrong_longitude():
with pytest.raises(AttributeError) as exception_info:
Marker(latitude=90, longitude=-190)
assert str(exception_info.value) == (
"Longitude must be between " "-180 and 180 degrees inclusive."
"Longitude must be between -180 and 180 degrees inclusive."
)


Expand Down

0 comments on commit 9af693c

Please sign in to comment.