Skip to content
This repository has been archived by the owner on Jul 21, 2019. It is now read-only.

Commit

Permalink
fix pmd_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Jan 1, 2018
1 parent 7d569d9 commit 0ac7835
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
6 changes: 2 additions & 4 deletions .vscode/launch.json
Expand Up @@ -10,11 +10,9 @@
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/setup.py",
//"program": "${workspaceRoot}/setup.py",
"program": "${file}",
"args": [
"nosetests"
//, "--tests"
//, "test.obj_test"
],
"cwd": "${workspaceRoot}",
"env": {},
Expand Down
Empty file modified pymeshio/vmd/writer.py 100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion setup.py 100755 → 100644
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# coding: utf-8
from logging import getLogger
logger = getLogger(__name__)
Expand Down
19 changes: 19 additions & 0 deletions test/__init__.py
@@ -0,0 +1,19 @@
import pathlib
import sys
import unittest

HERE = pathlib.Path(__file__).parent
sys.path.append(str(HERE.parent))

from pmd_test import PmdTestCase


def main():
suite = unittest.TestSuite()
suite.addTest(PmdTestCase('test_read'))
runner = unittest.TextTestRunner()
runner.run(suite)


if __name__ == '__main__':
main()
51 changes: 30 additions & 21 deletions test/pmd_test.py
@@ -1,5 +1,9 @@
# coding: utf-8
import pathlib
here = pathlib.Path(__file__).parent
import sys
sys.path.append(str(here.parent))

import io
import unittest
import pymeshio.common
Expand All @@ -8,38 +12,40 @@
import pymeshio.pmd.writer


PMD_FILE=pymeshio.common.unicode('resources/初音ミクVer2.pmd')
PMD_FILE = pymeshio.common.unicode('resources/初音ミクVer2.pmd')


class PmdTestCase(unittest.TestCase):

class TestPmd(unittest.TestCase):

def setUp(self):
pass

def test_read(self):
model=pymeshio.pmd.reader.read_from_file(PMD_FILE)
model = pymeshio.pmd.reader.read_from_file(PMD_FILE)
self.assertEqual(pymeshio.pmd.Model, model.__class__)
self.assertEqual(pymeshio.common.unicode('初音ミク').encode('cp932'), model.name)
self.assertEqual(pymeshio.common.unicode('Miku Hatsune').encode('cp932'), model.english_name)
self.assertEqual(pymeshio.common.unicode(
"PolyMo用モデルデータ:初音ミク ver.2.3\n"+
"(物理演算対応モデル)\n"+
"\n"+
"モデリング :あにまさ氏\n"+
"データ変換 :あにまさ氏\n"+
'初音ミク').encode('cp932'), model.name)
self.assertEqual(pymeshio.common.unicode(
'Miku Hatsune').encode('cp932'), model.english_name)
self.assertEqual(pymeshio.common.unicode(
"PolyMo用モデルデータ:初音ミク ver.2.3\n" +
"(物理演算対応モデル)\n" +
"\n" +
"モデリング :あにまさ氏\n" +
"データ変換 :あにまさ氏\n" +
"Copyright :CRYPTON FUTURE MEDIA, INC").encode('cp932'),
model.comment)
self.assertEqual(pymeshio.common.unicode(
"MMD Model: Miku Hatsune ver.2.3\n"+
"(Physical Model)\n"+
"\n"+
"Modeling by Animasa\n"+
"Converted by Animasa\n"+
"MMD Model: Miku Hatsune ver.2.3\n" +
"(Physical Model)\n" +
"\n" +
"Modeling by Animasa\n" +
"Converted by Animasa\n" +
"Copyright CRYPTON FUTURE MEDIA, INC").encode('cp932'),
model.english_comment)
self.assertEqual(12354, len(model.vertices))
self.assertEqual(22961 * 3, len(model.indices))
print("{0} textures".format(len(model.toon_textures)))
#print("{0} textures".format(len(model.toon_textures)))
self.assertEqual(17, len(model.materials))
self.assertEqual(140, len(model.bones))
self.assertEqual(31, len(model.morphs))
Expand All @@ -48,13 +54,16 @@ def test_read(self):

def test_write(self):
# read source file
buf=pymeshio.common.readall(PMD_FILE)
buf = pymeshio.common.readall(PMD_FILE)
# read and write to out
model=pymeshio.pmd.reader.read(io.BytesIO(buf))
out=io.BytesIO()
model = pymeshio.pmd.reader.read(io.BytesIO(buf))
out = io.BytesIO()
pymeshio.pmd.writer.write(out, model)
# read out buffer again
model2=pymeshio.pmd.reader.read(io.BytesIO(out.getvalue()))
model2 = pymeshio.pmd.reader.read(io.BytesIO(out.getvalue()))
model.diff(model2)
self.assertEqual(model, model2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 0ac7835

Please sign in to comment.