예제 #1
0
    def test_collection(self):
        collection = ParserCollection()
        collection.add('off', OFFParser())
        assert len(collection._collection) == 1
        assert isinstance(collection.get('off'), OFFParser)

        with pytest.raises(KeyError):
            collection.delete('aaa')
        assert len(collection._collection) == 1

        collection.delete('off')
        assert len(collection._collection) == 0
예제 #2
0
    def test_delete_mesh(self):
        model = Model()
        path = f'{TEST_FILES_FOLDER_PATH}/caseron.off'
        info = OFFParser.load_file(path)
        vertices = info.get('data').get('vertices')
        indices = info.get('data').get('indices')

        mesh = model.mesh(vertices=vertices, indices=indices)
        _id = mesh.id
        model.delete(_id)

        assert model.get(_id) is None
예제 #3
0
    def test_get_mesh(self):
        model = Model()
        path = f'{TEST_FILES_FOLDER_PATH}/caseron.off'
        info = OFFParser.load_file(path)
        vertices = info.get('data').get('vertices')
        indices = info.get('data').get('indices')

        mesh = model.mesh(vertices=vertices, indices=indices)
        mesh_get = model.get(mesh.id)

        assert mesh is not None
        assert mesh_get is not None
        assert mesh.id == mesh_get.id
예제 #4
0
    def test_save_file(self):
        info = Parser.load_file(path=f'{TEST_FILES_FOLDER_PATH}/caseron.off')
        vertices = info.get('data').get('vertices')
        indices = info.get('data').get('indices')

        properties = {'color': [1.0, 0.6, 0.2], 'alpha': 0.5}

        Parser.save_file(path=f'{TEST_FILES_FOLDER_PATH}/caseron_save.off',
                         vertices=vertices,
                         indices=indices,
                         properties=properties)
        Parser.save_file(path=f'{TEST_FILES_FOLDER_PATH}/caseron_save.off',
                         data={
                             'vertices': vertices,
                             'indices': indices
                         },
                         properties=properties)
        Parser.save_file(path=f'{TEST_FILES_FOLDER_PATH}/caseron_save.off',
                         data={
                             'x': vertices[:, 0],
                             'y': vertices[:, 1],
                             'z': vertices[:, 2],
                             'indices': indices
                         },
                         properties=properties)
        info_s = Parser.load_file(
            path=f'{TEST_FILES_FOLDER_PATH}/caseron_save.off')
        vertices_s = info_s.get('data').get('vertices')
        indices_s = info_s.get('data').get('indices')
        metadata_s = info_s.get('metadata')

        for v, v_s in zip(vertices, vertices_s):
            for e, e_s in zip(v, v_s):
                assert abs(e - e_s) < 1e-12

        for i, i_s in zip(indices, indices_s):
            for e, e_s in zip(i, i_s):
                assert abs(e - e_s) < 1e-12

        assert metadata_s.get('name') == 'caseron_save'
        assert metadata_s.get('extension') == 'off'

        # Cleanup
        os.remove(f'{TEST_FILES_FOLDER_PATH}/caseron_save.off')
예제 #5
0
    def test_add_mesh(self):
        model = Model()
        path = f'{TEST_FILES_FOLDER_PATH}/caseron.off'
        info = OFFParser.load_file(path)
        vertices = info.get('data').get('vertices')
        indices = info.get('data').get('indices')

        x, y, z = zip(*vertices)

        mesh_1 = model.mesh(vertices=vertices,
                            indices=indices,
                            name='caseron',
                            extension='off')
        mesh_2 = model.mesh(x=x,
                            y=y,
                            z=z,
                            indices=indices,
                            name='caseron',
                            extension='off')

        assert mesh_1.id != mesh_2.id
예제 #6
0
 def test_load_file(self):
     info = Parser.load_file(f'{TEST_FILES_FOLDER_PATH}/caseron.off')
     vertices = info.get('data').get('vertices')
     indices = info.get('data').get('indices')
     assert len(vertices) == 12
     assert len(indices) == 20
예제 #7
0
 def test_save_empty(self):
     with pytest.raises(Exception):
         Parser.save_file()
     with pytest.raises(Exception):
         Parser.save_file(None)
예제 #8
0
 def test_load_damaged(self):
     with pytest.raises(Exception):
         Parser.load_file(f'{TEST_FILES_FOLDER_PATH}/bad.off')
예제 #9
0
 def test_load_wrong_extension(self):
     with pytest.raises(Exception):
         Parser.load_file(f'{TEST_FILES_FOLDER_PATH}/caseron.dxf')
예제 #10
0
 def test_load_inexistent(self):
     with pytest.raises(Exception):
         Parser.load_file(f'{TEST_FILES_FOLDER_PATH}/nonexistent.off')