From b7a7c6e88dde2409537e19810ca01f19b1e97314 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 20:09:49 +0000 Subject: [PATCH 1/3] Extend unit tests for get_primitive_cell() Added test cases to cover: - Periodic boundary condition validation: ensuring ValueError is raised if structure is not periodic. - Custom arrays warning: ensuring a warning is logged when custom arrays are present in the source structure. Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com> --- tests/test_analyse_symmetry.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_analyse_symmetry.py b/tests/test_analyse_symmetry.py index c084735e9..10f08a37a 100644 --- a/tests/test_analyse_symmetry.py +++ b/tests/test_analyse_symmetry.py @@ -425,6 +425,27 @@ def test_arg_equivalent_vectors(self): dx_round = np.round(np.absolute(dx), decimals=3) self.assertEqual(len(np.unique(dx_round + arg_v)), len(np.unique(arg_v))) + def test_get_primitive_cell_pbc_error(self): + structure = bulk("Al", cubic=True) + structure.pbc = [True, True, False] + sym = stk.analyse.get_symmetry(structure=structure) + with self.assertRaisesRegex(ValueError, "Can only symmetrize periodic structures."): + sym.get_primitive_cell() + + def test_get_primitive_cell_arrays_warning(self): + structure = bulk("Al", cubic=True) + structure.set_array("test_array", np.zeros(len(structure))) + sym = stk.analyse.get_symmetry(structure=structure) + with self.assertLogs(level="WARNING") as cm: + sym.get_primitive_cell() + self.assertTrue( + any( + "Custom arrays {'test_array'} do not carry over to new structure!" + in output + for output in cm.output + ) + ) + def test_error(self): """spglib errors should be wrapped in a SymmetryError.""" From f03b22e9a3da90f9d479f42e693e624d8d400947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Fri, 10 Apr 2026 22:17:35 +0200 Subject: [PATCH 2/3] fixes --- tests/test_analyse_symmetry.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_analyse_symmetry.py b/tests/test_analyse_symmetry.py index 10f08a37a..71bc9b23f 100644 --- a/tests/test_analyse_symmetry.py +++ b/tests/test_analyse_symmetry.py @@ -3,6 +3,7 @@ # Distributed under the terms of "New BSD License", see the LICENSE file. import unittest +import warnings import numpy as np from ase.atoms import Atoms @@ -436,13 +437,14 @@ def test_get_primitive_cell_arrays_warning(self): structure = bulk("Al", cubic=True) structure.set_array("test_array", np.zeros(len(structure))) sym = stk.analyse.get_symmetry(structure=structure) - with self.assertLogs(level="WARNING") as cm: + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") sym.get_primitive_cell() self.assertTrue( any( "Custom arrays {'test_array'} do not carry over to new structure!" in output - for output in cm.output + for output in w ) ) From ba311ddf9c94fd5b83a295c514f4eae11d8fd391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Fri, 10 Apr 2026 22:28:54 +0200 Subject: [PATCH 3/3] another fix --- tests/test_analyse_symmetry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_analyse_symmetry.py b/tests/test_analyse_symmetry.py index 71bc9b23f..aa09acd59 100644 --- a/tests/test_analyse_symmetry.py +++ b/tests/test_analyse_symmetry.py @@ -443,8 +443,8 @@ def test_get_primitive_cell_arrays_warning(self): self.assertTrue( any( "Custom arrays {'test_array'} do not carry over to new structure!" - in output - for output in w + in str(warning.message) + for warning in w ) )