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
|
'''
unit tests for pymol.exporting geometry formats
'''
from pymol import cmd, testing
def file_get_contents(filename, mode='r'):
with open(filename, mode) as handle:
return handle.read()
class TestExportingGeom(testing.PyMOLTestCase):
def testVRML(self):
cmd.fragment('gly')
for rep in ['spheres', 'sticks', 'surface']:
cmd.show_as(rep)
with testing.mktemp('.wrl') as filename:
cmd.save(filename)
contents = file_get_contents(filename)
self.assertTrue(contents.startswith('#VRML V2'))
@testing.requires_version('1.8')
def testCOLLADA(self):
cmd.fragment('gly')
for rep in ['spheres', 'sticks', 'surface']:
cmd.show_as(rep)
with testing.mktemp('.dae') as filename:
cmd.save(filename)
contents = file_get_contents(filename)
self.assertTrue('<COLLADA' in contents)
@testing.requires('incentive')
@testing.requires_version('2.1')
def testSTL(self):
cmd.fragment('gly')
for rep in ['spheres', 'sticks', 'surface']:
cmd.show_as(rep)
with testing.mktemp('.stl') as filename:
cmd.save(filename)
contents = file_get_contents(filename, 'rb')
# 80 bytes header
# 4 bytes (uint32) number of triangles
self.assertTrue(len(contents) > 84)
|