Skip to content

Commit

Permalink
#3 Work in progress:
Browse files Browse the repository at this point in the history
-Update tests
-Update test reference files
-Update gitignore

[ci skip]
  • Loading branch information
FABallemand committed Jul 18, 2023
1 parent 244dbd0 commit 18e6b48
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
tests/dev_tests/*
*_test.gpx
*.old
*.private
*.unused

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
18 changes: 9 additions & 9 deletions ezgpx/utils/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def haversine_distance(point_1, point_2) -> float:
https://en.wikipedia.org/wiki/Haversine_formula
Args:
point_1 (TrackPoint): First point.
point_2 (TrackPoint): Second point.
point_1 (WayPoint): First point.
point_2 (WayPoint): Second point.
Returns:
float: Haversine distance between the points.
Expand All @@ -34,8 +34,8 @@ def distance(point_1, point_2) -> float:
Euclidian distance between two points.
Args:
point_1 (TrackPoint): First point.
point_2 (TrackPoint): Second point.
point_1 (WayPoint): First point.
point_2 (WayPoint): Second point.
Returns:
float: Distance between the points.
Expand All @@ -50,9 +50,9 @@ def perpendicular_distance(start_point, end_point, point) -> float:
Distance between a point and a line.
Args:
start_point (TrackPoint): A point on the line.
end_point (TrackPoint): A point on the line.
point (TrackPoint): A point to measure the distance from.
start_point (WayPoint): A point on the line.
end_point (WayPoint): A point on the line.
point (WayPoint): A point to measure the distance from.
Returns:
float: Perpendicular distance between the point *point* and the line defined by *start_point* and *end_point*.
Expand All @@ -63,8 +63,8 @@ def line_coefficients(point_1, point_2):
Compute the coefficients of a line equation of the form: ax+by+c=0.
Args:
point_1 (TrackPoint): A point on the line.
point_2 (TrackPoint): A point on the line.
point_1 (WayPoint): A point on the line.
point_2 (WayPoint): A point on the line.
Returns:
tuple: Coefficients of the line equation.
Expand Down
33 changes: 13 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
long_description = f.read()

setup(
name='ezGPX',
version='0.1.0',
name='ezgpx',
version='0.1.1',
description='Easy to use Python GPX library',
long_description=long_description,
long_description_content_type='text/markdown',
keywords=['gpx', 'gpx-files', 'gpx-parser', 'gpx-reader', 'gpx-writer', 'gpx-data'],
# url='https://medium-multiply.readthedocs.io/',
download_url='https://github.com/FABallemand/ezGPX',
project_urls={
"Bug Tracker": "https://github.com/FABallemand/ezGPX/issues",
# "Documentation": "",
"Source Code": "https://github.com/FABallemand/ezGPX",
},
author='Fabien ALLEMAND',
author_email='[email protected]',
license='GNU GPLv3',
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
Expand All @@ -30,24 +36,11 @@
'Programming Language :: Python :: 3.9',
'Operating System :: OS Independent'
],
packages=find_packages(include=['ezgpx']),
# packages=find_packages(include=['ezgpx']),
packages=['ezgpx'],
include_package_data=True,
install_requires=["gmap", "folium"],
install_requires=['gmap', 'folium'],
setup_requires=['pytest-runner'],
tests_require=['pytest'],
test_suite='tests'
)

# setup(
# name='ezGPX',
# # packages=find_packages(include=['mypythonlib']),
# packages=find_packages(),
# version='0.1.0',
# description='Easy to use Python GPX library',
# author='Fabien ALLEMAND',
# license='GNU GPLv3',
# install_requires=[],
# setup_requires=['pytest-runner'],
# tests_require=['pytest'],
# test_suite='tests',
# )
)
49 changes: 27 additions & 22 deletions tests/test_GPX.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,68 @@

class TestGPX():

def _test_plot_1(self):
def _test_matplotlib_plot_1(self):
# Plot
self.test_gpx.plot(start_stop=False, elevation_color=False, file_path="tmp/strava_run_1.png")
self.test_gpx.matplotlib_plot(start_stop_colors=None, elevation_color=False, title="Track", file_path="tmp/matplotlib_strava_run_1.png")

# Load images
test_img = plt.imread("tmp/strava_run_1.png")
ref_img = plt.imread("../test_files/reference_files/strava_run_1.png")
test_img = plt.imread("tmp/matplotlib_strava_run_1.png")
ref_img = plt.imread("../tests/test_files/reference_files/matplotlib_strava_run_1.png")

# Compare images
return np.array_equal(test_img, ref_img)

def _test_plot_2(self):
def _test_matplotlib_plot_2(self):
# Plot
self.test_gpx.plot(start_stop=True, elevation_color=False, file_path="tmp/strava_run_1_start_stop.png")
self.test_gpx.matplotlib_plot(start_stop_colors=("#00FF00", "#FF0000"), elevation_color=False, title="Track", file_path="tmp/matplotlib_strava_run_1_start_stop.png")

# Load images
test_img = plt.imread("tmp/strava_run_1_start_stop.png")
ref_img = plt.imread("../test_files/reference_files/strava_run_1_start_stop.png")
test_img = plt.imread("tmp/matplotlib_strava_run_1_start_stop.png")
ref_img = plt.imread("../tests/test_files/reference_files/matplotlib_strava_run_1_start_stop.png")

# Compare images
return np.array_equal(test_img, ref_img)

def _test_plot_3(self):
def _test_matplotlib_plot_3(self):
# Plot
self.test_gpx.plot(start_stop=False, elevation_color=False, file_path="tmp/strava_run_1_elevation.png")
self.test_gpx.matplotlib_plot(start_stop_colors=None, elevation_color=True, title="Track", file_path="tmp/matplotlib_strava_run_1_elevation.png")

# Load images
test_img = plt.imread("tmp/strava_run_1_elevation.png")
ref_img = plt.imread("../test_files/reference_files/strava_run_1_elevation.png")
test_img = plt.imread("tmp/matplotlib_strava_run_1_elevation.png")
ref_img = plt.imread("../tests/test_files/reference_files/matplotlib_strava_run_1_elevation.png")

# Compare images
return np.array_equal(test_img, ref_img)

def _test_plot_4(self):
def _test_matplotlib_plot_4(self):
# Plot
self.test_gpx.plot(start_stop=True, elevation_color=True, file_path="tmp/strava_run_1_start_stop_elevation.png")
self.test_gpx.matplotlib_plot(start_stop_colors=("#00FF00", "#FF0000"), elevation_color=True, title="Track", file_path="tmp/matplotlib_strava_run_1_start_stop_elevation.png")

# Load images
test_img = plt.imread("tmp/strava_run_1_start_stop_elevation.png")
ref_img = plt.imread("../test_files/reference_files/strava_run_1_start_stop_elevation.png")
test_img = plt.imread("tmp/matplotlib_strava_run_1_start_stop_elevation.png")
ref_img = plt.imread("../tests/test_files/reference_files/matplotlib_strava_run_1_start_stop_elevation.png")

# Compare images
return np.array_equal(test_img, ref_img)

def test_plot(self, remove_tmp: bool = True):
def test_matplotlib_plot(self, remove_tmp: bool = True):
"""
Test matplotlib_plot method.
self.test_gpx = GPX("../test_files/files/strava_run_1.gpx")
Args:
remove_tmp (bool, optional): Remove temporary folder. Defaults to True.
"""
self.test_gpx = GPX("../tests/test_files/files/strava_run_1.gpx")

# Create temporary folder
rmtree("tmp", True)
os.makedirs(os.path.dirname(__file__) + "/tmp")

# Tests
assert(self._test_plot_1())
assert(self._test_plot_2())
assert(self._test_plot_3())
assert(self._test_plot_4())
assert(self._test_matplotlib_plot_1())
assert(self._test_matplotlib_plot_2())
assert(self._test_matplotlib_plot_3())
assert(self._test_matplotlib_plot_4())

# Remove temporary folder
if remove_tmp:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 13 additions & 13 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
os.chdir(file_folder)
sys.path.append(parent_folder + "/ezgpx")

from ezgpx import utils, TrackPoint
from ezgpx import utils, WayPoint

class TestUtils():

def test_haversine_distance(self):
pass

def _test_perpendicular_distance_horizontal_line(self):
start = TrackPoint(0, 0)
end = TrackPoint(0, 2)
point = TrackPoint(1, 1)
start = WayPoint("wpt", 0, 0)
end = WayPoint("wpt", 0, 2)
point = WayPoint("wpt", 1, 1)
return math.isclose(utils.perpendicular_distance(start, end, point), 1)

def _test_perpendicular_distance_vertical_line(self):
start = TrackPoint(0, 0)
end = TrackPoint(2, 0)
point = TrackPoint(1, 1)
start = WayPoint("wpt", 0, 0)
end = WayPoint("wpt", 2, 0)
point = WayPoint("wpt", 1, 1)
return math.isclose(utils.perpendicular_distance(start, end, point), 1)

def _test_perpendicular_distance_random_line(self):
start = TrackPoint(0, 0)
end = TrackPoint(1, 1)
point = TrackPoint(1, 0)
start = WayPoint("wpt", 0, 0)
end = WayPoint("wpt", 1, 1)
point = WayPoint("wpt", 1, 0)
return math.isclose(utils.perpendicular_distance(start, end, point), math.sqrt(2)/2)

def _test_perpendicular_distance_point_on_line(self):
start = TrackPoint(0, 0)
end = TrackPoint(1, 1)
point = TrackPoint(2, 2)
start = WayPoint("wpt", 0, 0)
end = WayPoint("wpt", 1, 1)
point = WayPoint("wpt", 2, 2)
return math.isclose(utils.perpendicular_distance(start, end, point), 0)

def test_perpendicular_distance(self):
Expand Down

0 comments on commit 18e6b48

Please sign in to comment.