Skip to content

Add tests for tempfile_from_geojson() #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

willschlitzer
Copy link
Contributor

This pull requests adds two tests to test_helpers.py that test tempfile_from_geojson()

Fixes #

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@willschlitzer willschlitzer added the maintenance Boring but important stuff for the core devs label Jun 23, 2021
@willschlitzer willschlitzer added this to the 0.5.0 milestone Jun 23, 2021
@willschlitzer willschlitzer self-assigned this Jun 23, 2021
@willschlitzer willschlitzer marked this pull request as ready for review June 25, 2021 08:23
@willschlitzer
Copy link
Contributor Author

willschlitzer commented Jun 28, 2021

This is failing tests on the Python 3.7 CI jobs with ModuleNotFoundError: No module named 'geopandas'. Should geopandas be added/not made optional to requirements.txt and environment.yml?

Comment on lines +121 to +135
def test_tempfile_from_geojson():
"""
Test tempfile_from_geojson works when passed a geopandas GeoDataFrame.
"""
linestring = shapely.geometry.LineString([(20, 15), (30, 15)])
polygon = shapely.geometry.Polygon([(20, 10), (23, 10), (23, 14), (20, 14)])
gdf = gpd.GeoDataFrame(
index=["polygon", "linestring"],
geometry=[polygon, linestring],
)
with tempfile_from_geojson(gdf) as geojson_string:
assert isinstance(geojson_string, str)
with open(geojson_string) as tmpfile:
assert os.path.basename(tmpfile.name).startswith("pygmt-")
assert os.path.basename(tmpfile.name).endswith(".gmt")
Copy link
Member

@weiji14 weiji14 Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing tests on the Python 3.7 CI jobs with ModuleNotFoundError: No module named 'geopandas'. Should geopandas be added/not made optional to requirements.txt and environment.yml?

No, geopandas should be an optional-only dependency. Could you provide some context as to why these two tests for the tempfile_from_geojson() function are to be added? To be honest, this tempfile_from_geojson function (added in #1000) is meant to be a temporary solution until GMT can read GeoJSON directly (as per GenericMappingTools/gmt#4599) though that might take some time.

If you must though, I'd suggest using pytest.importorskip to load geopandas and shapely, similar to at

gpd = pytest.importorskip("geopandas")
shapely = pytest.importorskip("shapely")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I added it was that the code coverage was showing tempfile_from_geojson() wasn't tested. I just assumed we hadn't gotten around to writing tests for it yet so I wrote them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tempfile_from_geojson function does have full test coverage (see https://codecov.io/gh/GenericMappingTools/pygmt/src/master/pygmt/helpers/tempfile.py). It is tested indirectly at test_geopandas.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll close the PR.

@weiji14 weiji14 deleted the test-geojson-helper branch June 29, 2021 12:22
@seisman seisman modified the milestones: 0.5.0, 0.4.1 Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants