Initial Python 3 port
Many things work, some don't. Notably, genPOI doesn't work, and there's some signedness comparison stuff going on in the C extension. This also completely drops support for Python 2, as maintaining a C extension for both Python 2 and 3 is a pain and not worth it for the 9 months that Python 2 is still going to be supported upstream. The documentation needs to be adjusted as well. All of the few tests we have pass, and rendering a map works, both with a configuration file and without. We can also use optimizeimages. Concerns #1528.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
|
||||
# For convenience
|
||||
|
||||
@@ -9,15 +9,15 @@ class TestLRU(unittest.TestCase):
|
||||
|
||||
def test_single_insert(self):
|
||||
self.lru[1] = 2
|
||||
self.assertEquals(self.lru[1], 2)
|
||||
self.assertEqual(self.lru[1], 2)
|
||||
|
||||
def test_multiple_insert(self):
|
||||
self.lru[1] = 2
|
||||
self.lru[3] = 4
|
||||
self.lru[5] = 6
|
||||
self.assertEquals(self.lru[1], 2)
|
||||
self.assertEquals(self.lru[3], 4)
|
||||
self.assertEquals(self.lru[5], 6)
|
||||
self.assertEqual(self.lru[1], 2)
|
||||
self.assertEqual(self.lru[3], 4)
|
||||
self.assertEqual(self.lru[5], 6)
|
||||
|
||||
def test_full(self):
|
||||
self.lru[1] = 'asdf'
|
||||
@@ -27,11 +27,11 @@ class TestLRU(unittest.TestCase):
|
||||
self.lru[5] = 'asdf'
|
||||
self.lru[6] = 'asdf'
|
||||
self.assertRaises(KeyError, self.lru.__getitem__, 1)
|
||||
self.assertEquals(self.lru[2], 'asdf')
|
||||
self.assertEquals(self.lru[3], 'asdf')
|
||||
self.assertEquals(self.lru[4], 'asdf')
|
||||
self.assertEquals(self.lru[5], 'asdf')
|
||||
self.assertEquals(self.lru[6], 'asdf')
|
||||
self.assertEqual(self.lru[2], 'asdf')
|
||||
self.assertEqual(self.lru[3], 'asdf')
|
||||
self.assertEqual(self.lru[4], 'asdf')
|
||||
self.assertEqual(self.lru[5], 'asdf')
|
||||
self.assertEqual(self.lru[6], 'asdf')
|
||||
|
||||
def test_lru(self):
|
||||
self.lru[1] = 'asdf'
|
||||
@@ -40,17 +40,17 @@ class TestLRU(unittest.TestCase):
|
||||
self.lru[4] = 'asdf'
|
||||
self.lru[5] = 'asdf'
|
||||
|
||||
self.assertEquals(self.lru[1], 'asdf')
|
||||
self.assertEquals(self.lru[2], 'asdf')
|
||||
self.assertEquals(self.lru[4], 'asdf')
|
||||
self.assertEquals(self.lru[5], 'asdf')
|
||||
self.assertEqual(self.lru[1], 'asdf')
|
||||
self.assertEqual(self.lru[2], 'asdf')
|
||||
self.assertEqual(self.lru[4], 'asdf')
|
||||
self.assertEqual(self.lru[5], 'asdf')
|
||||
|
||||
# 3 should be evicted now
|
||||
self.lru[6] = 'asdf'
|
||||
|
||||
self.assertRaises(KeyError, self.lru.__getitem__, 3)
|
||||
self.assertEquals(self.lru[1], 'asdf')
|
||||
self.assertEquals(self.lru[2], 'asdf')
|
||||
self.assertEquals(self.lru[4], 'asdf')
|
||||
self.assertEquals(self.lru[5], 'asdf')
|
||||
self.assertEquals(self.lru[6], 'asdf')
|
||||
self.assertEqual(self.lru[1], 'asdf')
|
||||
self.assertEqual(self.lru[2], 'asdf')
|
||||
self.assertEqual(self.lru[4], 'asdf')
|
||||
self.assertEqual(self.lru[5], 'asdf')
|
||||
self.assertEqual(self.lru[6], 'asdf')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import unittest
|
||||
|
||||
from itertools import chain, izip
|
||||
from itertools import chain
|
||||
|
||||
from overviewer_core.tileset import iterate_base4, RendertileSet
|
||||
from overviewer_core.util import roundrobin
|
||||
@@ -150,7 +150,7 @@ class RendertileSetTest(unittest.TestCase):
|
||||
self.assertRaises(AssertionError, self.test_iterate)
|
||||
|
||||
def test_count(self):
|
||||
self.assertEquals(self.tree.count(), len(self.tile_paths))
|
||||
self.assertEqual(self.tree.count(), len(self.tile_paths))
|
||||
|
||||
def test_bool(self):
|
||||
"Tests the boolean status of a node"
|
||||
@@ -202,7 +202,7 @@ class RendertileSetTest(unittest.TestCase):
|
||||
"""Test a post-traversal of the tree's dirty tiles"""
|
||||
# Expect the results in this proper order.
|
||||
iterator = iter(self.tree.posttraversal())
|
||||
for expected, actual in izip(self.tile_paths_posttraversal, iterator):
|
||||
for expected, actual in zip(self.tile_paths_posttraversal, iterator):
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
self.assertRaises(StopIteration, next, iterator)
|
||||
@@ -211,7 +211,7 @@ class RendertileSetTest(unittest.TestCase):
|
||||
"""Test a round-robin post-traversal of the tree's dirty tiles"""
|
||||
# Expect the results in this proper order.
|
||||
iterator = iter(self.tree.posttraversal(robin=True))
|
||||
for expected, actual in izip(self.tile_paths_posttraversal_robin, iterator):
|
||||
for expected, actual in zip(self.tile_paths_posttraversal_robin, iterator):
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
self.assertRaises(StopIteration, next, iterator)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
from collections import OrderedDict
|
||||
|
||||
from overviewer_core import configParser
|
||||
from overviewer_core.settingsValidators import ValidationException
|
||||
@@ -6,7 +7,6 @@ from overviewer_core.settingsValidators import ValidationException
|
||||
from overviewer_core import world
|
||||
from overviewer_core import rendermodes
|
||||
|
||||
from overviewer_core.util import OrderedDict
|
||||
|
||||
class SettingsTest(unittest.TestCase):
|
||||
|
||||
@@ -23,12 +23,12 @@ class SettingsTest(unittest.TestCase):
|
||||
# no exceptions so far. that's a good thing
|
||||
|
||||
# Test the default
|
||||
self.assertEquals(things['renders']['myworld']['bgcolor'], (26,26,26,0))
|
||||
self.assertEqual(things['renders']['myworld']['bgcolor'], (26,26,26,0))
|
||||
|
||||
# Test a non-default
|
||||
self.assertEquals(things['renders']['otherworld']['bgcolor'], (255,255,255,0))
|
||||
self.assertEqual(things['renders']['otherworld']['bgcolor'], (255,255,255,0))
|
||||
|
||||
self.assertEquals(things['renders']['myworld']['northdirection'],
|
||||
self.assertEqual(things['renders']['myworld']['northdirection'],
|
||||
world.UPPER_LEFT)
|
||||
|
||||
def test_rendermode_validation(self):
|
||||
@@ -63,7 +63,7 @@ class SettingsTest(unittest.TestCase):
|
||||
}),
|
||||
]))
|
||||
self.s.set_config_item("outputdir", "/tmp/fictional/outputdir")
|
||||
self.assertEquals(fromfile.get_validated_config(), self.s.get_validated_config())
|
||||
self.assertEqual(fromfile.get_validated_config(), self.s.get_validated_config())
|
||||
|
||||
def test_rendermode_string(self):
|
||||
self.s.set_config_item("worlds", {
|
||||
@@ -79,7 +79,7 @@ class SettingsTest(unittest.TestCase):
|
||||
},
|
||||
})
|
||||
p = self.s.get_validated_config()
|
||||
self.assertEquals(p['renders']['myworld']['rendermode'], rendermodes.normal)
|
||||
self.assertEqual(p['renders']['myworld']['rendermode'], rendermodes.normal)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -50,11 +50,11 @@ class FakeRegionset(object):
|
||||
return NotImplementedError()
|
||||
|
||||
def iterate_chunks(self):
|
||||
for (x,z),mtime in self.chunks.iteritems():
|
||||
for (x,z),mtime in self.chunks.items():
|
||||
yield x,z,mtime
|
||||
|
||||
def iterate_newer_chunks(self, filemtime):
|
||||
for (x,z),mtime in self.chunks.iteritems():
|
||||
for (x,z),mtime in self.chunks.items():
|
||||
yield x,z,mtime
|
||||
|
||||
def get_chunk_mtime(self, x, z):
|
||||
@@ -77,7 +77,7 @@ def get_tile_set(chunks):
|
||||
the compare_iterate_to_expected() method.
|
||||
"""
|
||||
tile_set = defaultdict(int)
|
||||
for (chunkx, chunkz), chunkmtime in chunks.iteritems():
|
||||
for (chunkx, chunkz), chunkmtime in chunks.items():
|
||||
|
||||
col, row = tileset.convert_coords(chunkx, chunkz)
|
||||
|
||||
@@ -86,9 +86,9 @@ def get_tile_set(chunks):
|
||||
tile_set[tile.path] = max(tile_set[tile.path], chunkmtime)
|
||||
|
||||
# At this point, tile_set holds all the render-tiles
|
||||
for tile, tile_mtime in tile_set.copy().iteritems():
|
||||
for tile, tile_mtime in tile_set.copy().items():
|
||||
# All render-tiles are length 5. Hard-code its upper tiles
|
||||
for i in reversed(xrange(5)):
|
||||
for i in reversed(range(5)):
|
||||
tile_set[tile[:i]] = max(tile_set[tile[:i]], tile_mtime)
|
||||
return dict(tile_set)
|
||||
|
||||
@@ -98,7 +98,7 @@ def create_fakedir(outputdir, tiles):
|
||||
files) and sets mtimes appropriately
|
||||
|
||||
"""
|
||||
for tilepath, tilemtime in tiles.iteritems():
|
||||
for tilepath, tilemtime in tiles.items():
|
||||
dirpath = os.path.join(outputdir, *(str(x) for x in tilepath[:-1]))
|
||||
if len(tilepath) == 0:
|
||||
imgname = "base.png"
|
||||
@@ -175,7 +175,7 @@ class TilesetTest(unittest.TestCase):
|
||||
self.assertTrue(tilepath in expected, "%s was not expected to be returned. Expected %s" % (tilepath, expected))
|
||||
|
||||
# Now check that all expected tiles were indeed returned
|
||||
for tilepath in expected.iterkeys():
|
||||
for tilepath in expected.keys():
|
||||
self.assertTrue(tilepath in paths, "%s was expected to be returned but wasn't: %s" % (tilepath, paths))
|
||||
|
||||
def test_get_phase_length(self):
|
||||
@@ -215,7 +215,7 @@ class TilesetTest(unittest.TestCase):
|
||||
"""Same as above but with a different set of chunks
|
||||
"""
|
||||
# Pick 3 random chunks to update
|
||||
chunks = self.rs.chunks.keys()
|
||||
chunks = list(self.rs.chunks.keys())
|
||||
self.r.shuffle(chunks)
|
||||
updated_chunks = {}
|
||||
for key in chunks[:3]:
|
||||
|
||||
@@ -17,19 +17,19 @@ class ExampleWorldTest(unittest.TestCase):
|
||||
w = world.World("test/data/worlds/exmaple")
|
||||
|
||||
regionsets = w.get_regionsets()
|
||||
self.assertEquals(len(regionsets), 3)
|
||||
self.assertEqual(len(regionsets), 3)
|
||||
|
||||
regionset = regionsets[0]
|
||||
self.assertEquals(regionset.get_region_path(0,0), 'test/data/worlds/exmaple/DIM-1/region/r.0.0.mcr')
|
||||
self.assertEquals(regionset.get_region_path(-1,0), 'test/data/worlds/exmaple/DIM-1/region/r.-1.0.mcr')
|
||||
self.assertEquals(regionset.get_region_path(1,1), 'test/data/worlds/exmaple/DIM-1/region/r.0.0.mcr')
|
||||
self.assertEquals(regionset.get_region_path(35,35), None)
|
||||
self.assertEqual(regionset.get_region_path(0,0), 'test/data/worlds/exmaple/DIM-1/region/r.0.0.mcr')
|
||||
self.assertEqual(regionset.get_region_path(-1,0), 'test/data/worlds/exmaple/DIM-1/region/r.-1.0.mcr')
|
||||
self.assertEqual(regionset.get_region_path(1,1), 'test/data/worlds/exmaple/DIM-1/region/r.0.0.mcr')
|
||||
self.assertEqual(regionset.get_region_path(35,35), None)
|
||||
|
||||
# a few random chunks. reference timestamps fetched with libredstone
|
||||
self.assertEquals(regionset.get_chunk_mtime(0,0), 1316728885)
|
||||
self.assertEquals(regionset.get_chunk_mtime(-1,-1), 1316728886)
|
||||
self.assertEquals(regionset.get_chunk_mtime(5,0), 1316728905)
|
||||
self.assertEquals(regionset.get_chunk_mtime(-22,16), 1316786786)
|
||||
self.assertEqual(regionset.get_chunk_mtime(0,0), 1316728885)
|
||||
self.assertEqual(regionset.get_chunk_mtime(-1,-1), 1316728886)
|
||||
self.assertEqual(regionset.get_chunk_mtime(5,0), 1316728905)
|
||||
self.assertEqual(regionset.get_chunk_mtime(-22,16), 1316786786)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user