Skip to content

Commit 28fbcac

Browse files
author
Han Wang
committed
fix(test): backup/restore fparam.npy in TestFparam instead of deleting
TestFparam.tearDown deleted the committed fparam.npy, breaking other tests (e.g. test_fitting_stat) running later in the same CI shard. Also revert the unnecessary .resolve() workaround in test_fitting_stat.
1 parent 64dc703 commit 28fbcac

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

source/tests/pt/test_training.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,22 @@ def setUp(self) -> None:
268268
self.config["training"]["numb_steps"] = 1
269269
self.config["training"]["save_freq"] = 1
270270
self.set_path = Path(__file__).parent / "water/data/data_0" / "set.000"
271-
shutil.copyfile(self.set_path / "energy.npy", self.set_path / "fparam.npy")
271+
# Backup the committed fparam.npy (numb_fparam=2) before overwriting
272+
# with a 1-column version for this test.
273+
self._fparam_backup = self.set_path / "fparam.npy.bak"
274+
fparam_path = self.set_path / "fparam.npy"
275+
if fparam_path.exists():
276+
shutil.copyfile(fparam_path, self._fparam_backup)
277+
shutil.copyfile(self.set_path / "energy.npy", fparam_path)
272278
self.config["model"]["data_stat_nbatch"] = 100
273279

274280
def tearDown(self) -> None:
275-
(self.set_path / "fparam.npy").unlink(missing_ok=True)
281+
# Restore the original fparam.npy so other tests can use it.
282+
fparam_path = self.set_path / "fparam.npy"
283+
if self._fparam_backup.exists():
284+
shutil.move(str(self._fparam_backup), str(fparam_path))
285+
else:
286+
fparam_path.unlink(missing_ok=True)
276287
DPTrainTest.tearDown(self)
277288

278289

source/tests/pt_expt/fitting/test_fitting_stat.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,13 @@ def _get_weighted_fitting_stat(
117117
return weighted_avg, weighted_std
118118

119119

120-
# Paths to the water data used by PT tests.
121-
# resolve() follows the ``pt/water -> model/water`` symlink so numpy can
122-
# always open the real file, even on CI runners where symlink handling
123-
# can be fragile.
124-
_PT_DATA = str(
125-
(Path(__file__).parent.parent.parent / "pt" / "water" / "data" / "data_0").resolve()
126-
)
120+
# Paths to the water data used by PT tests
121+
_PT_DATA = str(Path(__file__).parent.parent.parent / "pt" / "water" / "data" / "data_0")
127122
_PT_DATA_NO_FPARAM = str(
128-
(Path(__file__).parent.parent.parent / "pt" / "water" / "data" / "data_1").resolve()
123+
Path(__file__).parent.parent.parent / "pt" / "water" / "data" / "data_1"
129124
)
130125
_PT_DATA_SINGLE = str(
131-
(Path(__file__).parent.parent.parent / "pt" / "water" / "data" / "single").resolve()
126+
Path(__file__).parent.parent.parent / "pt" / "water" / "data" / "single"
132127
)
133128

134129
_descriptor_se_e2_a = {

0 commit comments

Comments
 (0)