tests now clean up after themselves
This commit is contained in:
parent
c5479867af
commit
882e1b36f7
19
tests.py
19
tests.py
@ -15,17 +15,22 @@ import tempfile
|
|||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
from os.path import join
|
||||||
import numpy
|
import numpy
|
||||||
from numpy import *
|
from numpy import *
|
||||||
from logging import info
|
from logging import info
|
||||||
from pymclevel.infiniteworld import MCServerChunkGenerator
|
from pymclevel.infiniteworld import MCServerChunkGenerator
|
||||||
#logging.basicConfig(format=u'%(levelname)s:%(message)s')
|
#logging.basicConfig(format=u'%(levelname)s:%(message)s')
|
||||||
#logging.getLogger().level = logging.INFO
|
#logging.getLogger().level = logging.INFO
|
||||||
|
def mktemp(suffix):
|
||||||
|
td = tempfile.mkdtemp(suffix)
|
||||||
|
os.rmdir(td)
|
||||||
|
return td
|
||||||
|
|
||||||
class TempLevel(object):
|
class TempLevel(object):
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
filename = os.path.join("testfiles", filename)
|
filename = join("testfiles", filename)
|
||||||
#def tempCopy(filename):
|
#def tempCopy(filename):
|
||||||
if os.path.isdir(filename):
|
if os.path.isdir(filename):
|
||||||
tmpname = tempfile.mkdtemp(os.path.basename(filename))
|
tmpname = tempfile.mkdtemp(os.path.basename(filename))
|
||||||
@ -98,8 +103,10 @@ class TestJavaLevel(unittest.TestCase):
|
|||||||
|
|
||||||
class TestAlphaLevelCreate(unittest.TestCase):
|
class TestAlphaLevelCreate(unittest.TestCase):
|
||||||
def testCreate(self):
|
def testCreate(self):
|
||||||
temppath = tempfile.mktemp("AlphaCreate")
|
temppath = mktemp("AlphaCreate")
|
||||||
self.alphaLevel = MCInfdevOldLevel(filename=temppath, create=True);
|
self.alphaLevel = MCInfdevOldLevel(filename=temppath, create=True);
|
||||||
|
self.alphaLevel.close()
|
||||||
|
shutil.rmtree(temppath)
|
||||||
|
|
||||||
class TestAlphaLevel(unittest.TestCase):
|
class TestAlphaLevel(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -194,7 +201,8 @@ class TestSchematics(unittest.TestCase):
|
|||||||
#info("Schematic from indev")
|
#info("Schematic from indev")
|
||||||
|
|
||||||
size = (64, 64, 64)
|
size = (64, 64, 64)
|
||||||
schematic = MCSchematic(shape=size, filename="hell.schematic", mats='Classic');
|
temp = mktemp("testcreate.schematic")
|
||||||
|
schematic = MCSchematic(shape=size, filename=temp, mats='Classic');
|
||||||
level = self.indevlevel.level
|
level = self.indevlevel.level
|
||||||
|
|
||||||
self.failUnlessRaises(ValueError, lambda:(
|
self.failUnlessRaises(ValueError, lambda:(
|
||||||
@ -224,6 +232,9 @@ class TestSchematics(unittest.TestCase):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
|
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
|
||||||
|
schematic.close()
|
||||||
|
os.remove(temp)
|
||||||
|
|
||||||
def testRotate(self):
|
def testRotate(self):
|
||||||
level = self.indevlevel.level
|
level = self.indevlevel.level
|
||||||
schematic = level.extractSchematic(level.bounds)
|
schematic = level.extractSchematic(level.bounds)
|
||||||
@ -236,6 +247,8 @@ class TestSchematics(unittest.TestCase):
|
|||||||
box = BoundingBox((0, 0, 0), (64, 64, 64,))
|
box = BoundingBox((0, 0, 0), (64, 64, 64,))
|
||||||
zs = level.extractZipSchematic(box)
|
zs = level.extractZipSchematic(box)
|
||||||
assert(box.chunkCount == zs.chunkCount)
|
assert(box.chunkCount == zs.chunkCount)
|
||||||
|
zs.close()
|
||||||
|
os.remove(zs.filename)
|
||||||
|
|
||||||
def testINVEditChests(self):
|
def testINVEditChests(self):
|
||||||
info("INVEdit chest")
|
info("INVEdit chest")
|
||||||
|
Reference in New Issue
Block a user