Trackpoints Routepoints and Waypoints
Before today's change, in my source code for tests I had only trackpoints. This worked pretty well, but then I've figure out, I need to be able to check if someone's going to use different type of *points. And obviously I added this to my steps-to-make.
I've created different type of gpx file encodings(TrackPoints/WayPoints/RoutePoints) for tests.
I've added Routepoints and Waypoints. And this made to a tests failure once I've added them to test as parameters.
As I've figure out before, one of the "content" type had different encoding of data and I needed to fix few things in source code.
Finally code has 3 types of different *points.
Final result
Here is final result of test-source-code:
class BaseGPXReaderTest(unittest.TestCase):
"""
A Prof Of Concept for creating one generalized GPXReader test class.
It will then be inherited by other classes that will use TrackPoints example data,
Route Points data and Way Points data using pytest-fixtures.
"""
@parameterized.expand([
('web/tests/example_data/fast_example.gpx'),
('web/tests/example_data/fast_example_trackpoints.gpx'),
('web/tests/example_data/fast_example_waypoints.gpx'),
('web/tests/example_data/fast_example_routepoints.gpx'),
])
def test_get_points(self, gpxfile):
"""
Tests if there will be data output from get_points.
Test if:
- points exists for different types.
- what will happen if types exists, but no data?
"""
gpxreader = GPXReader(gpxfile)
points = []
for point in gpxreader.get_points():
points.append(point)
assert len(points) > 0
@parameterized.expand([
('web/tests/example_data/fast_example.gpx'),
('web/tests/example_data/fast_example_trackpoints.gpx'),
('web/tests/example_data/fast_example_waypoints.gpx'),
('web/tests/example_data/fast_example_routepoints.gpx'),
])
def test_get_elevations(self, gpxfile):
"""
Tests if all elevations will be returned from input element.
Test should check if elements are TrackPoints Route Points or Way Points.
"""
gpxreader = GPXReader(gpxfile)
elevations = gpxreader.get_elevations()
assert len(elevations) > 0
@parameterized.expand([
('web/tests/example_data/fast_example.gpx', 224),
('web/tests/example_data/fast_example_trackpoints.gpx', 224),
('web/tests/example_data/fast_example_waypoints.gpx', 224),
('web/tests/example_data/fast_example_routepoints.gpx', 224),
])
def test_get_elevations_len(self, gpxfile, elevations_len=224):
"""
Test if proper amount of elevations are read by get_elevations method.
"""
gpxreader = GPXReader(gpxfile)
elevations = gpxreader.get_elevations()
assert len(elevations) == elevations_len
What I don't like about this source-code?
I don't like that there is a lot of repeated code (if parameters are a repeated code ? ) that leads to break the DRY Principle
I'll need to think if this is actually a "repeated" code or if some of this functions does not need so much of parameter types.
Code commits done for this post:
- Fixes few pylint errors.
- Fixes waypoints & routepoints
- Adds route-track-way points example with nose parameterized
Tools and applications used:
- VIM + Plugins (Fugitive, Vim-Markdown and Vimux )
- Docker
- Tmux
Comments
comments powered by Disqus