-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
222 lines (172 loc) · 7.73 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
'''
Created on Jul 23, 2011
@author: Rio
'''
#from mclevel import fromFile, loadWorldNumber, BoundingBox
#from infiniteworld import MCInfdevOldLevel
#from schematic import MCSchematic
from pymclevel import *
import itertools
import traceback
import unittest
import tempfile
import logging
import shutil
import os
import numpy
from numpy import *
from logging import info
#logging.basicConfig(format=u'%(levelname)s:%(message)s')
#logging.getLogger().level = logging.INFO
class TempLevel(object):
def __init__(self, filename):
if not os.path.exists(filename):
filename = os.path.join("testfiles", filename)
#def tempCopy(filename):
if os.path.isdir(filename):
tmpname = tempfile.mkdtemp(os.path.basename(filename))
os.rmdir(tmpname)
shutil.copytree(filename, tmpname)
else:
fd, tmpname = tempfile.mkstemp(os.path.basename(filename))
os.close(fd)
os.unlink(tmpname)
shutil.copy(filename, tmpname)
self.tmpname = tmpname
self.level = fromFile(tmpname)
#def tempRemove(filename):
def __del__(self):
self.level.close()
del self.level
filename = self.tmpname
if os.path.isdir(filename):
shutil.rmtree(filename)
else:
os.unlink(filename)
class TestIndevLevel(unittest.TestCase):
def setUp(self):
self.srclevel = TempLevel("hell.mclevel")
self.indevlevel = TempLevel("hueg.mclevel")
def testEntities(self):
level = self.indevlevel.level
entityTag = Entity.Create("Zombie")
tileEntityTag = TileEntity.Create("Painting")
level.addEntity(entityTag)
level.addTileEntity(tileEntityTag)
schem = level.extractSchematic(level.bounds)
level.copyBlocksFrom(schem, schem.bounds, (0, 0, 0))
#raise Failure
def testCopy(self):
info("Indev level")
indevlevel = self.indevlevel.level
srclevel = self.srclevel.level
indevlevel.copyBlocksFrom(srclevel, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
assert((indevlevel.Blocks[0:64, 0:64, 0:64] == srclevel.Blocks[0:64, 0:64, 0:64]).all())
def testFill(self):
indevlevel = self.indevlevel.level
indevlevel.fillBlocks(BoundingBox((0, 0, 0), (64, 64, 64,)), indevlevel.materials.Sand, [indevlevel.materials.Rock, indevlevel.materials.Dirt])
indevlevel.saveInPlace()
class TestJavaLevel(unittest.TestCase):
def setUp(self):
self.creativelevel = TempLevel("Dojo_64_64_128.dat")
self.indevlevel = TempLevel("hell.mclevel")
def testCopy(self):
indevlevel = self.indevlevel.level
creativelevel = self.creativelevel.level
creativelevel.copyBlocksFrom(indevlevel, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
assert(numpy.array((indevlevel.Blocks[0:64, 0:64, 0:64]) == (creativelevel.Blocks[0:64, 0:64, 0:64])).all())
creativelevel.saveInPlace()
#xxx old survival levels
class TestAlphaLevelCreate(unittest.TestCase):
def testCreate(self):
temppath = tempfile.mktemp("AlphaCreate")
self.alphaLevel = MCInfdevOldLevel(filename=temppath, create=True);
class TestAlphaLevel(unittest.TestCase):
def setUp(self):
#self.alphaLevel = TempLevel("Dojo_64_64_128.dat")
self.indevlevel = TempLevel("hell.mclevel")
self.alphalevel = TempLevel("PyTestWorld")
def testCreateChunks(self):
indevlevel = self.indevlevel.level
level = self.alphalevel.level
for ch in list(level.allChunks): level.deleteChunk(*ch)
level.createChunksInBox(BoundingBox((0, 0, 0), (32, 0, 32)))
def testCopyConvertBlocks(self):
indevlevel = self.indevlevel.level
level = self.alphalevel.level
level.copyBlocksFrom(indevlevel, BoundingBox((0, 0, 0), (256, 128, 256)), (-0, 0, 0))
convertedSourceBlocks, convertedSourceData = indevlevel.convertBlocksFromLevel(level, indevlevel.Blocks[0:16, 0:16, 0:indevlevel.Height], indevlevel.Data[0:16, 0:16, 0:indevlevel.Height])
assert (level.getChunk(0, 0).Blocks[0:16, 0:16, 0:indevlevel.Height] == convertedSourceBlocks).all()
def testImportSchematic(self):
indevlevel = self.indevlevel.level
level = self.alphalevel.level
schem = fromFile("schematics\\CreativeInABox.schematic");
level.copyBlocksFrom(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 64, 0));
schem = MCSchematic(shape=(1, 1, 3))
schem.copyBlocksFrom(level, BoundingBox((0, 64, 0), (1, 1, 3)), (0, 0, 0));
convertedSourceBlocks, convertedSourceData = schem.convertBlocksFromLevel(level, schem.Blocks, schem.Data)
assert (level.getChunk(0, 0).Blocks[0:1, 0:3, 64:65] == convertedSourceBlocks).all()
def testRecreateChunks(self):
level = self.alphalevel.level
for x, z in itertools.product(xrange(-1, 3), xrange(-1, 2)):
level.deleteChunk(x, z);
level.createChunk(x, z)
def testFill(self):
level = self.alphalevel.level
level.fillBlocks(BoundingBox((-11, 0, -7), (38, 128, 25)) , level.materials.WoodPlanks);
c = level.getChunk(0, 0)
assert (c.Blocks == 5).all()
def testReplace(self):
level = self.alphalevel.level
level.fillBlocks(BoundingBox((-11, 0, -7), (38, 128, 25)) , level.materials.WoodPlanks, [level.materials.Dirt, level.materials.Grass]);
def testSaveRelight(self):
indevlevel = self.indevlevel.level
level = self.alphalevel.level
cx, cz = -3, -1;
level.deleteChunk(cx, cz);
level.createChunk(cx, cz);
level.copyBlocksFrom(indevlevel, BoundingBox((0, 0, 0), (64, 64, 64,)), (-96, 32, 0))
level.generateLights();
level.saveInPlace();
class TestSchematics(unittest.TestCase):
def setUp(self):
#self.alphaLevel = TempLevel("Dojo_64_64_128.dat")
self.indevlevel = TempLevel("hell.mclevel")
def testCreate(self):
#info("Schematic from indev")
size = (64, 64, 64)
schematic = MCSchematic(shape=size, filename="hell.schematic", mats='Classic');
level = self.indevlevel.level
schematic.rotateLeft();
self.failUnlessRaises(ValueError, lambda:(
schematic.copyBlocksFrom(level, BoundingBox((-32, -32, -32), (64, 64, 64,)), (0, 0, 0))
))
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
assert((schematic.Blocks[0:64, 0:64, 0:64] == level.Blocks[0:64, 0:64, 0:64]).all())
schematic.compress();
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (-32, -32, -32))
assert((schematic.Blocks[0:32, 0:32, 0:32] == level.Blocks[32:64, 32:64, 32:64]).all())
schematic.compress();
schematic.saveInPlace();
schem = fromFile("schematics\CreativeInABox.schematic");
tempSchematic = MCSchematic(shape=(1, 1, 3))
tempSchematic.copyBlocksFrom(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 0, 0))
info("Schematic from alpha")
level = loadWorldNumber(1)
for cx, cz in itertools.product(xrange(0, 4), xrange(0, 4)):
try:
level.createChunk(cx, cz)
except ValueError:
pass
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
def testINVEditChests(self):
info("INVEdit chest")
invFile = fromFile("schematics/Chests/TinkerersBox.inv");
info("Blocks: ", invFile.Blocks)
info("Data: ", invFile.Data)
info("Entities: ", invFile.Entities)
info("TileEntities: ", invFile.TileEntities)
#raise SystemExit;
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()