Skip to content

Commit

Permalink
Prevent calling optional scipy in conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-schlipf committed Jun 18, 2024
1 parent b8b9dee commit 28507fc
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,25 @@


@pytest.fixture(scope="session")
def is_core():
def only_core():
if not _is_core():
pytest.skip("This test checks py4vasp-core functionality not used by py4vasp.")


@pytest.fixture(scope="session")
def not_core():
if _is_core():
pytest.skip("This test requires features not present in py4vasp-core.")


def _is_core():
try:
importlib.metadata.distribution("py4vasp-core")
return True
except importlib.metadata.PackageNotFoundError:
return False


@pytest.fixture()
def only_core(is_core):
if not is_core:
pytest.skip("This test checks py4vasp-core functionality not used by py4vasp.")


@pytest.fixture()
def not_core(is_core):
if is_core:
pytest.skip("This test requires features not present in py4vasp-core.")


class _Assert:
@staticmethod
def allclose(actual, desired, tolerance=1):
Expand Down Expand Up @@ -714,14 +713,15 @@ def _partial_charge(selection):
spin_dimension = 1
grid = raw.VaspData(tuple(reversed(grid_dim)))
gaussian_charge = np.zeros((len(kpoints), len(bands), spin_dimension, *grid_dim))
cov = grid_dim[0] / 10 # standard deviation
z = np.arange(grid_dim[0]) # z range
for gy in range(grid_dim[1]):
for gx in range(grid_dim[2]):
m = int(grid_dim[0] / 2) + gy / 10 + gx / 10
val = stats.multivariate_normal(mean=m, cov=cov).pdf(z)
# Fill the gaussian_charge array
gaussian_charge[:, :, :, :, gy, gx] = val
if not _is_core():
cov = grid_dim[0] / 10 # standard deviation
z = np.arange(grid_dim[0]) # z range
for gy in range(grid_dim[1]):
for gx in range(grid_dim[2]):
m = int(grid_dim[0] / 2) + gy / 10 + gx / 10
val = stats.multivariate_normal(mean=m, cov=cov).pdf(z)
# Fill the gaussian_charge array
gaussian_charge[:, :, :, :, gy, gx] = val
gaussian_charge = raw.VaspData(gaussian_charge)
return raw.PartialCharge(
structure=structure,
Expand Down

0 comments on commit 28507fc

Please sign in to comment.