Skip to content
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

Abstract test classes to share common logic between creators #133

Merged
merged 1 commit into from
Mar 30, 2018
Merged

Abstract test classes to share common logic between creators #133

merged 1 commit into from
Mar 30, 2018

Conversation

pantierra
Copy link
Contributor

@pantierra pantierra commented Mar 1, 2018

As a follow up to #131, this PR proposes to create a class CreatorsTestsAbstract with the general testing logic for providers/creators, which was before implemented very similarily in the gh_accra and ni_managua providers. With this PR, the providers just have to extend from this class and define the necessary variables through overridable methods:

  • _get_selector() (required)
  • _get_required_variables() (required)
  • _get_standard_variables() (optional)
  • _override_configuration() (optional)

Unfortunately the comparing diff tool seems to be quite overwhelmed by these kind of changes, and it is difficult to see the changes. Looking at the code, without using the diff tool is probably easier.

amount_of_stops = len(stops['regular']) + len(stops['stations'])
self.assertEqual(
# amount_of_stops, self.count_stops, # WORKS FOR ACCRA
amount_of_stops, self.count_stops + self.count_stations, # WORKS FOR MANAGUA
Copy link
Contributor Author

@pantierra pantierra Mar 1, 2018

Choose a reason for hiding this comment

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

Here we have an incompatibility between Accra and Managua and I would like to ask for your help on this, @prhod and @nlehuby.

For some reason the GTFS for Managua counts stops and stations (stop_areas), whereas Accra only counts the stops and not the stations. However in line 99 explicitly stops and stations are added up. So I guess Managua is following the correct behaviour. But I'm really not sure on this one and how to fix it for Accra.

Do you have an idea?

Copy link
Contributor Author

@pantierra pantierra Mar 1, 2018

Choose a reason for hiding this comment

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

Because of some other changes, the code moved: The important part is now at line 141-143

"""

# Define selector for this tests
self.selector = "YOUR SELECTOR"
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this would be better with an abstract method?

Copy link
Contributor Author

@pantierra pantierra Mar 1, 2018

Choose a reason for hiding this comment

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

This is where my knowledge on Python ends currently. I gave it a try here, but it breaks with error message

TypeError: Can't instantiate abstract class TestCreatorsAbstract with abstract methods setUp

My very wild guess: There seems to be some deep-shit going on because setUp is the initiator function.

Can anybody help me or point me to documentation that helps me? Thanks.

Copy link
Owner

Choose a reason for hiding this comment

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

You would declare a new method get_selector() which throws a NotImplemented exception, so all subclasses need to implement it. Then where you need the selector, you call the method.

Copy link
Contributor Author

@pantierra pantierra Mar 1, 2018

Choose a reason for hiding this comment

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

ok, it is implemented in this PR as suggested, with two abstract functions:

  • _get_selector()
  • _get_required_values()

And optionally can be overridden:

  • _get_standard_values()
  • _override_configuration()

Is this how you meant it, @grote?

@pantierra
Copy link
Contributor Author

pantierra commented Mar 2, 2018

Automatic tests currently fail because of different behaviour on handling stations (stop_areas) between Accra and Managua, as described here:

AssertionError: Wrong count of stops in the cache file

I'd prefer to come to a consistent solution for both providers. Alternatively we would have to add another variable to be set to use in the critical position. What do you think how we can solve this best?

@pantierra
Copy link
Contributor Author

pantierra commented Mar 2, 2018

Let's keep this more simple: I introduced a separate variable stops_osm_count for this case, where Accra and Managua differ. The reason seems to be: Managua uses OSM stop_areas to create stations, while Accra does a proximity search to define stations. I think there is no way out but defining this other variable. Or such improvement should happen in a separate PR.

Now, tests work well (it actually fixes an error which lets the current master fail).

Copy link
Collaborator

@prhod prhod left a comment

Choose a reason for hiding this comment

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

👍 Great !

Copy link
Collaborator

@nlehuby nlehuby left a comment

Choose a reason for hiding this comment

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

Nice job, seems very clear and easy to re-use 👍

I've added a few minors comments.

break
if not trip_point_found:
print(
"No corresponing stop_time for trip_id={} and stop_sequence={}".format(
Copy link
Collaborator

Choose a reason for hiding this comment

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

*corresponding.
Maybe matching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There has been no change on this one in this PR. But I'm happy to improve the wording as suggested.

"Wrong stop_points count in the generated GTFS")
self.assertEqual(gtfs_infos["stop_areas_count"], self.required_values['stations_count'],
"Wrong stop_areas count in the generated GTFS")
self.assertEqual(gtfs_infos["routes_count"], self.required_values['routes_count'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we switch the order of the tests ?
The tests about the required values provide much more useful info to debug and to inspect the potential differences than the is_identical_gtfs one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, but probably better to do in a separate PR.

"""
raise NotImplementedError

def _get_standard_values(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like values. Maybe variables or test_config ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can rename it to variables.

@pantierra
Copy link
Contributor Author

Thanks for your reviews @prhod and @nlehuby!

@pantierra
Copy link
Contributor Author

Rerolled with the latest suggestions. Further I included the query print-outs from #134, because it makes much more sense to have them in this PR.

From my side, this seems to be ready to merge in.

@pantierra
Copy link
Contributor Author

@grote Any chance to get this in at some point?

@grote
Copy link
Owner

grote commented Mar 30, 2018

Thanks for the work and the reminder!

@grote grote merged commit b7b6b4f into grote:master Mar 30, 2018
@pantierra
Copy link
Contributor Author

Thank you

@pantierra pantierra deleted the creator-tests-abstract branch March 30, 2018 19:34
@pantierra pantierra mentioned this pull request Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants