Rework test suite to use pytest fixtures in conftest.py

This commit is contained in:
David Vierra 2015-09-22 16:38:06 -10:00
parent fd98d50c4e
commit 9ef15e0890
11 changed files with 208 additions and 218 deletions

View File

@ -9,7 +9,7 @@ from mceditlib.test.templevel import TempFile
log = logging.getLogger(__name__)
chain = RevisionHistory(TempFile("test_files/AnvilWorld"))
chain = RevisionHistory(TempFile("AnvilWorld"))
chunkPositions = list(chain.getHead().chunkPositions(""))

View File

@ -3,7 +3,6 @@ import os
import shutil
import numpy
import py.test
from mceditlib.anvil.adapter import AnvilWorldAdapter
from mceditlib.util import exhaust
@ -11,48 +10,39 @@ from mceditlib.worldeditor import WorldEditor
from mceditlib import nbt
from mceditlib.selection import BoundingBox
from mceditlib.pc.regionfile import RegionFile
from templevel import mktemp, TempLevel, TempFile
from templevel import mktemp, TempFile
__author__ = 'Rio'
def testCreate():
temppath = mktemp("AnvilCreate")
anvilLevel = WorldEditor(filename=temppath, create=True, adapterClass=AnvilWorldAdapter)
anvilLevel.close()
pc_world = WorldEditor(filename=temppath, create=True, adapterClass=AnvilWorldAdapter)
pc_world.close()
shutil.rmtree(temppath)
@py.test.fixture
def sourceLevel():
return TempLevel("Station.schematic")
@py.test.fixture
def anvilLevel():
return TempLevel("AnvilWorld")
def testCreateChunks(anvilLevel):
dim = anvilLevel.getDimension()
def testCreateChunks(pc_world):
dim = pc_world.getDimension()
for ch in list(dim.chunkPositions()):
dim.deleteChunk(*ch)
for ch in BoundingBox((0, 0, 0), (32, 0, 32)).chunkPositions():
dim.createChunk(*ch)
def testRecreateChunks(anvilLevel):
dim = anvilLevel.getDimension()
def testRecreateChunks(pc_world):
dim = pc_world.getDimension()
for x, z in itertools.product(xrange(-1, 3), xrange(-1, 2)):
dim.deleteChunk(x, z)
assert not dim.containsChunk(x, z)
dim.createChunk(x, z)
def testCopyRelight(anvilLevel, sourceLevel):
destDim = anvilLevel.getDimension()
exhaust(destDim.copyBlocksIter(sourceLevel.getDimension(), BoundingBox((0, 0, 0), (32, 64, 32,)),
def testCopyRelight(pc_world, schematic_world):
destDim = pc_world.getDimension()
exhaust(destDim.copyBlocksIter(schematic_world.getDimension(), BoundingBox((0, 0, 0), (32, 64, 32,)),
destDim.bounds.origin))
anvilLevel.saveChanges()
pc_world.saveChanges()
def testRecompress(anvilLevel):
dim = anvilLevel.getDimension()
def testRecompress(pc_world):
dim = pc_world.getDimension()
keys = 'Blocks Data SkyLight BlockLight'.split()
cx, cz = iter(dim.chunkPositions()).next()
@ -70,7 +60,7 @@ def testRecompress(anvilLevel):
d[key] = numpy.array(getattr(section, key))
for i in range(5):
anvilLevel.saveChanges()
pc_world.saveChanges()
section = dim.getChunk(cx, cz).getSection(cy)
section.dirty = True
assert (section.Data == 13).all()
@ -81,7 +71,7 @@ def testBigEndianIntHeightMap():
""" Test modifying, saving, and loading the new TAG_Int_Array heightmap
added with the Anvil format.
"""
region = RegionFile(TempFile("test_files/AnvilWorld/region/r.0.0.mca"))
region = RegionFile(TempFile("AnvilWorld/region/r.0.0.mca"))
chunk_data = region.readChunkBytes(0, 0)
chunk = nbt.load(buf=chunk_data)

View File

@ -4,52 +4,44 @@
from __future__ import absolute_import, division, print_function
from collections import deque
import logging
import pytest
from mceditlib.test.templevel import TempLevel
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
@pytest.fixture(params=["AnvilWorld"])
def world(request):
return TempLevel(request.param)
def testThrashing(world):
if not hasattr(world, '_chunkDataCache'):
def testThrashing(pc_world):
if not hasattr(pc_world, '_chunkDataCache'):
return
world.setCacheLimit(50)
dim = world.getDimension()
pc_world.setCacheLimit(50)
dim = pc_world.getDimension()
recent = deque(maxlen=10)
for cx, cz in dim.chunkPositions():
chunk = dim.getChunk(cx, cz)
for lastChunkPos in recent:
if lastChunkPos not in world._chunkDataCache:
if lastChunkPos not in pc_world._chunkDataCache:
raise ValueError(
"Cache thrashing detected! %s no longer in cache. (cache has %d stored, %d hits %d misses)\n"
"Cache keys: %s" % (
lastChunkPos, len(world._chunkDataCache.cache), world._chunkDataCache.hits,
world._chunkDataCache.misses,
list(world._chunkDataCache)))
lastChunkPos, len(pc_world._chunkDataCache.cache), pc_world._chunkDataCache.hits,
pc_world._chunkDataCache.misses,
list(pc_world._chunkDataCache)))
recent.append((cx, cz, ""))
def testOldThrashing(world):
if not hasattr(world, '_loadedChunkData'):
def testOldThrashing(pc_world):
if not hasattr(pc_world, '_loadedChunkData'):
return
world.loadedChunkLimit = 50
dim = world.getDimension()
pc_world.loadedChunkLimit = 50
dim = pc_world.getDimension()
recent = deque(maxlen=10)
for cx, cz in dim.chunkPositions():
chunk = dim.getChunk(cx, cz)
for lastChunkPos in recent:
if lastChunkPos not in world._loadedChunkData:
if lastChunkPos not in pc_world._loadedChunkData:
raise ValueError("Cache thrashing detected! %s no longer in cache. \n"
"Cache keys: %s" % (
lastChunkPos,
world._loadedChunkData.keys()))
pc_world._loadedChunkData.keys()))
recent.append((cx, cz, ""))
log.info("Finished. %d in cache.", len(world._loadedChunkData))
log.info("Finished. %d in cache.", len(pc_world._loadedChunkData))

