X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=test%2Fpmx_test.py;h=e9185eea52ee44da446666f0991410923ca7a0dc;hb=cf6ec3e04ee67bbe635510486475961ed32e46f2;hp=878c251aa961ef4e2c58b4084e9966c8e8488113;hpb=e71383740ef0dabf087ddfd6643903219c8408c7;p=meshio%2Fpymeshio.git diff --git a/test/pmx_test.py b/test/pmx_test.py index 878c251..e9185ee 100644 --- a/test/pmx_test.py +++ b/test/pmx_test.py @@ -1,37 +1,59 @@ # coding: utf-8 -import pymeshio.pmx.loader - - -PMX_FILE=u'resources/初音ミクVer2.pmx' - -def test_read(): - model=pymeshio.pmx.loader.load(PMX_FILE) - assert model.__class__==pymeshio.pmx.Model - assert model.name==u'初音ミク' - assert model.english_name==u'Miku Hatsune' - assert model.comment==( - u"PolyMo用モデルデータ:初音ミク ver.2.3\r\n"+ - u"(物理演算対応モデル)\r\n"+ - u"\r\n"+ - u"モデリング :あにまさ氏\r\n"+ - u"データ変換 :あにまさ氏\r\n"+ - u"Copyright :CRYPTON FUTURE MEDIA, INC" - ) - assert model.english_comment==( - u"MMD Model: Miku Hatsune ver.2.3\r\n"+ - u"(Physical Model)\r\n"+ - u"\r\n"+ - u"Modeling by Animasa\r\n"+ - u"Converted by Animasa\r\n"+ - u"Copyright CRYPTON FUTURE MEDIA, INC" - ) - - assert len(model.vertices)==12354 - assert len(model.indices)==22961 * 3 - print("{0} textures".format(len(model.textures))) - assert len(model.materials)==17 - assert len(model.bones)==140 - assert len(model.morphs)==30 - assert len(model.display_slots)==9 - assert len(model.rigidbodies)==45 - assert len(model.joints)==27 +import unittest +import io +import pymeshio.pmd +import pymeshio.pmx.reader +import pymeshio.pmx.writer + + +PMX_FILE=pymeshio.unicode('resources/初音ミクVer2.pmx') + + +class TestPmx(unittest.TestCase): + + def setUp(self): + pass + + 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( + "PolyMo用モデルデータ:初音ミク ver.2.3\r\n"+ + "(物理演算対応モデル)\r\n"+ + "\r\n"+ + "モデリング :あにまさ氏\r\n"+ + "データ変換 :あにまさ氏\r\n"+ + "Copyright :CRYPTON FUTURE MEDIA, INC"), + model.comment) + self.assertEqual(pymeshio.unicode( + "MMD Model: Miku Hatsune ver.2.3\r\n"+ + "(Physical Model)\r\n"+ + "\r\n"+ + "Modeling by Animasa\r\n"+ + "Converted by Animasa\r\n"+ + "Copyright CRYPTON FUTURE MEDIA, INC"), + model.english_comment) + + self.assertEqual(12354, len(model.vertices)) + self.assertEqual(22961 * 3, len(model.indices)) + print("{0} textures".format(len(model.textures))) + self.assertEqual(17, len(model.materials)) + self.assertEqual(140, len(model.bones)) + self.assertEqual(30, len(model.morphs)) + self.assertEqual(9, len(model.display_slots)) + 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) +