X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=test%2Fpmx_test.py;h=858f55e8d833732a3a3b55634a85b19106b339b9;hb=1a59747c66623ef3b6b66412d25ffc4e613cd893;hp=1e89b0dcb910320e9207c50f2c84692bc509c237;hpb=7ff333d9b8fffaaf28975006afb7bff34e04b483;p=meshio%2Fpymeshio.git diff --git a/test/pmx_test.py b/test/pmx_test.py index 1e89b0d..858f55e 100644 --- a/test/pmx_test.py +++ b/test/pmx_test.py @@ -1,10 +1,15 @@ # coding: utf-8 import unittest -import pymeshio.pmd +import io +import pymeshio.common +import pymeshio.pmd.reader import pymeshio.pmx.reader +import pymeshio.pmx.writer +import pymeshio.converter -PMX_FILE=pymeshio.unicode('resources/初音ミクVer2.pmx') +PMD_FILE=pymeshio.common.unicode('resources/初音ミクVer2.pmd') +PMX_FILE=pymeshio.common.unicode('resources/初音ミクVer2.pmx') class TestPmx(unittest.TestCase): @@ -15,9 +20,9 @@ class TestPmx(unittest.TestCase): def test_read(self): model=pymeshio.pmx.reader.read_from_file(PMX_FILE) self.assertEqual(pymeshio.pmx.Model, model.__class__) - self.assertEqual(pymeshio.unicode('初音ミク'), model.name) - self.assertEqual(pymeshio.unicode('Miku Hatsune'), model.english_name) - self.assertEqual(pymeshio.unicode( + self.assertEqual(pymeshio.common.unicode('初音ミク'), model.name) + self.assertEqual(pymeshio.common.unicode('Miku Hatsune'), model.english_name) + self.assertEqual(pymeshio.common.unicode( "PolyMo用モデルデータ:初音ミク ver.2.3\r\n"+ "(物理演算対応モデル)\r\n"+ "\r\n"+ @@ -25,7 +30,7 @@ class TestPmx(unittest.TestCase): "データ変換 :あにまさ氏\r\n"+ "Copyright :CRYPTON FUTURE MEDIA, INC"), model.comment) - self.assertEqual(pymeshio.unicode( + self.assertEqual(pymeshio.common.unicode( "MMD Model: Miku Hatsune ver.2.3\r\n"+ "(Physical Model)\r\n"+ "\r\n"+ @@ -44,3 +49,25 @@ class TestPmx(unittest.TestCase): self.assertEqual(45, len(model.rigidbodies)) self.assertEqual(27, len(model.joints)) + def test_write(self): + # read source file + buf=pymeshio.common.readall(PMX_FILE) + # read and write to out + model=pymeshio.pmx.reader.read(io.BytesIO(buf)) + out=io.BytesIO() + pymeshio.pmx.writer.write(out, model) + # read out buffer again + model2=pymeshio.pmx.reader.read(io.BytesIO(out.getvalue())) + self.assertEqual(model, model2) + + def test_convert(self): + # convert + pmd=pymeshio.pmd.reader.read_from_file(PMD_FILE) + converted=pymeshio.converter.pmd_to_pmx(pmd) + # validate + pmx=pymeshio.pmx.reader.read_from_file(PMX_FILE) + # check diffference + pmx.diff(converted) + #self.assertEqual(pmx, converted) + pymeshio.pmx.writer.write(io.open("tmp.pmx", "wb"), converted) +