View File

@ -0,0 +1,34 @@
"""
conftest
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import zipfile
import pytest
from mceditlib.test.templevel import TempLevel
log = logging.getLogger(__name__)
@pytest.fixture
def pc_world():
return TempLevel("AnvilWorld")
@pytest.fixture(params=["Station.schematic"])
def schematic_world(request):
return TempLevel(request.param)
@pytest.fixture(params=["AnvilWorld", "Floating.schematic"])
# , "MCRWorld", "city_256_256_128.dat", "PocketWorldAdapter.zip"
def any_world(request):
if request.param == "PocketWorldAdapter.zip":
def unpackPocket(tmpname):
zf = zipfile.ZipFile("test_files/PocketWorldAdapter.zip")
zf.extractall(tmpname)
return WorldEditor(tmpname + "/PocketWorldAdapter")
return TempLevel("XXX", createFunc=unpackPocket)
return TempLevel(request.param)

View File

@ -1,4 +1,3 @@
import zipfile
import numpy
import pytest
import logging
@ -6,48 +5,30 @@ from mceditlib.blocktypes import blocktypeConverter
from mceditlib.export import extractSchematicFrom
from mceditlib.selection import BoundingBox
from mceditlib import block_copy
from mceditlib.worldeditor import WorldEditor
from templevel import TempLevel
logging.basicConfig(level=logging.INFO)
__author__ = 'Rio'
@pytest.fixture(params=["AnvilWorld", "Floating.schematic"])
# , "MCRWorld", "city_256_256_128.dat", "PocketWorldAdapter.zip"
def world(request):
if request.param == "PocketWorldAdapter.zip":
def unpackPocket(tmpname):
zf = zipfile.ZipFile("test_files/PocketWorldAdapter.zip")
zf.extractall(tmpname)
return WorldEditor(tmpname + "/PocketWorldAdapter")
return TempLevel("XXX", createFunc=unpackPocket)
return TempLevel(request.param)
@pytest.fixture(params=["Station.schematic"])
def sourceLevel(request):
return TempLevel(request.param)
def testGetEntities(world):
dim = world.getDimension()
def testGetEntities(any_world):
dim = any_world.getDimension()
print len(list(dim.getEntities(dim.bounds)))
def testImportAndConvert(world, sourceLevel):
destDim = world.getDimension()
sourceDim = sourceLevel.getDimension()
def testImportAndConvert(any_world, schematic_world):
destDim = any_world.getDimension()
sourceDim = schematic_world.getDimension()
destPoint = sourceDim.bounds.origin
oldEntityCount = len(list(destDim.getEntities(BoundingBox(destPoint, sourceDim.bounds.size))))
destDim.copyBlocks(sourceDim, sourceDim.bounds, destPoint, create=True)
convertBlocks = blocktypeConverter(world, sourceLevel)
convertBlocks = blocktypeConverter(any_world.blocktypes, schematic_world.blocktypes)
for sourceChunk in sourceDim.getChunks():
cx = sourceChunk.cx
@ -76,14 +57,14 @@ def testImportAndConvert(world, sourceLevel):
== len(list(destDim.getEntities(sourceDim.bounds))))
def testFill(world):
dim = world.getDimension()
def testFill(any_world):
dim = any_world.getDimension()
bounds = dim.bounds
box = BoundingBox(bounds.origin + (bounds.size / 2), (64, bounds.height / 2, 64))
x, y, z = numpy.array(list(box.positions)).transpose()
dim.fillBlocks(box, world.blocktypes["planks"])
dim.fillBlocks(box, any_world.blocktypes["planks"])
def checkEqual(a, b):
"""
@ -100,38 +81,38 @@ def testFill(world):
for cy in chunk.bounds.sectionPositions(*cp):
assert chunk.getSection(cy) is not None, "Section %s not found" % cy
checkEqual(dim.getBlocks(x, y, z).Blocks, world.blocktypes["planks"].ID)
checkEqual(dim.getBlocks(x, y, z).Blocks, any_world.blocktypes["planks"].ID)
dim.fillBlocks(box, world.blocktypes["stone"], [world.blocktypes["planks"]])
world.saveChanges()
world.close()
dim.fillBlocks(box, any_world.blocktypes["stone"], [any_world.blocktypes["planks"]])
any_world.saveChanges()
any_world.close()
filename = world.filename
world = WorldEditor(filename)
checkEqual(world.getDimension().getBlocks(x, y, z).Blocks, world.blocktypes["stone"].ID)
filename = any_world.filename
any_world = WorldEditor(filename)
checkEqual(any_world.getDimension().getBlocks(x, y, z).Blocks, any_world.blocktypes["stone"].ID)
def testOldReplace(world):
dim = world.getDimension()
dim.fillBlocks(BoundingBox((-11, 0, -7), (38, dim.bounds.height, 25)), world.blocktypes["planks"],
[world.blocktypes["dirt"], world.blocktypes["grass"]])
def testOldReplace(any_world):
dim = any_world.getDimension()
dim.fillBlocks(BoundingBox((-11, 0, -7), (38, dim.bounds.height, 25)), any_world.blocktypes["planks"],
[any_world.blocktypes["dirt"], any_world.blocktypes["grass"]])
def testMultiReplace(world):
dim = world.getDimension()
def testMultiReplace(any_world):
dim = any_world.getDimension()
dim.fillBlocks(BoundingBox((-11, 0, -7), (38, dim.bounds.height, 25)),
[(world.blocktypes["planks"], world.blocktypes["dirt"]),
(world.blocktypes["grass"], world.blocktypes["iron_ore"])])
[(any_world.blocktypes["planks"], any_world.blocktypes["dirt"]),
(any_world.blocktypes["grass"], any_world.blocktypes["iron_ore"])])
def testImport(world, sourceLevel):
dim = world.getDimension()
dim.copyBlocks(sourceLevel.getDimension(), BoundingBox((0, 0, 0), (32, 64, 32,)), dim.bounds.origin)
world.saveChanges()
def testImport(any_world, schematic_world):
dim = any_world.getDimension()
dim.copyBlocks(schematic_world.getDimension(), BoundingBox((0, 0, 0), (32, 64, 32,)), dim.bounds.origin)
any_world.saveChanges()
def testExportImport(world):
dim = world.getDimension()
def testExportImport(any_world):
dim = any_world.getDimension()
schem = extractSchematicFrom(dim, dim.bounds)
schemDim = schem.getDimension()

