Skip to content

Commit

Permalink
test: add format 0 testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
justbilt committed Oct 23, 2017
1 parent 0b5c2c0 commit a299488
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 4 deletions.
217 changes: 217 additions & 0 deletions tests/data/v0.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>frames</key>
<dict>
<key>testAnimationResource/1.png</key>
<dict>
<key>width</key>
<integer>201</integer>
<key>height</key>
<integer>320</integer>
<key>originalWidth</key>
<integer>201</integer>
<key>originalHeight</key>
<integer>320</integer>
<key>x</key>
<integer>0</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/2.png</key>
<dict>
<key>width</key>
<integer>186</integer>
<key>height</key>
<integer>252</integer>
<key>originalWidth</key>
<integer>186</integer>
<key>originalHeight</key>
<integer>252</integer>
<key>x</key>
<integer>203</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/3.png</key>
<dict>
<key>width</key>
<integer>247</integer>
<key>height</key>
<integer>479</integer>
<key>originalWidth</key>
<integer>247</integer>
<key>originalHeight</key>
<integer>479</integer>
<key>x</key>
<integer>391</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/4.png</key>
<dict>
<key>width</key>
<integer>141</integer>
<key>height</key>
<integer>110</integer>
<key>originalWidth</key>
<integer>141</integer>
<key>originalHeight</key>
<integer>110</integer>
<key>x</key>
<integer>640</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/5.png</key>
<dict>
<key>width</key>
<integer>190</integer>
<key>height</key>
<integer>236</integer>
<key>originalWidth</key>
<integer>190</integer>
<key>originalHeight</key>
<integer>236</integer>
<key>x</key>
<integer>783</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/6.png</key>
<dict>
<key>width</key>
<integer>474</integer>
<key>height</key>
<integer>402</integer>
<key>originalWidth</key>
<integer>474</integer>
<key>originalHeight</key>
<integer>402</integer>
<key>x</key>
<integer>975</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/7.png</key>
<dict>
<key>width</key>
<integer>146</integer>
<key>height</key>
<integer>112</integer>
<key>originalWidth</key>
<integer>146</integer>
<key>originalHeight</key>
<integer>112</integer>
<key>x</key>
<integer>1451</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/8.png</key>
<dict>
<key>width</key>
<integer>135</integer>
<key>height</key>
<integer>180</integer>
<key>originalWidth</key>
<integer>135</integer>
<key>originalHeight</key>
<integer>180</integer>
<key>x</key>
<integer>1599</integer>
<key>y</key>
<integer>0</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>testAnimationResource/hat.png</key>
<dict>
<key>width</key>
<integer>452</integer>
<key>height</key>
<integer>458</integer>
<key>originalWidth</key>
<integer>452</integer>
<key>originalHeight</key>
<integer>458</integer>
<key>x</key>
<integer>0</integer>
<key>y</key>
<integer>481</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
<key>25.png</key>
<dict>
<key>width</key>
<integer>20</integer>
<key>height</key>
<integer>23</integer>
<key>originalWidth</key>
<integer>20</integer>
<key>originalHeight</key>
<integer>23</integer>
<key>x</key>
<integer>454</integer>
<key>y</key>
<integer>481</integer>
<key>offsetX</key>
<real>0</real>
<key>offsetY</key>
<real>0</real>
</dict>
</dict>
<key>metadata</key>
<dict>
<key>format</key>
<integer>0</integer>
<key>textureFileName</key>
<string>v0.png</string>
<key>realTextureFileName</key>
<string>v0.png</string>
<key>size</key>
<string>{2048,1024}</string>
</dict>
<key>texture</key>
<dict>
<key>width</key>
<integer>2048</integer>
<key>height</key>
<integer>1024</integer>
</dict>
</dict>
</plist>
Binary file added tests/data/v0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 10 additions & 4 deletions tests/test_untp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def _cleanUp(self):
if os.path.exists(TEMP_PATH):
shutil.rmtree(TEMP_PATH)

def _test_unpack(self, _plist, _output, _size_field="sourceSize"):
def _test_unpack(self, _plist, _output, _size_field="{sourceSize}"):
data = plistlib.readPlist(_plist)
for k,v in data.frames.iteritems():
clip_path = os.path.join(_output, k)
self.assertTrue(os.path.exists(clip_path))
src_image = Image.open(clip_path)
self.assertEqual(v[_size_field], "{%s,%d}" %(src_image.size))
self.assertEqual(_size_field.format(**v), "{%s,%d}" %(src_image.size))

def setUp(self):
self._cleanUp()
Expand All @@ -45,6 +45,11 @@ def setUp(self):
def tearDown(self):
self._cleanUp()

def test_unpack_f0(self):
"""Test unpack plist that format is 1"""
untp.unpacker(ipath("v0.plist"), ipath("v0.png"), opath("v0"))
self._test_unpack(ipath("v0.plist"), opath("v0"), _size_field="{{{originalWidth},{originalHeight}}}")

def test_unpack_f1(self):
"""Test unpack plist that format is 1"""
untp.unpacker(ipath("v1.plist"), ipath("v1.png"), opath("v1"))
Expand All @@ -58,14 +63,15 @@ def test_unpack_f2(self):
def test_unpack_f3(self):
"""Test unpack plist that format is 3"""
untp.unpacker(ipath("subdir", "v3.plist"), ipath("subdir", "v3.png"), opath("v3"))
self._test_unpack(ipath("subdir", "v3.plist"), opath("v3"), _size_field="spriteSourceSize")
self._test_unpack(ipath("subdir", "v3.plist"), opath("v3"), _size_field="{spriteSourceSize}")

def test_unpack_dir(self):
"""Test unpack directory"""
untp.unpacker_dir(DATA_PATH, True, output_dir=TEMP_PATH)
self._test_unpack(ipath("v0.plist"), opath("v0"), _size_field="{{{originalWidth},{originalHeight}}}")
self._test_unpack(ipath("v1.plist"), opath("v1"))
self._test_unpack(ipath("v2.plist"), opath("v2"))
self._test_unpack(ipath("subdir", "v3.plist"), opath("subdir", "v3"), _size_field="spriteSourceSize")
self._test_unpack(ipath("subdir", "v3.plist"), opath("subdir", "v3"), _size_field="{spriteSourceSize}")

def test_unpack_fnt(self):
"""Test unpack plist that format is 1"""
Expand Down

0 comments on commit a299488

Please sign in to comment.