data-for-change / anyway

ANYWAY - Car accidents map
http://www.anyway.co.il
MIT License
75 stars 242 forks source link

Unit test fail from time to time #2051

Closed BarVolunteering closed 2 years ago

BarVolunteering commented 2 years ago

Example: https://github.com/hasadna/anyway/pull/2037

Error:

tests/unit_tests/test_main.py::MainTest::test_bad_data PASSED [ 72%] tests/unit_tests/test_main.py::MainTest::test_data_null PASSED [ 73%] tests/unit_tests/test_main.py::MainTest::test_parse_marker PASSED [ 74%]

=================================== FAILURES =================================== ____ test_location_extraction_extract_geofeatures ____

def test_location_extraction_extract_geo_features():
    if not secrets.exists("GOOGLE_MAPS_KEY"):
        pytest.skip("Could not find GOOGLE_MAPS_KEY")

    parsed = dict(
        link="https://twitter.com/mda_israel/status/1253010741080326148",
        title='בשעה 19:39 התקבל דיווח במוקד 101 של מד"א במרחב דן על הולכת רגל שככל הנראה נפגעה מאופנוע ברחוב ביאליק ברמת גן. צוותי מד"א מעניקים טיפול ומפנים לבי"ח איכילוב 2 פצועים: אישה כבת 30 במצב קשה, עם חבלה רב מערכתית ורוכב האופנוע, צעיר בן 18 במצב בינוני, עם חבלות בראש ובגפיים.',
        description='בשעה 19:39 התקבל דיווח במוקד 101 של מד"א במרחב דן על הולכת רגל שככל הנראה נפגעה מאופנוע ברחוב ביאליק ברמת גן. צוותי מד"א מעניקים טיפול ומפנים לבי"ח איכילוב 2 פצועים: אישה כבת 30 במצב קשה, עם חבלה רב מערכתית ורוכב האופנוע, צעיר בן 18 במצב בינוני, עם חבלות בראש ובגפיים.',
        source="twitter",
        tweet_id=1253010741080326144,
        author="מגן דוד אדום",
        date=datetime.datetime(2020, 4, 22, 19, 39, 51),
        accident=True,
    )
    expected = NewsFlash(
        **parsed,
        lat=32.0861791,
        lon=34.8098462,
        resolution="רחוב",
        location="רחוב ביאליק ברמת גן",
        road_segment_name=None,
        district_hebrew=None,
        non_urban_intersection_hebrew=None,
        region_hebrew=None,
        road1=None,
        road2=None,
        street1_hebrew="ביאליק",
        street2_hebrew=None,
        yishuv_name="רמת גן",
    )

    actual = NewsFlash(**parsed)
  location_extraction.extract_geo_features(init_db(), actual)

tests/test_news_flash.py:195:


anyway/parsers/location_extraction.py:493: in extract_geo_features location_from_db = get_db_matching_location( anyway/parsers/location_extraction.py:163: in get_db_matching_location markers = db.get_markers_for_location_extraction() anyway/parsers/news_flash_db_adapter.py:58: in get_markers_for_location_extraction df.columns = query_res.keys() /venv3/lib/python3.8/site-packages/pandas/core/generic.py:5287: in setattr return object.setattr(self, name, value) pandas/_libs/properties.pyx:67: in pandas._libs.properties.AxisProperty.set ??? /venv3/lib/python3.8/site-packages/pandas/core/generic.py:661: in _set_axis self._data.set_axis(axis, labels)


self = BlockManager Items: Index([], dtype='object') Axis 1: Index([], dtype='object') axis = 0 new_labels = Index(['id', 'road1', 'road2', 'non_urban_intersection_hebrew', 'yishuv_name', 'street1_hebrew', 'street2_hebre...ude', 'yishuv_symbol', 'road_segment_id', 'street1', 'street2', 'non_urban_intersection'], dtype='object')

def set_axis(self, axis, new_labels):
    new_labels = ensure_index(new_labels)
    old_len = len(self.axes[axis])
    new_len = len(new_labels)

    if new_len != old_len:
      raise ValueError(

f"Length mismatch: Expected axis has {old_len} elements, new " f"values have {new_len} elements" ) E ValueError: Length mismatch: Expected axis has 0 elements, new values have 17 elements

/venv3/lib/python3.8/site-packages/pandas/core/internals/managers.py:177: ValueError ----------------------------- Captured stdout call ----------------------------- 2021-12-15 05:51:52,571 INFO sqlalchemy.engine.base.Engine SELECT * FROM cbs_locations 2021-12-15 05:51:52,571 INFO sqlalchemy.engine.base.Engine {} ----------------------------- Captured stderr call ----------------------------- 2021-12-15 05:51:52 DEBUG using location string: "רחוב ביאליק ברמת גן" 2021-12-15 05:51:52 DEBUG Starting new HTTPS connection (1): maps.googleapis.com:443 2021-12-15 05:51:52 DEBUG https://maps.googleapis.com:443 "GET /maps/api/geocode/json?address=%D7%A8%D7%97%D7%95%D7%91+%D7%91%D7%99%D7%90%D7%9C%D7%99%D7%A7+%D7%91%D7%A8%D7%9E%D7%AA+%D7%92%D7%9F&region=il&key=* HTTP/1.1" 200 None 2021-12-15 05:51:52 INFO SELECT FROM cbs_locations 2021-12-15 05:51:52 INFO {} ------------------------------ Captured log call ------------------------------- DEBUG root:location_extraction.py:309 using location string: "רחוב ביאליק ברמת גן" DEBUG urllib3.connectionpool:connectionpool.py:971 Starting new HTTPS connection (1): maps.googleapis.com:443 DEBUG urllib3.connectionpool:connectionpool.py:452 https://maps.googleapis.com:443 "GET /maps/api/geocode/json?address=%D7%A8%D7%97%D7%95%D7%91+%D7%91%D7%99%D7%90%D7%9C%D7%99%D7%A7+%D7%91%D7%A8%D7%9E%D7%AA+%D7%92%D7%9F&region=il&key= HTTP/1.1" 200 None INFO sqlalchemy.engine.base.Engine:log.py:110 SELECT * FROM cbs_locations INFO sqlalchemy.engine.base.Engine:log.py:110 {} =============================== warnings summary =============================== /venv3/lib/python3.8/site-packages/flask/json/init.py:211 tests/test_flask.py::test_main

atalyaalon commented 2 years ago

@BarVolunteering I suggest disabling the test for now