View File

@ -3,7 +3,7 @@ import time
import zipfile
import numpy
from mceditlib import nbt
from templevel import TempLevel
from templevel import TempFile
__author__ = 'Rio'
@ -11,7 +11,7 @@ class TestNBT():
def testLoad(self):
"Load an indev level."
level = nbt.load("test_files/indev.mclevel")
level = nbt.load(TempFile("indev.mclevel"))
# The root tag must have a name, and so must any tag within a TAG_Compound
print level.name
@ -25,7 +25,7 @@ class TestNBT():
return level
def testLoadUncompressed(self):
rootTag = nbt.load("test_files/uncompressed.nbt")
rootTag = nbt.load(TempFile("uncompressed.nbt"))
def testCreate(self):
"Create an indev level."
@ -163,16 +163,3 @@ class TestNBT():
else:
assert False
def testSpeed(self):
d = join("test_files", "TileTicks_chunks.zip")
zf = zipfile.ZipFile(d)
files = [zf.read(f) for f in zf.namelist()[:40]]
startTime = time.time()
for f in files:
if len(f):
n = nbt.load(buf=f)
duration = time.time() - startTime
assert duration < 1.0 # Will fail when not using _nbt.pyx

View File

@ -6,45 +6,44 @@ import numpy
logging.basicConfig(level=logging.INFO)
def test_relight():
templevel = TempLevel("AnvilWorld")
anvilLevel = templevel
anvilDim = anvilLevel.getDimension()
pc_world = TempLevel("AnvilWorld")
anvilDim = pc_world.getDimension()
bounds = anvilDim.bounds
point = bounds.origin + (bounds.size * (0.5, 0.5, 0.5))
box = bounds.expand(-100, 0, -100)
# box = BoundingBox((256, 0, 256), (64, anvilLevel.Height, 64))
# box = BoundingBox((256, 0, 256), (64, pc_world.Height, 64))
chunks = [(cx, cz) for cx, cz in anvilDim.chunkPositions() if (cx << 4, 1, cz << 4) not in box]
for c in chunks:
anvilDim.deleteChunk(*c)
#anvilLevel = WorldEditor(filename=temppath, create=True)
station = WorldEditor("test_files/station.schematic")
#pc_world = WorldEditor(filename=temppath, create=True)
station = TempLevel("station.schematic")
stationDim = station.getDimension()
anvilDim.copyBlocks(stationDim, stationDim.bounds, point, create=True)
for cPos in anvilDim.chunkPositions():
anvilDim.getChunk(*cPos)
#anvilLevel.copyBlocksFrom(station, station.bounds, point + (station.Width, 0, 0), create=True)
anvilLevel.generateLights()
#pc_world.copyBlocksFrom(station, station.bounds, point + (station.Width, 0, 0), create=True)
pc_world.generateLights()
anvilLevel.saveChanges()
pc_world.saveChanges()
cx = int(point.x + 32) >> 4
cz = int(point.z + 32) >> 4
# os.system(sys.executable + " ../mcedit.py " + anvilLevel.filename)
# os.system(sys.executable + " ../mcedit.py " + pc_world.filename)
def check():
sl = numpy.sum(anvilLevel.getChunk(cx, cz).SkyLight)
bl = numpy.sum(anvilLevel.getChunk(cx, cz).BlockLight)
sl = numpy.sum(pc_world.getChunk(cx, cz).SkyLight)
bl = numpy.sum(pc_world.getChunk(cx, cz).BlockLight)
assert (sl, bl) == (341328, 43213)
check()
anvilLevel.close()
pc_world.close()
anvilLevel = WorldEditor(templevel.tmpname)
pc_world = WorldEditor(templevel.tmpname)
check()

