1
1
import math
2
2
3
+ import numpy as np
3
4
import pytest
4
5
from pyRestTable import Table
6
+ from ...misc import IDENTITY_MATRIX_3X3
7
+ from ...tests .common import assert_context_result
8
+ from ...ops import Operations
5
9
6
10
from .. import hkl_soleil
11
+ # from contextlib import nullcontext as does_not_raise
12
+ # context, expected
13
+ # with context as reason:
14
+ # pass
15
+ # assert_context_result(expected, reason)
7
16
8
17
9
18
def test_version ():
@@ -17,6 +26,78 @@ def test_version():
17
26
assert solver .version == libhkl .VERSION
18
27
19
28
29
+ def kryptonite ():
30
+ """Make a kryptonite sample for E4CV."""
31
+ from ...blocks .sample import Sample
32
+ from ...blocks .lattice import Lattice
33
+ from ...blocks .reflection import Reflection
34
+
35
+ core = Operations (None , default_sample = False )
36
+ sample = Sample (core , "kryptonite" , Lattice (0.01 )) # should be interesting
37
+ r1 = Reflection (
38
+ name = "r1" ,
39
+ pseudos = dict (h = 1 , k = 0 , l = 0 ),
40
+ reals = dict (omega = 1 , chi = 0 , phi = 0 , tth = 2 ),
41
+ wavelength = 1.54 ,
42
+ geometry = "E4CV" ,
43
+ pseudo_axis_names = "h k l" .split (),
44
+ real_axis_names = "omega chi phi tth" .split (),
45
+ )
46
+ sample .reflections .add (r1 )
47
+ return sample
48
+
49
+
50
+ def test_hkl_soleil ():
51
+ arr = hkl_soleil .libhkl .Matrix .new_euler (0 , 0 , 0 )
52
+ assert hkl_soleil .to_hkl (arr ) == arr
53
+
54
+ arr = np .array ([1 , 2 , 3 ])
55
+ np .testing .assert_array_equal (hkl_soleil .to_numpy (arr ), arr )
56
+
57
+
58
+ def test_HklSolver ():
59
+ solver = hkl_soleil .HklSolver (geometry = "E4CV" , engine = "hkl" )
60
+ assert solver .wavelength == 1.54
61
+ assert solver .axes_c == []
62
+ assert solver .axes_r == ["omega" , "chi" , "phi" , "tth" ]
63
+ assert solver .axes_w == ["omega" , "chi" , "phi" , "tth" ]
64
+ assert solver .engines == ["hkl" , "psi" , "q" , "incidence" , "emergence" ]
65
+
66
+ assert solver .sample is None # pre-requisite for next assertions
67
+ assert solver .U == IDENTITY_MATRIX_3X3
68
+ assert solver .UB == IDENTITY_MATRIX_3X3
69
+ assert solver .calculate_UB (None , None ) is None
70
+
71
+ with pytest .raises (TypeError ) as reason :
72
+ solver .addReflection (1.0 )
73
+ assert_context_result ("Must supply Reflection object" , reason )
74
+
75
+ with pytest .raises (KeyError ) as reason :
76
+ solver .extras = dict (trombone = 0 )
77
+ assert_context_result ("Unexpected dictionary key received" , reason )
78
+
79
+ with pytest .raises (ValueError ) as reason :
80
+ solver .inverse (dict (a = 1 , b = 2 , c = 3 , d = 4 ))
81
+ assert_context_result ("Wrong dictionary keys received" , reason )
82
+
83
+ with pytest .raises (TypeError ) as reason :
84
+ solver .inverse (dict (omega = "1" , chi = 0 , phi = 0 , tth = 0 ))
85
+ assert_context_result ("All values must be numbers" , reason )
86
+
87
+ with pytest .raises (TypeError ) as reason :
88
+ solver .lattice = 1.0
89
+ assert_context_result ("Must supply Lattice object" , reason )
90
+
91
+ with pytest .raises (ValueError ) as reason :
92
+ solver .refineLattice ([])
93
+ assert_context_result ("Must provide 3 or more reflections" , reason )
94
+
95
+ with pytest .raises (TypeError ) as reason :
96
+ solver .sample = "kryptonite"
97
+ assert_context_result ("Must supply Sample object" , reason )
98
+ solver .sample = kryptonite ()
99
+
100
+
20
101
@pytest .mark .parametrize (
21
102
"gname, ename, reals" ,
22
103
[
0 commit comments