Skip to content

Commit

Permalink
style: clean up linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeller3 committed Nov 5, 2024
1 parent ebaac1f commit 839fe68
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 145 deletions.
58 changes: 39 additions & 19 deletions tests/test_boolean.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""
Test module for booleans.
"""
import os
import json

import glob
import json
import os
import unittest

from turfpy.boolean import (
boolean_disjoint,
boolean_intersects,
)
from turfpy.boolean import boolean_disjoint, boolean_intersects


def load_json_file_sync(filepath):
with open(filepath) as f:
Expand All @@ -21,37 +20,58 @@ def setUp(self):
self.dirname = os.path.dirname(os.path.abspath(__file__))

def test_true_fixtures(self):
for filepath in glob.glob(os.path.join(self.dirname, "boolean_disjoint_test", "true", "**", "*.geojson"), recursive=True):
for filepath in glob.glob(
os.path.join(
self.dirname, "boolean_disjoint_test", "true", "**", "*.geojson"
),
recursive=True,
):
geojson = load_json_file_sync(filepath)
feature1 = geojson['features'][0]
feature2 = geojson['features'][1]
feature1 = geojson["features"][0]
feature2 = geojson["features"][1]
result = boolean_disjoint(feature1, feature2)
self.assertTrue(result, True)

def test_false_fixtures(self):
for filepath in glob.glob(os.path.join(self.dirname, "boolean_disjoint_test", "false", "**", "*.geojson"), recursive=True):
for filepath in glob.glob(
os.path.join(
self.dirname, "boolean_disjoint_test", "false", "**", "*.geojson"
),
recursive=True,
):
geojson = load_json_file_sync(filepath)
feature1 = geojson['features'][0]
feature2 = geojson['features'][1]
feature1 = geojson["features"][0]
feature2 = geojson["features"][1]
result = boolean_disjoint(feature1, feature2)
self.assertFalse(result, False)


class TestTurfBooleanIntersects(unittest.TestCase):
def setUp(self):
self.dirname = os.path.dirname(os.path.abspath(__file__))

def test_true_fixtures(self):
for filepath in glob.glob(os.path.join(self.dirname, "boolean_intersects_test", "true", "**", "*.geojson"), recursive=True):
for filepath in glob.glob(
os.path.join(
self.dirname, "boolean_intersects_test", "true", "**", "*.geojson"
),
recursive=True,
):
geojson = load_json_file_sync(filepath)
feature1 = geojson['features'][0]
feature2 = geojson['features'][1]
feature1 = geojson["features"][0]
feature2 = geojson["features"][1]
result = boolean_intersects(feature1, feature2)
self.assertTrue(result, True)

def test_false_fixtures(self):
for filepath in glob.glob(os.path.join(self.dirname, "boolean_intersects_test", "false", "**", "*.geojson"), recursive=True):
for filepath in glob.glob(
os.path.join(
self.dirname, "boolean_intersects_test", "false", "**", "*.geojson"
),
recursive=True,
):
geojson = load_json_file_sync(filepath)
feature1 = geojson['features'][0]
feature2 = geojson['features'][1]
feature1 = geojson["features"][0]
feature2 = geojson["features"][1]
result = boolean_intersects(feature1, feature2)
self.assertFalse(result, False)
self.assertFalse(result, False)
42 changes: 22 additions & 20 deletions tests/test_feature_conversion.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
"""
Test module for feature conversions.
"""
import os

import json
from pathlib import Path
import os
import unittest
from pathlib import Path

from turfpy.feature_conversion import (
polygon_to_line
)
from turfpy.feature_conversion import polygon_to_line

# Define directories
current_dir = Path(__file__).resolve().parent
directories = {
'in': current_dir / 'feature_conversion_polygon_to_line_test' / 'in',
'out': current_dir / 'feature_conversion_polygon_to_line_test' / 'out',
"in": current_dir / "feature_conversion_polygon_to_line_test" / "in",
"out": current_dir / "feature_conversion_polygon_to_line_test" / "out",
}

# Load fixtures
fixtures = []
for filename in os.listdir(directories['in']):
filepath = directories['in'] / filename
with open(filepath, 'r') as file:
for filename in os.listdir(directories["in"]):
filepath = directories["in"] / filename
with open(filepath, "r") as file:
geojson = json.load(file)
fixtures.append({
'filename': filename,
'name': Path(filename).stem,
'geojson': geojson,
})
fixtures.append(
{
"filename": filename,
"name": Path(filename).stem,
"geojson": geojson,
}
)


class TestPolygonToLine(unittest.TestCase):

def test_polygon_to_linestring(self):
for fixture in fixtures:
name = fixture['name']
filename = fixture['filename']
geojson = fixture['geojson']
name = fixture["name"]
filename = fixture["filename"]
geojson = fixture["geojson"]

# Perform the conversion
results = polygon_to_line(geojson)

# Load the expected results
with open(directories['out'] / filename, 'r') as file:
with open(directories["out"] / filename, "r") as file:
expected_results = json.load(file)

# Assert the results are as expected
self.assertEqual(results, expected_results, name)
self.assertEqual(results, expected_results, name)
1 change: 1 addition & 0 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module will test all functions in helper module.
"""

from geojson import Feature, Point, Polygon

from turfpy.helper import get_coord, get_coords
Expand Down
1 change: 1 addition & 0 deletions tests/test_random.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test module for randoms.
"""

from geojson import Feature, Point

from turfpy.measurement import bbox, boolean_point_in_polygon
Expand Down
1 change: 1 addition & 0 deletions tests/test_transformation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test module for transformations.
"""

from geojson import (
Feature,
FeatureCollection,
Expand Down
1 change: 1 addition & 0 deletions turfpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""A Python library for performing geospatial data analysis which reimplements turf.js
"""

from .__version__ import __version__ # noqa F401
1 change: 1 addition & 0 deletions turfpy/_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
can be used to check whether a dependency is installed
or not.
"""

HAS_PYGEOS = None

HAS_GEOPANDAS = None
Expand Down
Loading

0 comments on commit 839fe68

Please sign in to comment.