-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
74 lines (55 loc) · 1.84 KB
/
conftest.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Provide fixture and other testing helpers."""
import freud
import numpy as np
import pytest
@pytest.fixture(autouse=True, scope="session")
def seeds(rng):
"""Return a random integer seed."""
def seed():
return rng.integers(1_000_000)
return seed
@pytest.fixture(autouse=True, scope="session")
def _np_seed():
"""Set the NumPy random seed for external code."""
np.random.seed(3857834) # noqa: NPY002
@pytest.fixture(scope="session")
def rng():
"""A random number generator for tests that have need for random numbers."""
return np.random.default_rng(5645646)
@pytest.fixture(scope="session")
def mock_fcc_system(rng):
"""Create 3D FCC systems.
Parameters
----------
ns: tuple[int, int, int], optional
Number of unit cells in each dimension. Defaults to ``(2, 2, 2)``.
a: float, optional
The lattice spacing. Defaults to 1.0.
noise: float, optional
The standard deviation of noise about the lattice sites. Defaults to
``1e-3``.
"""
def system_factory(ns=(2, 2, 2), a=1.0, noise=1e-3):
return freud.data.UnitCell.fcc().generate_system(
ns, a, noise, rng.integers(1e4)
)
return system_factory
@pytest.fixture(scope="session")
def mock_random_system():
"""Create 2 or 3D random position systems.
Parameters
----------
N: int, optional
Number of particles. Defaults to 100.
l: float, optional
The box length. Defaults to 10.0.
dimensions: int, optional
The dimension of the system. Defaults to 3.
"""
def system_factory(N=50, l=10.0, dimensions=3):
return freud.data.make_random_system(
box_size=l,
num_points=N,
is2D=dimensions == 2, # noqa: PLR2004
)
return system_factory