diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edbce9c051..ce6bba03fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,25 +1,39 @@ name: Test overpass-api-python-wrapper -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: + branches: + - main jobs: - build: + test: runs-on: ubuntu-latest + strategy: max-parallel: 5 matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - sudo apt-get install libgeos-dev - python -m pip install --upgrade pip - pip install tox tox-gh-actions - - name: Test with tox - run: tox \ No newline at end of file + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + + - name: Install system dependencies + run: sudo apt-get install -y libgeos-dev + + - name: Install project dependencies + run: poetry install --no-root --sync + + - name: Run tests with tox + run: poetry run tox diff --git a/.gitignore b/.gitignore index 3d2579d726..c276c9cc6a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ pip-log.txt docs/_build/ Pipfile.lock venv/ +.tox diff --git a/poetry.lock b/poetry.lock index 1a0f75940a..2cde21fd88 100644 --- a/poetry.lock +++ b/poetry.lock @@ -143,6 +143,24 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "deepdiff" +version = "7.0.1" +description = "Deep Difference and Search of any Python object/data. Recreate objects by adding adding deltas to each other." +optional = false +python-versions = ">=3.8" +files = [ + {file = "deepdiff-7.0.1-py3-none-any.whl", hash = "sha256:447760081918216aa4fd4ca78a4b6a848b81307b2ea94c810255334b759e1dc3"}, + {file = "deepdiff-7.0.1.tar.gz", hash = "sha256:260c16f052d4badbf60351b4f77e8390bee03a0b516246f6839bc813fb429ddf"}, +] + +[package.dependencies] +ordered-set = ">=4.1.0,<4.2.0" + +[package.extras] +cli = ["click (==8.1.7)", "pyyaml (==6.0.1)"] +optimize = ["orjson"] + [[package]] name = "distlib" version = "0.3.8" @@ -271,6 +289,20 @@ files = [ {file = "numpy-2.0.1.tar.gz", hash = "sha256:485b87235796410c3519a699cfe1faab097e509e90ebb05dcd098db2ae87e7b3"}, ] +[[package]] +name = "ordered-set" +version = "4.1.0" +description = "An OrderedSet is a custom MutableSet that remembers its order, so that every" +optional = false +python-versions = ">=3.7" +files = [ + {file = "ordered-set-4.1.0.tar.gz", hash = "sha256:694a8e44c87657c59292ede72891eb91d34131f6531463aab3009191c77364a8"}, + {file = "ordered_set-4.1.0-py3-none-any.whl", hash = "sha256:046e1132c71fcf3330438a539928932caf51ddbc582496833e23de611de14562"}, +] + +[package.extras] +dev = ["black", "mypy", "pytest"] + [[package]] name = "osm2geojson" version = "0.2.5" @@ -389,6 +421,23 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "requests-mock" +version = "1.12.1" +description = "Mock out responses from the requests package" +optional = false +python-versions = ">=3.5" +files = [ + {file = "requests-mock-1.12.1.tar.gz", hash = "sha256:e9e12e333b525156e82a3c852f22016b9158220d2f47454de9cae8a77d371401"}, + {file = "requests_mock-1.12.1-py2.py3-none-any.whl", hash = "sha256:b1e37054004cdd5e56c84454cc7df12b25f90f382159087f4b6915aaeef39563"}, +] + +[package.dependencies] +requests = ">=2.22,<3" + +[package.extras] +fixture = ["fixtures"] + [[package]] name = "shapely" version = "2.0.5" @@ -519,4 +568,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = ">3.9, <3.12" -content-hash = "6bd263541e92433bc8567ed5d8faf010a500b5d73f1ffe91959443f646a0b369" +content-hash = "cbde58fd145ca379e13dd16d277aa51a4bebe0eb205fb9e55909cf7ddad3b2cf" diff --git a/pyproject.toml b/pyproject.toml index da5e91dba2..0ac1685a41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,13 +13,13 @@ python = ">3.9, <3.12" osm2geojson = "^0.2.5" requests = "^2.32.3" -[tool.poetry.dev-dependencies] -pytest = "^7.4.0" -tox = "^4.6.3" - [tool.poetry.group.dev.dependencies] +pytest = "^7.4.0" geojson = "^3.1.0" +requests-mock = { extras = ["fixtures"], version = "^1.12.1" } +deepdiff = "^7.0.1" +tox = "^4.17.1" [build-system] -requires = ["poetry-core"] +requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 52a31908a6..0000000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest>=7.4.0 -requests-mock[fixture] -tox>=4.6.3 -geojson>=1.3.1 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 6a05501a0c..0000000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -osm2geojson>=0.1.30 -requests>=2.31.0 diff --git a/tests/example_live.json b/tests/example_live.json new file mode 100644 index 0000000000..14a785afbd --- /dev/null +++ b/tests/example_live.json @@ -0,0 +1,367 @@ +{ + "type": "FeatureCollection", + "generator": "overpass-turbo", + "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.", + "timestamp": "2024-08-10T18:01:43Z", + "features": [ + { + "type": "Feature", + "id": "relation/6518385", + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [-122.183933, 37.846772], + [-122.183935, 37.841137], + [-122.183929, 37.840341], + [-122.183949, 37.839595], + [-122.182912, 37.83957], + [-122.182634, 37.839717], + [-122.182271, 37.839908], + [-122.181039, 37.839916], + [-122.180953, 37.839917], + [-122.18098, 37.839502], + [-122.179526, 37.839474], + [-122.179458, 37.838394], + [-122.179246, 37.838281], + [-122.179015, 37.838187], + [-122.178398, 37.837974], + [-122.178218, 37.837895], + [-122.178038, 37.838142], + [-122.176957, 37.837722], + [-122.175136, 37.839844], + [-122.173416, 37.839848], + [-122.170366, 37.839856], + [-122.170393, 37.841024], + [-122.17167, 37.841556], + [-122.172363, 37.841828], + [-122.173039, 37.842167], + [-122.173059, 37.842199], + [-122.173359, 37.842656], + [-122.173667, 37.84333], + [-122.174148, 37.843785], + [-122.174239, 37.844001], + [-122.174198, 37.844895], + [-122.174197, 37.84491], + [-122.174198, 37.844938], + [-122.17421, 37.84505], + [-122.174244, 37.845431], + [-122.174278, 37.845781], + [-122.174374, 37.846768], + [-122.174381, 37.846909], + [-122.174897, 37.846908], + [-122.174886, 37.850508], + [-122.179469, 37.850483], + [-122.179472, 37.84959], + [-122.179485, 37.846769], + [-122.183933, 37.846772] + ] + ], + [ + [ + [-122.214506, 37.865654], + [-122.214739, 37.865305], + [-122.215062, 37.864823], + [-122.215317, 37.864443], + [-122.215441, 37.864258], + [-122.215644, 37.863955], + [-122.215787, 37.863741], + [-122.213781, 37.862786], + [-122.21353, 37.862666], + [-122.213115, 37.862469], + [-122.211992, 37.862088], + [-122.211749, 37.862006], + [-122.21111, 37.861842], + [-122.211011, 37.861928], + [-122.210872, 37.862025], + [-122.210717, 37.862148], + [-122.210538, 37.862304], + [-122.210372, 37.862476], + [-122.21023, 37.862636], + [-122.210112, 37.862792], + [-122.209981, 37.862994], + [-122.209885, 37.863179], + [-122.209807, 37.863371], + [-122.209741, 37.863566], + [-122.20969, 37.863783], + [-122.209659, 37.863971], + [-122.209651, 37.864191], + [-122.209649, 37.864426], + [-122.20983, 37.86445], + [-122.210077, 37.864798], + [-122.212723, 37.864933], + [-122.212632, 37.865082], + [-122.214506, 37.865654] + ] + ], + [ + [ + [-122.197877, 37.85778], + [-122.198009, 37.861454], + [-122.206689, 37.861446], + [-122.206636, 37.862631], + [-122.2088, 37.86268], + [-122.209006, 37.861648], + [-122.209036, 37.861483], + [-122.208942, 37.861471], + [-122.208703, 37.861442], + [-122.208394, 37.861405], + [-122.207189, 37.861261], + [-122.207248, 37.860891], + [-122.207408, 37.859896], + [-122.207766, 37.859935], + [-122.208188, 37.859981], + [-122.208941, 37.860063], + [-122.20885, 37.859909], + [-122.208785, 37.859769], + [-122.209453, 37.859626], + [-122.209757, 37.860235], + [-122.210262, 37.860607], + [-122.211345, 37.860794], + [-122.2115, 37.860812], + [-122.21206, 37.86088], + [-122.212933, 37.8612], + [-122.213738, 37.861522], + [-122.214499, 37.862013], + [-122.215336, 37.86253], + [-122.21633, 37.862981], + [-122.217, 37.862143], + [-122.218226, 37.863233], + [-122.21858, 37.863031], + [-122.21805, 37.862382], + [-122.217921, 37.862287], + [-122.217372, 37.861838], + [-122.217316, 37.861709], + [-122.217274, 37.861549], + [-122.217243, 37.861458], + [-122.217197, 37.861362], + [-122.217137, 37.861274], + [-122.217074, 37.861197], + [-122.216911, 37.86104], + [-122.21661, 37.860783], + [-122.216546, 37.860723], + [-122.216481, 37.860648], + [-122.216433, 37.860582], + [-122.215701, 37.860658], + [-122.215417, 37.860394], + [-122.214833, 37.859851], + [-122.214168, 37.859233], + [-122.213903, 37.858986], + [-122.212917, 37.859008], + [-122.211748, 37.85828], + [-122.212137, 37.858256], + [-122.212047, 37.857809], + [-122.211506, 37.85714], + [-122.211307, 37.856894], + [-122.211025, 37.857108], + [-122.21085, 37.856934], + [-122.211096, 37.856762], + [-122.210923, 37.856645], + [-122.211163, 37.856313], + [-122.210977, 37.855542], + [-122.210623, 37.855061], + [-122.210885, 37.854196], + [-122.209269, 37.852516], + [-122.20877, 37.851925], + [-122.208486, 37.85169], + [-122.208438, 37.851157], + [-122.208502, 37.851109], + [-122.208541, 37.851063], + [-122.208566, 37.851015], + [-122.208577, 37.850955], + [-122.208596, 37.850482], + [-122.206622, 37.843483], + [-122.206148, 37.843571], + [-122.206153, 37.844079], + [-122.206287, 37.844071], + [-122.206375, 37.844106], + [-122.206428, 37.844158], + [-122.206449, 37.844236], + [-122.206447, 37.844294], + [-122.206444, 37.844375], + [-122.206432, 37.844509], + [-122.206408, 37.844569], + [-122.206318, 37.844628], + [-122.206013, 37.844757], + [-122.205926, 37.844826], + [-122.205853, 37.844948], + [-122.205755, 37.845186], + [-122.205716, 37.845454], + [-122.205692, 37.845581], + [-122.205632, 37.84565], + [-122.205495, 37.845739], + [-122.205358, 37.845857], + [-122.205352, 37.845942], + [-122.20541, 37.846273], + [-122.205394, 37.846387], + [-122.205346, 37.846512], + [-122.204974, 37.847075], + [-122.204831, 37.847448], + [-122.204807, 37.847701], + [-122.204778, 37.847778], + [-122.204655, 37.847849], + [-122.204615, 37.847869], + [-122.204584, 37.847916], + [-122.20456, 37.848005], + [-122.204533, 37.84831], + [-122.204427, 37.848645], + [-122.204432, 37.848755], + [-122.204503, 37.848825], + [-122.204612, 37.848879], + [-122.204701, 37.848915], + [-122.204722, 37.848938], + [-122.204719, 37.848972], + [-122.204699, 37.849004], + [-122.204632, 37.849013], + [-122.204475, 37.848981], + [-122.204071, 37.848987], + [-122.203951, 37.84896], + [-122.203839, 37.848899], + [-122.203814, 37.848821], + [-122.203864, 37.848741], + [-122.203775, 37.848634], + [-122.203649, 37.848788], + [-122.203566, 37.848937], + [-122.203476, 37.84912], + [-122.203425, 37.84928], + [-122.203361, 37.849483], + [-122.203312, 37.849699], + [-122.203293, 37.849857], + [-122.20307, 37.849528], + [-122.203008, 37.849391], + [-122.202922, 37.849257], + [-122.202848, 37.849167], + [-122.202784, 37.849109], + [-122.201952, 37.848548], + [-122.201904, 37.848511], + [-122.201848, 37.848454], + [-122.201797, 37.848392], + [-122.201749, 37.848329], + [-122.201714, 37.848254], + [-122.201686, 37.848126], + [-122.201662, 37.84805], + [-122.201615, 37.847969], + [-122.201547, 37.847906], + [-122.201452, 37.847847], + [-122.201293, 37.847766], + [-122.200899, 37.847626], + [-122.200603, 37.847587], + [-122.200188, 37.847506], + [-122.199673, 37.847378], + [-122.199029, 37.847391], + [-122.198832, 37.847411], + [-122.198686, 37.847378], + [-122.198509, 37.847245], + [-122.1982, 37.846859], + [-122.197763, 37.846534], + [-122.197436, 37.846209], + [-122.19685, 37.845815], + [-122.196707, 37.845596], + [-122.196595, 37.845336], + [-122.196562, 37.845099], + [-122.19655, 37.844859], + [-122.196555, 37.844785], + [-122.196591, 37.8446], + [-122.196626, 37.844275], + [-122.196625, 37.844159], + [-122.196596, 37.844063], + [-122.196527, 37.84398], + [-122.196416, 37.843891], + [-122.196167, 37.843758], + [-122.193102, 37.844092], + [-122.193004, 37.84685], + [-122.188458, 37.8468], + [-122.188587, 37.850433], + [-122.188619, 37.852042], + [-122.189155, 37.85316], + [-122.18951, 37.853395], + [-122.190287, 37.854202], + [-122.191239, 37.854941], + [-122.192671, 37.855601], + [-122.19383, 37.856063], + [-122.194573, 37.856456], + [-122.194969, 37.856665], + [-122.194092, 37.857792], + [-122.197877, 37.85778] + ], + [ + [-122.209682, 37.858775], + [-122.209445, 37.858474], + [-122.209792, 37.858168], + [-122.210106, 37.858073], + [-122.210318, 37.858454], + [-122.209682, 37.858775] + ], + [ + [-122.193631, 37.850507], + [-122.192981, 37.850497], + [-122.192966, 37.851048], + [-122.191979, 37.851031], + [-122.191993, 37.85048], + [-122.192015, 37.849655], + [-122.193653, 37.849682], + [-122.193631, 37.850507] + ], + [ + [-122.195626, 37.850528], + [-122.195622, 37.850664], + [-122.194665, 37.85065], + [-122.194668, 37.850514], + [-122.195626, 37.850528] + ] + ] + ] + }, + "properties": { + "@id": "relation/6518385", + "boundary": "protected_area", + "contact:website": "http://www.ebparks.org/parks/sibley", + "name": "Sibley Volcanic Regional Preserve", + "operator": "East Bay Regional Park District", + "owner": "East Bay Regional Park District", + "protect_class": "4", + "source": "https://www.ebparks.org/images/Assets/files/parks/sibley/Sibley-map_2250w-04-23-18.gif", + "type": "multipolygon", + "website": "https://www.ebparks.org/parks/sibley/", + "wikidata": "Q7349780", + "wikipedia": "en:Robert Sibley Volcanic Regional Preserve" + } + }, + { + "type": "Feature", + "id": "way/10322303", + "geometry": { + "type": "LineString", + "coordinates": [ + [-122.318271, 37.86911], + [-122.318192, 37.868925], + [-122.3181, 37.868851], + [-122.317971, 37.86879], + [-122.317754, 37.86875], + [-122.317622, 37.868773], + [-122.317385, 37.868904], + [-122.317284, 37.869007], + [-122.317244, 37.869049], + [-122.31729, 37.869279], + [-122.317325, 37.869433], + [-122.31737, 37.869623], + [-122.317409, 37.869766], + [-122.317436, 37.869861] + ] + }, + "properties": { + "@id": "way/10322303", + "addr:city": "Berkeley", + "foot": "yes", + "highway": "service" + } + }, + { + "type": "Feature", + "id": "node/4927326183", + "geometry": { "type": "Point", "coordinates": [-122.318423, 37.869678] }, + "properties": { "@id": "node/4927326183" } + } + ] +} diff --git a/tests/test_api.py b/tests/test_api.py index 8a01f3a298..73f90a9152 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -10,8 +10,10 @@ from typing import Tuple, Union import geojson -import overpass import pytest +from deepdiff import DeepDiff + +import overpass USE_LIVE_API = bool(os.getenv("USE_LIVE_API", "false")) @@ -105,9 +107,16 @@ def test_geojson_live(): "rel(6518385);out body geom;way(10322303);out body geom;node(4927326183);", verbosity="body geom", ) - with Path("tests/example.geojson").open("r") as fp: - ref_geo = geojson.load(fp) - assert osm_geo == ref_geo + + with Path("tests/example_live.json").open("r") as fp: + ref_geo = json.load(fp) + + # assert that the dictionaries are the same + # diff = DeepDiff(osm_geo, ref_geo, include_paths="[root]['features']") + diff = DeepDiff(osm_geo, ref_geo, include_paths="[root]['features']") + print(diff if diff else "No differences found") + + assert not diff @pytest.mark.parametrize( diff --git a/tox.ini b/tox.ini index 235ed60c80..74c7ce7386 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,16 @@ [tox] -envlist = py{38,39,310,311} +envlist = py{39,310,311} skip_missing_interpreters = true [testenv] -deps = -r requirements-dev.txt -commands = python -m pytest +allowlist_externals = poetry +commands_pre = + poetry install --no-root --sync +commands = + poetry run pytest tests/ --import-mode importlib [gh-actions] python = - 3.8: py38 3.9: py39 3.10: py310 3.11: py311 \ No newline at end of file