View File

@ -16,7 +16,7 @@ from mceditlib import nbt
@pytest.fixture
def history():
filename = "test_files/AnvilWorld"
filename = "AnvilWorld"
tmpname = TempFile(filename)
return RevisionHistory(tmpname)

View File

@ -1,6 +1,7 @@
import itertools
import os
import unittest
import pytest
from mceditlib.worldeditor import WorldEditor
from templevel import TempLevel, mktemp
from mceditlib.schematic import SchematicFileAdapter, createSchematic
@ -8,86 +9,84 @@ from mceditlib.selection import BoundingBox
__author__ = 'Rio'
class TestSchematics(unittest.TestCase):
def setUp(self):
# self.alphaLevel = TempLevel("Dojo_64_64_128.dat")
self.schematicLevel = TempLevel("Floating.schematic")
self.anvilLevel = TempLevel("AnvilWorld")
def testCreate(self):
# log.info("Schematic from indev")
@pytest.skip("Classic not implemented")
def testCreate(self):
size = (64, 64, 64)
temp = mktemp("testcreate.schematic")
editor = createSchematic(shape=size, blocktypes='Classic')
editor.filename = temp
dim = editor.getDimension()
level = self.schematicLevel
# log.info("Schematic from indev")
dim.importSchematic(level, (0, 0, 0))
assert((schematic.Blocks[0:64, 0:64, 0:64] == level.adapter.Blocks[0:64, 0:64, 0:64]).all())
size = (64, 64, 64)
temp = mktemp("testcreate.schematic")
editor = createSchematic(shape=size, blocktypes='Classic')
editor.filename = temp
dim = editor.getDimension()
level = self.schematicLevel
dim.importSchematic(level, (-32, -32, -32))
assert((schematic.Blocks[0:32, 0:32, 0:32] == level.adapter.Blocks[32:64, 32:64, 32:64]).all())
dim.importSchematic(level, (0, 0, 0))
assert((schematic.Blocks[0:64, 0:64, 0:64] == level.adapter.Blocks[0:64, 0:64, 0:64]).all())
schematic.saveChanges()
dim.importSchematic(level, (-32, -32, -32))
assert((schematic.Blocks[0:32, 0:32, 0:32] == level.adapter.Blocks[32:64, 32:64, 32:64]).all())
schem = WorldEditor("test_files/Station.schematic")
tempEditor = createSchematic(shape=(1, 1, 3))
tempDim = tempEditor.getDimension()
tempDim.copyBlocks(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 0, 0))
schematic.saveChanges()
level = self.anvilLevel
for cx, cz in itertools.product(xrange(0, 4), xrange(0, 4)):
try:
level.createChunk(cx, cz)
except ValueError:
pass
dim.copyBlocks(level.getDimension(), BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
os.remove(temp)
schem = WorldEditor("test_files/Station.schematic")
tempEditor = createSchematic(shape=(1, 1, 3))
tempDim = tempEditor.getDimension()
tempDim.copyBlocks(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 0, 0))
def testRotate(self):
editor = self.anvilLevel
dim = editor.getDimension()
schematic = dim.exportSchematic(BoundingBox((0, 0, 0), (21, 11, 8)))
level = self.pc_world
for cx, cz in itertools.product(xrange(0, 4), xrange(0, 4)):
try:
level.createChunk(cx, cz)
except ValueError:
pass
dim.copyBlocks(level.getDimension(), BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
os.remove(temp)
schematic.rotateLeft()
dim.importSchematic(schematic, dim.bounds.origin)
schematic.flipEastWest()
dim.importSchematic(schematic, dim.bounds.origin)
@pytest.skip("Rotate not implemented")
def testRotate(pc_world):
dim = pc_world.getDimension()
schematic = dim.exportSchematic(BoundingBox((0, 0, 0), (21, 11, 8)))
schematic.flipVertical()
dim.importSchematic(schematic, dim.bounds.origin)
schematic.rotateLeft()
dim.importSchematic(schematic, dim.bounds.origin)
def testZipSchematic(self):
level = self.anvilLevel
schematic.flipEastWest()
dim.importSchematic(schematic, dim.bounds.origin)
x, y, z = level.bounds.origin
x += level.bounds.size[0]/2 & ~15
z += level.bounds.size[2]/2 & ~15
schematic.flipVertical()
dim.importSchematic(schematic, dim.bounds.origin)
box = BoundingBox((x, y, z), (64, 64, 64,))
zs = level.extractZipSchematic(box)
assert(box.chunkCount == zs.chunkCount)
zs.close()
os.remove(zs.filename)
def testINVEditChests(self):
invFile = WorldEditor("schematics/Chests/TinkerersBox.inv")
assert invFile.Blocks.any()
assert not invFile.Data.any()
assert len(invFile.Entities) == 0
assert len(invFile.TileEntities) == 1
# raise SystemExit
def testZipSchematic(pc_world):
level = pc_world.getDimension()
def testCopyOffsets(self):
editor = TempLevel("AnvilWorld")
dimension = editor.getDimension()
schematic = createSchematic((13, 8, 5))
schematicDim = schematic.getDimension()
x, y, z = level.bounds.origin
x += level.bounds.size[0]/2 & ~15
z += level.bounds.size[2]/2 & ~15
x, y, z = dimension.bounds.origin + [p/2 for p in dimension.bounds.size]
for dx in range(16):
for dz in range(16):
dimension.copyBlocks(schematicDim, schematicDim.bounds, (x+dx, y, z+dz), biomes=True)
box = BoundingBox((x, y, z), (64, 64, 64,))
zs = level.extractZipSchematic(box)
assert(box.chunkCount == zs.chunkCount)
zs.close()
os.remove(zs.filename)
#
# def testINVEditChests(self):
# invFile = WorldEditor("schematics/Chests/TinkerersBox.inv")
# assert invFile.Blocks.any()
# assert not invFile.Data.any()
# assert len(invFile.Entities) == 0
# assert len(invFile.TileEntities) == 1
# # raise SystemExit
def testCopyOffsets(pc_world):
dimension = pc_world.getDimension()
schematic = createSchematic((13, 8, 5))
schematicDim = schematic.getDimension()
x, y, z = dimension.bounds.origin + [p/2 for p in dimension.bounds.size]
for dx in range(16):
for dz in range(16):
dimension.copyBlocks(schematicDim, schematicDim.bounds, (x+dx, y, z+dz), biomes=True)

View File

@ -1,31 +1,26 @@
import unittest
import pytest
from mceditlib.minecraft_server import MCServerChunkGenerator
from templevel import TempLevel
from mceditlib.selection import BoundingBox
__author__ = 'Rio'
class TestServerGen(unittest.TestCase):
def setUp(self):
# self.alphaLevel = TempLevel("Dojo_64_64_128.dat")
self.alphalevel = TempLevel("AnvilWorld")
@pytest.skip("Server generator not implemented")
def testCreate():
gen = MCServerChunkGenerator()
print "Version: ", gen.serverVersion
def testCreate(self):
gen = MCServerChunkGenerator()
print "Version: ", gen.serverVersion
def _testCreate(filename):
gen.createLevel(filename, BoundingBox((-128, 0, -128), (128, 128, 128)))
def _testCreate(filename):
gen.createLevel(filename, BoundingBox((-128, 0, -128), (128, 128, 128)))
TempLevel("ServerCreate", createFunc=_testCreate)
TempLevel("ServerCreate", createFunc=_testCreate)
@pytest.skip("Server generator not implemented")
def testServerGen(pc_world):
gen = MCServerChunkGenerator()
print "Version: ", gen.serverVersion
def testServerGen(self):
gen = MCServerChunkGenerator()
print "Version: ", gen.serverVersion
level = self.alphalevel
gen.generateChunkInLevel(level, 50, 50)
gen.generateChunksInLevel(level, [(120, 50), (121, 50), (122, 50), (123, 50), (244, 244), (244, 245), (244, 246)])
c = level.getChunk(50, 50)
assert c.getSection(0).Blocks.any()
gen.generateChunkInLevel(pc_world, 50, 50)
gen.generateChunksInLevel(pc_world, [(120, 50), (121, 50), (122, 50), (123, 50), (244, 244), (244, 245), (244, 246)])
c = pc_world.getChunk(50, 50)
assert c.getSection(0).Blocks.any()

View File

@ -1,12 +1,18 @@
import atexit
import os
from os.path import join
from os.path import join, dirname
import shutil
import tempfile
from mceditlib.worldeditor import WorldEditor
__author__ = 'Rio'
TEST_FILES_DIR = "test_files"
_TEST_FILES_DIR = "test_files"
# from $PROJECT/src/mceditlib/test/templevel.py, get to $PROJECT/test_files
_PROJECT = dirname(dirname(dirname(dirname(__file__))))
TEST_FILES_DIR = join(_PROJECT, _TEST_FILES_DIR)
tempdir = os.path.join(tempfile.gettempdir(), "mceditlib_test")
def killtemp():
@ -23,6 +29,13 @@ def mktemp(suffix):
return td
def TempFile(filename):
"""
Create a temporary copy of 'filename'.
'filename' must be a path relative to the 'test_files' folder
"""
assert not os.path.isabs(filename), "TempFile filename must be a relative path."
filename = join(TEST_FILES_DIR, filename)
tmpname = mktemp(os.path.basename(filename))
if not os.path.exists(filename):
raise IOError("File not found")