bluebonnet-data / bbd

Python bluebonnet-data library
MIT License
6 stars 5 forks source link

Pytest PermissionError for windows when unlinking during test_make_map_joins_properly #11

Closed DarkSideOfTheMat closed 3 years ago

DarkSideOfTheMat commented 3 years ago

In tests/gis/test_map.py there is a Windows Permission Error in the test_make_map_joins_properly test during Path(save_path).unlink()

Full pytest readout: `====================================================== FAILURES ======================================================= ____ test_make_map_joinsproperly ____

def test_make_map_joins_properly():
    data = standard_data

    data_map = gis.make_map(
        shapefile_path,
        data,
        join_on="name",
    )

    geojson = data_map.data
    assert geojson["type"] == "FeatureCollection"

    features = geojson["features"]
    assert len(features) == 36

    feature0_props = features[0]["properties"]
    assert feature0_props["name"] == "Bay Colony, Port Royale"
    assert feature0_props["Demographic 1"] == "bay col dem1"
    assert feature0_props["Demographic 2"] == "bay col dem2"

    feature1_props = features[1]["properties"]
    assert feature1_props["name"] == "NE 48th"
    assert feature1_props["Demographic 1"] == "NE 48th dem1"
    assert feature1_props["Demographic 2"] == "NE 48th dem2"

    feature2_props = features[2]["properties"]
    assert feature2_props["name"] == "Linden Pointe Apartments"
    assert feature2_props["Demographic 1"] is None
    assert feature2_props["Demographic 2"] is None

    data_map.add_to(m)

    _, save_path = tempfile.mkstemp(suffix=".html")
    m.save(save_path)
  Path(save_path).unlink()

tests\gis\test_map.py:58:


self = WindowsPath('C:/Users/Matthew/AppData/Local/Temp/tmpa998mnwr.html'), missing_ok = False

def unlink(self, missing_ok=False):
    """
    Remove this file or link.
    If the path is a directory, use rmdir() instead.
    """
    if self._closed:
        self._raise_closed()
    try:
      self._accessor.unlink(self)

E PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\Matthew\AppData\Local\Temp\tmpa998mnwr.html'`

Can probably be solved by changing save_path to the pytest format tmp_path which has built in cleanup. (Opened for posterity)