pyflakes helped fixes: tests.py: unravel import all of numpy and pymclevel modules

This commit is contained in:
David Sowder 2012-03-04 09:20:06 -06:00
parent fb6b4aa05a
commit f3648cadcd

View File

@ -3,30 +3,26 @@ Created on Jul 23, 2011
@author: Rio @author: Rio
''' '''
# from mclevel import fromFile, loadWorldNumber, BoundingBox
# from infiniteworld import MCInfdevOldLevel
# from schematic import MCSchematic
# import errorreporting # annotate tracebacks with call arguments
try:
from pymclevel import *
except ImportError:
from __init__ import *
# from mclevel import loadWorldNumber, BoundingBox
# import errorreporting # annotate tracebacks with call arguments
from box import BoundingBox
from cStringIO import StringIO from cStringIO import StringIO
from entity import Entity, TileEntity
from infiniteworld import MCInfdevOldLevel, MCServerChunkGenerator
import itertools import itertools
import unittest
import tempfile
import logging import logging
import shutil import mclevel
import nbt
import numpy
import os import os
from os.path import join from os.path import join
from schematic import MCSchematic
import shutil
import tempfile
import time import time
import unittest
import numpy
from numpy import *
from box import BoundingBox
from infiniteworld import MCServerChunkGenerator
import nbt
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
warn, error, info, debug = log.warn, log.error, log.info, log.debug warn, error, info, debug = log.warn, log.error, log.info, log.debug
@ -54,7 +50,7 @@ class TempLevel(object):
else: else:
createFunc(tmpname) createFunc(tmpname)
self.tmpname = tmpname self.tmpname = tmpname
self.level = fromFile(tmpname) self.level = mclevel.fromFile(tmpname)
def __del__(self): def __del__(self):
self.level.close() self.level.close()
@ -118,7 +114,7 @@ class TestNBT(unittest.TestCase):
"Byte arrays are stored as numpy.uint8 arrays. " "Byte arrays are stored as numpy.uint8 arrays. "
mapTag["Blocks"] = nbt.TAG_Byte_Array() mapTag["Blocks"] = nbt.TAG_Byte_Array()
mapTag["Blocks"].value = zeros(l * w * h, dtype=uint8) # create lots of air! mapTag["Blocks"].value = numpy.zeros(l * w * h, dtype=numpy.uint8) # create lots of air!
"The blocks array is indexed (y,z,x) for indev levels, so reshape the blocks" "The blocks array is indexed (y,z,x) for indev levels, so reshape the blocks"
mapTag["Blocks"].value.shape = (h, l, w) mapTag["Blocks"].value.shape = (h, l, w)
@ -129,7 +125,7 @@ class TestNBT(unittest.TestCase):
"This is a great way to learn the power of numpy array slicing and indexing." "This is a great way to learn the power of numpy array slicing and indexing."
mapTag["Data"] = nbt.TAG_Byte_Array() mapTag["Data"] = nbt.TAG_Byte_Array()
mapTag["Data"].value = zeros(l * w * h, dtype=uint8) mapTag["Data"].value = numpy.zeros(l * w * h, dtype=numpy.uint8)
return level return level
@ -289,7 +285,7 @@ class TestAlphaLevel(unittest.TestCase):
level = self.alphalevel.level level = self.alphalevel.level
cx, cz = level.allChunks.next() cx, cz = level.allChunks.next()
schem = fromFile("schematics/CreativeInABox.schematic") schem = mclevel.fromFile("schematics/CreativeInABox.schematic")
box = BoundingBox((cx * 16, 64, cz * 16), schem.bounds.size) box = BoundingBox((cx * 16, 64, cz * 16), schem.bounds.size)
level.copyBlocksFrom(schem, schem.bounds, (0, 64, 0)) level.copyBlocksFrom(schem, schem.bounds, (0, 64, 0))
schem = MCSchematic(shape=schem.bounds.size) schem = MCSchematic(shape=schem.bounds.size)
@ -343,7 +339,7 @@ class TestAlphaLevel(unittest.TestCase):
d = {} d = {}
keys = 'Blocks Data SkyLight BlockLight'.split() keys = 'Blocks Data SkyLight BlockLight'.split()
for key in keys: for key in keys:
d[key] = array(getattr(ch, key)) d[key] = numpy.array(getattr(ch, key))
for i in range(5): for i in range(5):
level.saveInPlace() level.saveInPlace()
@ -390,7 +386,7 @@ class TestSchematics(unittest.TestCase):
schematic.saveInPlace() schematic.saveInPlace()
schem = fromFile("schematics/CreativeInABox.schematic") schem = mclevel.fromFile("schematics/CreativeInABox.schematic")
tempSchematic = MCSchematic(shape=(1, 1, 3)) tempSchematic = MCSchematic(shape=(1, 1, 3))
tempSchematic.copyBlocksFrom(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 0, 0)) tempSchematic.copyBlocksFrom(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 0, 0))
@ -422,7 +418,7 @@ class TestSchematics(unittest.TestCase):
def testINVEditChests(self): def testINVEditChests(self):
info("INVEdit chest") info("INVEdit chest")
invFile = fromFile("schematics/Chests/TinkerersBox.inv") invFile = mclevel.fromFile("schematics/Chests/TinkerersBox.inv")
info("Blocks: %s", invFile.Blocks) info("Blocks: %s", invFile.Blocks)
info("Data: %s", invFile.Data) info("Data: %s", invFile.Data)
info("Entities: %s", invFile.Entities) info("Entities: %s", invFile.Entities)
@ -441,7 +437,7 @@ class TestPocket(unittest.TestCase):
# alphalevel = self.alphalevel.level # alphalevel = self.alphalevel.level
print "Chunk count", len(level.allChunks) print "Chunk count", len(level.allChunks)
chunk = level.getChunk(1, 5) chunk = level.getChunk(1, 5)
a = array(chunk.SkyLight) a = numpy.array(chunk.SkyLight)
level.saveInPlace() level.saveInPlace()
assert (a == chunk.SkyLight).all() assert (a == chunk.SkyLight).all()
@ -462,7 +458,7 @@ class TestAnvil(TestAlphaLevel):
hm = chunk["Level"]["HeightMap"] hm = chunk["Level"]["HeightMap"]
hm.value[2] = 500 hm.value[2] = 500
oldhm = array(hm.value) oldhm = numpy.array(hm.value)
filename = mktemp("ChangedChunk") filename = mktemp("ChangedChunk")
chunk.save(filename) chunk.save(filename)