|
1 | 1 | from __future__ import absolute_import, division |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | import numpy as np |
4 | 6 | from numpy.testing import (assert_almost_equal, |
5 | 7 | assert_equal) |
|
8 | 10 |
|
9 | 11 | from . import datafiles |
10 | 12 |
|
11 | | -def test_ccp4(): |
12 | | - g = Grid(datafiles.CCP4) |
| 13 | +@pytest.fixture(scope="module") |
| 14 | +def g(): |
| 15 | + return Grid(datafiles.CCP4) |
| 16 | + |
| 17 | +def test_ccp4(g): |
13 | 18 | POINTS = 192 |
14 | 19 | assert_equal(g.grid.flat, np.arange(1, POINTS+1)) |
15 | 20 | assert_equal(g.grid.size, POINTS) |
16 | 21 | assert_almost_equal(g.delta, [3./4, .5, 2./3]) |
17 | 22 | assert_equal(g.origin, np.zeros(3)) |
18 | 23 |
|
| 24 | + |
| 25 | +@pytest.fixture(scope="module") |
| 26 | +def ccp4data(): |
| 27 | + return CCP4.CCP4(datafiles.CCP4_1JZV) |
| 28 | + |
| 29 | +@pytest.mark.parametrize('name,value', [ |
| 30 | + ('nc', 96), |
| 31 | + ('nr', 76), |
| 32 | + ('ns', 70), |
| 33 | + ('mode', 2), |
| 34 | + ('ncstart', -4), |
| 35 | + ('nrstart', -23), |
| 36 | + ('nsstart', 102), |
| 37 | + ('nx', 84), |
| 38 | + ('ny', 84), |
| 39 | + ('nz', 160), |
| 40 | + ('xlen', 45.79999923706055), |
| 41 | + ('ylen', 45.79999923706055), |
| 42 | + ('zlen', 89.6500015258789), |
| 43 | + ('alpha', 90.0), |
| 44 | + ('beta', 90.0), |
| 45 | + ('gamma', 90.0), |
| 46 | + ('mapc', 2), |
| 47 | + ('mapr', 1), |
| 48 | + ('maps', 3), |
| 49 | + ('amin', -0.9930942058563232), |
| 50 | + ('amax', 9.050403594970703), |
| 51 | + ('amean', -0.0005801090155728161), |
| 52 | + ('ispg', 92), |
| 53 | + ('nsymbt', 640), |
| 54 | + ('lskflg', 0), |
| 55 | + ('bsaflag', '@'), |
| 56 | + ('skwmat', None), |
| 57 | + ('skwtrn', None), |
| 58 | + ('endianness', 'little'), |
| 59 | + ('arms', 0.4034915268421173), |
| 60 | + ('nlabl', 1), |
| 61 | + ('label', ' Map from fft '), |
| 62 | +]) |
| 63 | +def test_ccp4_integer_reading(ccp4data, name, value): |
| 64 | + if type(value) is float: |
| 65 | + assert_almost_equal(ccp4data.header[name], value, decimal=6) |
| 66 | + else: |
| 67 | + assert_equal(ccp4data.header[name], value) |
| 68 | + |
| 69 | + |
19 | 70 | def test_byteorder(): |
20 | 71 | with open(datafiles.CCP4, 'rb') as ccp4file: |
21 | 72 | flag = CCP4.CCP4._detect_byteorder(ccp4file) |
|
0 commit comments