Skip to content

Commit

Permalink
added tests and method .extract to Extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Feb 17, 2020
1 parent 9cb47ee commit 19459ba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
7 changes: 7 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extractor:
✔ write extractor class with KeywordProcessor globals for now @done(20-02-17 13:49)

GeoLookup:
✔ build keywordprocessors with demo data by default @done(20-02-17 13:49)
✔ make sure that user can also add her own data @done(20-02-17 13:49)
✔ test init with multiple inputs using pytest.mark.parametrize @done(20-02-17 13:49)
5 changes: 4 additions & 1 deletion flashgeotext/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class Extractor(object):
cities_processor: KeywordProcessor = KeywordProcessor(case_sensitive=True)
countries_processor: KeywordProcessor = KeywordProcessor(case_sensitive=True)

def extract(self, input_text: str):
return "works"

class GeoLookup(Extractor):

class GeoText(Extractor):
cities: dict = {}
countries: dict = {}

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from flashgeotext.extractor import GeoText


@pytest.fixture
def geotext_demodata():
geotext_demodata = GeoText()

return geotext_demodata
40 changes: 28 additions & 12 deletions tests/unit/test_extractor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from flashgeotext.extractor import Extractor
from flashgeotext.extractor import GeoLookup
from flashgeotext.extractor import GeoText


def test_extractor_init():
Expand All @@ -11,17 +11,23 @@ def test_extractor_init():
assert hasattr(ext, "countries_processor")


def test_geolookup_demo_data():
geolookup_with_demodata = GeoLookup(use_demo_data=True)
def test_extractor_extract(geotext_demodata):
geotext = geotext_demodata

assert geolookup_with_demodata.cities
assert geolookup_with_demodata.cities_processor
assert geolookup_with_demodata.countries
assert geolookup_with_demodata.countries_processor
assert geotext.extract("I love Berlin")


def test_geolookup_demo_data(geotext_demodata):
geotext = geotext_demodata

assert geotext.cities
assert geotext.cities_processor
assert geotext.countries
assert geotext.countries_processor


def test_geolookup_no_demo_data_and_empty_processor():
geolookup_empty = GeoLookup(use_demo_data=False)
geolookup_empty = GeoText(use_demo_data=False)

assert not geolookup_empty.cities
assert not geolookup_empty.countries
Expand All @@ -30,23 +36,33 @@ def test_geolookup_no_demo_data_and_empty_processor():


@pytest.mark.parametrize(
"cities, countries, len_countries_processor, len_cities_processor",
"cities, countries, len_cities_processor, len_countries_processor",
[
(
{
"Berlin": ["Berlin", "german capitol"],
"Kopenhagen": ["Kopenhagen", "danish capitol"],
},
{"Germany": ["Germany"], "Denmark": ["Denmark"]},
4,
2,
),
({}, {"Germany": ["Germany"], "Denmark": ["Denmark"]}, 0, 2),
(
{
"Berlin": ["Berlin", "german capitol"],
"Kopenhagen": ["Kopenhagen", "danish capitol"],
},
{},
4,
)
0,
),
],
)
def test_geolookup_manual_data(
cities, countries, len_countries_processor, len_cities_processor
cities, countries, len_cities_processor, len_countries_processor, geotext_demodata
):
geolookup = GeoLookup()
geolookup = geotext_demodata
geolookup.cities = cities
geolookup.countries = countries

Expand Down

0 comments on commit 19459ba

Please sign in to comment.