Пример #1
0
 def test_writing_ply_with_no_comments_does_not_write_comments(self):
     local_file = os.path.join(
         self.tmp_dir,
         "test_writing_ply_with_no_comments_does_not_write_comments.ply")
     m = ply.load(self.test_ply_path)
     ply.dump(m, local_file, ascii=True)
     with open(local_file) as f:
         self.assertNotRegexpMatches(f.read(), '\ncomment')
Пример #2
0
    def test_hey_look_its_a_buffer_overflow_in_rply(self):
        '''
        Without the rply fix, python will crash executing this (on osx, it
        crashes with "Abort trap: 6"). This test is passing when it doesn't
        crash :)

        The bug is in rply's error handling, which trustingly writes the name
        of an element into a fixed length buffer when there's a problem reading
        the element or its properties.
        '''
        bad_file = os.path.join(self.tmp_dir, 'danger_will_robinson.ply')
        with open(bad_file, 'w') as f:
            f.write('ply\n')
            f.write('format ascii 1.0\n')
            f.write('element vert' + (1024 * 'e') + 'x 8\n')
            f.write('end_header\n')
        with self.assertRaises(ply.PLYError):
            ply.load(bad_file)
Пример #3
0
 def test_writing_ply_with_comments_does_write_comments(self):
     local_file = os.path.join(
         self.tmp_dir,
         "test_writing_ply_with_comments_does_write_comments.ply")
     m = ply.load(self.test_ply_path)
     ply.dump(m,
              local_file,
              ascii=True,
              comments=['foo bar', 'this is a comment'])
     with open(local_file) as f:
         contents = f.read()
         self.assertRegexpMatches(
             contents, '\ncomment foo bar\ncomment this is a comment\n')
         self.assertNotRegexpMatches(contents, '\ncomment Copyright')
Пример #4
0
def _load(f, existing_mesh=None):
    import os
    from lace.serialization import ply, obj, wrl, stl, xyz, bsf
    ext = os.path.splitext(f.name)[1].lower()
    if ext == ".ply":
        return ply.load(f, existing_mesh=existing_mesh)
    elif ext == ".obj":
        return obj.load(f, existing_mesh=existing_mesh)
    elif ext == ".wrl":
        return wrl.load(f, existing_mesh=existing_mesh)
    elif ext == ".ylp":
        return ply.load_encrypted(f, existing_mesh=existing_mesh)
    elif ext == ".stl":
        return stl.load(f, existing_mesh=existing_mesh)
    elif ext == ".xyz":
        return xyz.load(f, existing_mesh=existing_mesh)
    elif ext == ".bsf":
        return bsf.load(f, existing_mesh=existing_mesh)
    else:
        raise NotImplementedError("Unknown mesh file format: %s" % f.name)
Пример #5
0
 def test_load_bsf(self):
     expected_mesh = ply.load(vc('/unittest/bsf/bsf_example.ply'))
     bsf_mesh = bsf.load(vc('/unittest/bsf/bsf_example.bsf'))
     np.testing.assert_array_almost_equal(bsf_mesh.v, expected_mesh.v)
     np.testing.assert_equal(bsf_mesh.f, expected_mesh.f)
Пример #6
0
 def test_loads_from_open_file_using_serializer(self):
     with open(self.test_ply_path) as f:
         m = ply.load(f)
     self.assertTrue((m.v == self.truth['box_v']).all())
     self.assertTrue((m.f == self.truth['box_f']).all())
Пример #7
0
 def test_loads_from_remote_path_using_serializer(self):
     skip_if_unavailable('s3')
     m = ply.load(self.test_ply_url)
     self.assertTrue((m.v == self.truth['box_v']).all())
     self.assertTrue((m.f == self.truth['box_f']).all())
Пример #8
0
 def test_loads_from_local_path_using_serializer(self):
     m = ply.load(self.test_ply_path)
     self.assertTrue((m.v == self.truth['box_v']).all())
     self.assertTrue((m.f == self.truth['box_f']).all())