diff --git a/TODO b/TODO new file mode 100644 index 0000000..21e254f --- /dev/null +++ b/TODO @@ -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) diff --git a/flashgeotext/extractor.py b/flashgeotext/extractor.py index ec5da60..2be33ad 100644 --- a/flashgeotext/extractor.py +++ b/flashgeotext/extractor.py @@ -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 = {} diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py new file mode 100644 index 0000000..7f9dbf8 --- /dev/null +++ b/tests/unit/conftest.py @@ -0,0 +1,10 @@ +import pytest + +from flashgeotext.extractor import GeoText + + +@pytest.fixture +def geotext_demodata(): + geotext_demodata = GeoText() + + return geotext_demodata diff --git a/tests/unit/test_extractor.py b/tests/unit/test_extractor.py index 03d7e49..7a0a246 100644 --- a/tests/unit/test_extractor.py +++ b/tests/unit/test_extractor.py @@ -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(): @@ -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 @@ -30,7 +36,7 @@ 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", [ ( { @@ -38,15 +44,25 @@ def test_geolookup_no_demo_data_and_empty_processor(): "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