Skip to content

Commit

Permalink
Apply recommended pytest config
Browse files Browse the repository at this point in the history
See scientific python development guide
  • Loading branch information
ffl096 committed Dec 10, 2024
1 parent 19a8699 commit e08d09a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 40 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
default_language_version:
python: python3.11

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
Expand Down
13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ignore = ["E501"] # line too long
[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F403"]

[tool.setuptools.packages.find]
Expand All @@ -118,7 +118,16 @@ disable_error_code = ["import-untyped"]
plugins = "numpy.typing.mypy_plugin"

[tool.pytest.ini_options]
addopts = "--capture=no"
minversion = "7.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = [
"error",
"ignore::scipy.sparse._base.SparseEfficiencyWarning",
"ignore:Sparse CSR tensor support is in beta state:UserWarning",
]
log_cli_level = "info"
testpaths = ["test"]

[tool.numpydoc_validation]
checks = [
Expand Down
17 changes: 5 additions & 12 deletions test/nn/cell/test_ccxn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ def test_forward(self):
att=False,
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)

adjacency_1 = torch.rand(2, 2)
incidence_2 = torch.rand(2, 2)

x_0, x_1 = (
torch.tensor(x_0).float().to(device),
torch.tensor(x_1).float().to(device),
)
adjacency_1 = adjacency_1.float().to(device)
incidence_2 = incidence_2.float().to(device)
x_0 = torch.rand(2, 2, dtype=torch.float32, device=device)
x_1 = torch.rand(2, 2, dtype=torch.float32, device=device)

adjacency_1 = torch.rand(2, 2, dtype=torch.float32, device=device)
incidence_2 = torch.rand(2, 2, dtype=torch.float32, device=device)

x_0, x_1, x_2 = model(x_0, x_1, adjacency_1, incidence_2)
assert x_0.shape == torch.Size([2, 2])
Expand Down
21 changes: 6 additions & 15 deletions test/nn/cell/test_cwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,12 @@ def test_forward(self):
n_layers=2,
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
x_2 = torch.rand(2, 2)
adjacency_1 = torch.rand(2, 2)
incidence_2 = torch.rand(2, 2)
incidence_1_t = torch.rand(2, 2)

x_0, x_1, x_2 = (
torch.tensor(x_0).float().to(device),
torch.tensor(x_1).float().to(device),
torch.tensor(x_2).float().to(device),
)
adjacency_1 = adjacency_1.float().to(device)
incidence_2 = incidence_2.float().to(device)
incidence_1_t = incidence_1_t.float().to(device)
x_0 = torch.rand(2, 2, dtype=torch.float32, device=device)
x_1 = torch.rand(2, 2, dtype=torch.float32, device=device)
x_2 = torch.rand(2, 2, dtype=torch.float32, device=device)
adjacency_1 = torch.rand(2, 2, dtype=torch.float32, device=device)
incidence_2 = torch.rand(2, 2, dtype=torch.float32, device=device)
incidence_1_t = torch.rand(2, 2, dtype=torch.float32, device=device)

x_0, x_1, x_2 = model(x_0, x_1, x_2, adjacency_1, incidence_2, incidence_1_t)
assert x_0.shape == torch.Size([2, 16])
Expand Down
12 changes: 4 additions & 8 deletions test/nn/combinatorial/test_hmc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the HMC class."""

import numpy as np
import torch

Expand All @@ -17,18 +18,13 @@ def test_forward(self):
channels_per_layer = [[in_channels, intermediate_channels, final_channels]]
model = HMC(channels_per_layer, negative_slope=0.2).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
x_2 = torch.rand(2, 2)
x_0 = torch.rand(2, 2, dtype=torch.float32, device=device)
x_1 = torch.rand(2, 2, dtype=torch.float32, device=device)
x_2 = torch.rand(2, 2, dtype=torch.float32, device=device)
adjacency_0 = torch.from_numpy(
np.random.default_rng().random((2, 2))
).to_sparse()

x_0, x_1, x_2 = (
torch.tensor(x_0).float().to(device),
torch.tensor(x_1).float().to(device),
torch.tensor(x_2).float().to(device),
)
adjacency_0 = adjacency_0.float().to(device)

x_0, x_1, x_2 = model(
Expand Down

0 comments on commit e08d09a

Please sign in to comment.