Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Minimum Product: World map ported to python3. #254

Merged
merged 1 commit into from
Sep 29, 2017

Conversation

OlafSzmidt
Copy link
Contributor

Ported world_map and test_world_map to python3, ie:

  • xrange is now replaced is range.
  • try and except used in instances where itervalues() is used. This way I can allow for both versions to run the code.

Copy link
Contributor

@danalex97 danalex97 left a comment

Choose a reason for hiding this comment

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

From the stacktrace in #245, I guess you try to port the whole aimmo-game package. If so, you should also change the Dockerfile to python3.

@OlafSzmidt
Copy link
Contributor Author

@danalex97 There are hundreds of places where the 2to3 move needs to done, not just world_map. Small steps. Will the codebase work with py2 dockerfiles for now? I wanted this PR to just be for world_map functionality :)

@danalex97
Copy link
Contributor

danalex97 commented Sep 27, 2017

@OlafSzmidt Oh, I see. That's why you did the itervalues to work with both versions. That makes sense.

danalex97
danalex97 previously approved these changes Sep 27, 2017
@OlafSzmidt
Copy link
Contributor Author

@danalex97 Exactly ;) And itervalues() are not compatible with py3, but values() are back-compatible with py2 because they just return a list. I'm just pushing an extra test for that functionality if you could check that before you go :P

danalex97
danalex97 previously approved these changes Sep 27, 2017
Copy link
Contributor

@danalex97 danalex97 left a comment

Choose a reason for hiding this comment

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

It all seems fine. I don't know how to run the tests with python3, though.

@OlafSzmidt
Copy link
Contributor Author

OlafSzmidt commented Sep 27, 2017

@danalex97 To be honest I was hoping that the with self.assertRaises() code block will force the except in the code to be ran. Coverage doesn't seem to show that it was covered though.... but......

self.assertFalse(isinstance(cell_names, collections.Iterable))
self.assertTrue(isinstance(cell_names, list))

Seems to pass; therefore I guess it's a problem with the coverage tool (or else I'm misunderstanding the use of with self.assertRaises(Exception) and the two lines above are never actually reached).

@@ -118,6 +120,22 @@ def test_all_cells(self):
self.assertIn('D', cell_names)
self.assertEqual(len(cell_names), 4)

def test_all_cells_python3(self):
# Except block will be called when python3 is used.
with self.assertRaises(Exception) as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test is wrong. This checks that an exception has been raised. The exception raised is in these lines:

self.assertFalse(isinstance(cell_names, collections.Iterable))
self.assertTrue(isinstance(cell_names, list))

since the assertion is false in python2. You can check this by commenting these lines. Thus, the test passes in python2. In python3, the test would fail since no exception would have been raised.

I think we should have only one test, that should work regardless of the python version or no test at all.

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 previous test will pass on both versions of python; and I suppose test coverage isn't THAT important in this case. I'll get rid of it. Thanks! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I'm curious if that is something actually testable and how one would do that.

@@ -305,7 +323,7 @@ class TestWorldMapWithOriginCentre(TestWorldMap):
def _generate_grid(self, columns=2, rows=2):
alphabet = iter(ascii_uppercase)
grid = {Location(x, y): MockCell(Location(x, y), name=next(alphabet))
for x in xrange(-int_ceil(columns/2.0)+1, int_floor(columns/2.0)+1) for y in xrange(-int_ceil(rows/2.0)+1, int_floor(rows/2.0)+1)}
for x in range(-int_ceil(columns/2.0)+1, int_floor(columns/2.0)+1) for y in range(-int_ceil(rows/2.0)+1, int_floor(rows/2.0)+1)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't notice. Good catch with those 👍

danalex97
danalex97 previously approved these changes Sep 27, 2017
@OlafSzmidt
Copy link
Contributor Author

Thanks @danalex97. @CelineBoudier @ramonfmir @mrniket - any remarks before I merge?

'''
try:
values = self.grid.itervalues()
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

you could try to except for a specific error type, less messy - in case the problem is not linked to the version of python for instance?

CelineBoudier
CelineBoudier previously approved these changes Sep 29, 2017
@CelineBoudier
Copy link
Contributor

but maybe squash before

New test for all_cells in py3.

Quickfix for test_all_cells test

Unnecessary new test removed.

Exception specified for all_cells.
@OlafSzmidt
Copy link
Contributor Author

Squashed.

@OlafSzmidt OlafSzmidt merged commit caf6fc5 into ocadotechnology:master Sep 29, 2017
@OlafSzmidt OlafSzmidt deleted the world_map_to_py3 branch September 29, 2017 10:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants