File: test_algorithm_module.py

package info (click to toggle)
astra-toolbox 2.3.0-4
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 4,972 kB
  • sloc: cpp: 24,378; python: 5,048; sh: 3,514; ansic: 1,181; makefile: 518
file content (50 lines) | stat: -rw-r--r-- 1,688 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
import astra
import pytest
import numpy as np


@pytest.fixture
def algorithm_config():
    proj_geom = astra.create_proj_geom('parallel3d', 1.0, 1.0, 20, 20, np.linspace(0, 1, 30))
    vol_geom = astra.create_vol_geom(10, 10, 10)
    proj_data_id = astra.data3d.create('-sino', proj_geom)
    vol_data_id = astra.data3d.create('-vol', vol_geom)
    config = astra.astra_dict('FP3D_CUDA')
    config['ProjectionDataId'] = proj_data_id
    config['VolumeDataId'] = vol_data_id
    yield config
    astra.data3d.delete(proj_data_id)
    astra.data3d.delete(vol_data_id)


def test_create_run(algorithm_config):
    algorithm_id = astra.algorithm.create(algorithm_config)
    astra.algorithm.run(algorithm_id)
    astra.algorithm.delete(algorithm_id)


def test_delete(algorithm_config):
    algorithm_id = astra.algorithm.create(algorithm_config)
    astra.algorithm.delete(algorithm_id)
    with pytest.raises(astra.log.AstraError):
        astra.algorithm.run(algorithm_id)


def test_clear(algorithm_config):
    algorithm_id1 = astra.algorithm.create(algorithm_config)
    algorithm_id2 = astra.algorithm.create(algorithm_config)
    astra.algorithm.clear()
    with pytest.raises(astra.log.AstraError):
        astra.algorithm.run(algorithm_id1)
    with pytest.raises(astra.log.AstraError):
        astra.algorithm.run(algorithm_id2)


def test_info(algorithm_config, capsys):
    get_n_info_objects = lambda: len(capsys.readouterr().out.split('\n')) - 5
    algorithm_id = astra.algorithm.create(algorithm_config)
    astra.algorithm.info()
    assert get_n_info_objects() == 1
    astra.algorithm.delete(algorithm_id)
    astra.algorithm.info()
    assert get_n_info_objects() == 0