Skip to content

Commit

Permalink
use pytest instead of nose
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Dec 14, 2023
1 parent e493594 commit 953491f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ django_test:
python manage.py test api.tests jobs.tests tasks.tests

test:
nosetests hdx_exports/tests/test_hdx_export_set.py
pytest hdx_exports/tests/test_hdx_export_set.py

worker:
PYTHONPATH=../osm-export-tool-python/ DJANGO_SETTINGS_MODULE=core.settings.project dramatiq tasks.task_runners --processes 1 --threads 1
Empty file added hdx_exports/tests/__init__.py
Empty file.
97 changes: 52 additions & 45 deletions hdx_exports/tests/test_hdx_export_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,45 @@

import json
import unittest
from hdx_exports.hdx_export_set import HDXExportSet
from ..hdx_export_set import HDXExportSet
from hdx.api.configuration import Configuration
from django.contrib.gis.geos import GEOSGeometry

from hdx.data.hdxobject import HDXError

DAKAR_GEOJSON_POLYGON = json.dumps({
DAKAR_GEOJSON_POLYGON = json.dumps(
{
"type": "Polygon",
"coordinates": [
[
[-17.465,14.719],
[-17.442,14.719],
[-17.442,14.741],
[-17.465,14.741],
[-17.465,14.719]
]
]
})

DAKAR_GEOJSON_MULTIPOLYGON = json.dumps({
[
[-17.465, 14.719],
[-17.442, 14.719],
[-17.442, 14.741],
[-17.465, 14.741],
[-17.465, 14.719],
]
],
}
)

DAKAR_GEOJSON_MULTIPOLYGON = json.dumps(
{
"type": "MultiPolygon",
"coordinates": [[
[
[-17.465,14.719],
[-17.442,14.719],
[-17.442,14.741],
[-17.465,14.741],
[-17.465,14.719]
]]
]
})

yaml = '''
"coordinates": [
[
[
[-17.465, 14.719],
[-17.442, 14.719],
[-17.442, 14.741],
[-17.465, 14.741],
[-17.465, 14.719],
]
]
],
}
)

yaml = """
Some Buildings:
types:
- polygons
Expand All @@ -49,8 +55,8 @@
select:
- natural
where: natural in ('waterway')
'''
#BASIC_FEATURE_SELECTION = FeatureSelection(yaml)
"""
# BASIC_FEATURE_SELECTION = FeatureSelection(yaml)

SINGLE_THEME_NOTE = """
OpenStreetMap exports for use in GIS applications.
Expand Down Expand Up @@ -86,58 +92,59 @@
information.
"""


@unittest.skip("HDX Configuration requires network access")
class TestHDXExportSet(unittest.TestCase):
maxDiff = None

def test_minimal_export_set(self):

h = HDXExportSet(
dataset_prefix="hot_dakar",
name="Dakar Urban Area",
extent=DAKAR_GEOJSON_POLYGON,
feature_selection=BASIC_FEATURE_SELECTION
feature_selection=BASIC_FEATURE_SELECTION,
)
datasets = h.datasets
self.assertEquals(len(datasets),2)
self.assertEquals(datasets['Some Buildings']['name'],'hot_dakar_some_buildings')
self.assertEquals(datasets['waterways']['name'],'hot_dakar_waterways')
self.assertEquals(len(datasets), 2)
self.assertEquals(
datasets["Some Buildings"]["name"], "hot_dakar_some_buildings"
)
self.assertEquals(datasets["waterways"]["name"], "hot_dakar_waterways")

def test_extent_not_polygon_or_multipolygon(self):
with self.assertRaises(AssertionError):
h = HDXExportSet(
dataset_prefix="hot_dakar",
name="Dakar Urban Area",
extent=GEOSGeometry("{'type':'LineString','coordinates':[]}"),
feature_selection=BASIC_FEATURE_SELECTION
dataset_prefix="hot_dakar",
name="Dakar Urban Area",
extent=GEOSGeometry("{'type':'LineString','coordinates':[]}"),
feature_selection=BASIC_FEATURE_SELECTION,
)


def test_single_theme_note(self):
yaml = '''
yaml = """
all:
select:
- name
'''
"""
h = HDXExportSet(
dataset_prefix="hot_dakar",
name="Dakar Urban Area",
extent=DAKAR_GEOJSON_POLYGON,
feature_selection=FeatureSelection(yaml)
feature_selection=FeatureSelection(yaml),
)
self.assertMultiLineEqual(h.hdx_note('all'),SINGLE_THEME_NOTE)
self.assertMultiLineEqual(h.hdx_note("all"), SINGLE_THEME_NOTE)

def test_filtered_note(self):
yaml = '''
yaml = """
some:
select:
- name
where: highway IS NOT NULL
'''
"""
h = HDXExportSet(
dataset_prefix="hot_dakar",
name="Dakar Urban Area",
extent=DAKAR_GEOJSON_POLYGON,
feature_selection=FeatureSelection(yaml)
feature_selection=FeatureSelection(yaml),
)
self.assertMultiLineEqual(h.hdx_note('some'),SINGLE_FILTER_NOTE)
self.assertMultiLineEqual(h.hdx_note("some"), SINGLE_FILTER_NOTE)
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ boto3~=1.23.10 # needed for cloudwatch
rasterio
# osm-export-tool==0.0.25 #manual setup is needed for now
osm-export-tool-python == 2.0.10
rtree==0.9.1
rtree==1.1.0
validators==0.20.0
geonamescache==1.5.0
psutil==5.9.1
Expand All @@ -36,4 +36,7 @@ deepdiff==5.7.0
hurry.filesize==0.9
dramatiq-abort==1.0

python3-openid
python3-openid

##testing
pytest==7.4.3

0 comments on commit 953491f

Please sign in to comment.