|
1 | 1 | import json |
2 | 2 | from pathlib import Path |
3 | 3 |
|
4 | | -import numpy as np |
5 | 4 | import pytest |
6 | 5 |
|
7 | | -from diffpy.utils.diffraction_objects import DiffractionObject |
8 | | - |
9 | 6 |
|
10 | 7 | @pytest.fixture |
11 | 8 | def user_filesystem(tmp_path): |
12 | 9 | base_dir = Path(tmp_path) |
13 | 10 | home_dir = base_dir / "home_dir" |
14 | 11 | home_dir.mkdir(parents=True, exist_ok=True) |
15 | | - cwd_dir = home_dir / "cwd_dir" |
| 12 | + cwd_dir = base_dir / "cwd_dir" |
16 | 13 | cwd_dir.mkdir(parents=True, exist_ok=True) |
17 | | - home_config_data = { |
18 | | - "owner_name": "home_ownername", |
19 | | - "owner_email": "home@email.com", |
20 | | - "owner_orcid": "home_orcid", |
21 | | - } |
| 14 | + |
| 15 | + home_config_data = {"username": "home_username", "email": "home@email.com"} |
22 | 16 | with open(home_dir / "diffpyconfig.json", "w") as f: |
23 | 17 | json.dump(home_config_data, f) |
24 | | - yield home_dir, cwd_dir |
25 | | - |
26 | | - |
27 | | -@pytest.fixture |
28 | | -def datafile(): |
29 | | - """Fixture to dynamically load any test file.""" |
30 | | - base_path = Path(__file__).parent / "testdata" # Adjusted base path |
31 | | - |
32 | | - def _load(filename): |
33 | | - return base_path / filename |
34 | | - |
35 | | - return _load |
36 | | - |
37 | | - |
38 | | -@pytest.fixture |
39 | | -def do_minimal(): |
40 | | - # Create an instance of DiffractionObject with empty xarray and yarray |
41 | | - # values, and a non-empty wavelength |
42 | | - return DiffractionObject( |
43 | | - xarray=np.empty(0), yarray=np.empty(0), xtype="tth", wavelength=1.54 |
44 | | - ) |
45 | | - |
46 | | - |
47 | | -@pytest.fixture |
48 | | -def do_minimal_tth(): |
49 | | - # Create an instance of DiffractionObject with non-empty xarray, yarray, |
50 | | - # and wavelength values |
51 | | - return DiffractionObject( |
52 | | - wavelength=2 * np.pi, |
53 | | - xarray=np.array([30, 60]), |
54 | | - yarray=np.array([1, 2]), |
55 | | - xtype="tth", |
56 | | - ) |
57 | | - |
58 | 18 |
|
59 | | -@pytest.fixture |
60 | | -def do_minimal_d(): |
61 | | - # Create an instance of DiffractionObject with non-empty xarray, yarray, |
62 | | - # and wavelength values |
63 | | - return DiffractionObject( |
64 | | - wavelength=1.54, |
65 | | - xarray=np.array([1, 2]), |
66 | | - yarray=np.array([1, 2]), |
67 | | - xtype="d", |
68 | | - ) |
69 | | - |
70 | | - |
71 | | -@pytest.fixture |
72 | | -def wavelength_warning_msg(): |
73 | | - return ( |
74 | | - "No wavelength has been specified. You can continue to use the " |
75 | | - "DiffractionObject, but some of its powerful features will not be " |
76 | | - "available. " |
77 | | - "To specify a wavelength, if you have " |
78 | | - "do = DiffractionObject(xarray, yarray, 'tth'), " |
79 | | - "you may set do.wavelength = 1.54 for a wavelength of 1.54 angstroms." |
80 | | - ) |
81 | | - |
82 | | - |
83 | | -@pytest.fixture |
84 | | -def invalid_q_or_d_or_wavelength_error_msg(): |
85 | | - return ( |
86 | | - "The supplied input array and wavelength will result in an " |
87 | | - "impossible two-theta. " |
88 | | - "Please check these values and re-instantiate the DiffractionObject " |
89 | | - "with correct values." |
90 | | - ) |
91 | | - |
92 | | - |
93 | | -@pytest.fixture |
94 | | -def invalid_add_type_error_msg(): |
95 | | - return ( |
96 | | - "You may only add a DiffractionObject with another DiffractionObject " |
97 | | - "or a scalar value. " |
98 | | - "Please rerun by adding another DiffractionObject instance or a " |
99 | | - "scalar value. " |
100 | | - "e.g., my_do_1 + my_do_2 or my_do + 10 or 10 + my_do" |
101 | | - ) |
102 | | - |
103 | | - |
104 | | -@pytest.fixture |
105 | | -def x_values_not_equal_error_msg(): |
106 | | - return ( |
107 | | - "The two objects have different values in x arrays " |
108 | | - "(my_do.all_arrays[:, [1, 2, 3]]). " |
109 | | - "Please ensure the x values of the two objects are identical " |
110 | | - "by re-instantiating the DiffractionObject with the correct x value " |
111 | | - "inputs." |
112 | | - ) |
| 19 | + yield tmp_path |
0 commit comments