Skip to content

Commit 06ef997

Browse files
committed
Fix conditional for non-Kramers WCC
1 parent 55e9274 commit 06ef997

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

tests/test_z2_invariant.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,25 @@ def test_trivial(num_lines, num_wcc, patch_surface_data):
3838
assert z2pack.invariant.z2(data, check_kramers_pairs=False) == 0
3939

4040

41-
def test_no_kramers_pairs(N, M, patch_surface_data): # pylint: disable=invalid-name
41+
def test_not_even_number_wcc(N, M, patch_surface_data): # pylint: disable=invalid-name
42+
"""
43+
Test that the Kramers pairs check raises when an odd number of WCC is present.
44+
"""
4245
wcc = [np.linspace(0, 1, 2 * M + 1) for j in range(N + 1)]
4346
data = SurfaceData(wcc)
4447
with pytest.raises(ValueError):
4548
z2pack.invariant.z2(data)
4649

4750

51+
def test_not_kramers_pairs(patch_surface_data):
52+
"""
53+
Test that the check for Kramers pairs raises when WCC are not pairs.
54+
"""
55+
data = SurfaceData([[0., 0.], [0.5, 0.6]])
56+
with pytest.raises(ValueError):
57+
print(z2pack.invariant.z2(data))
58+
59+
4860
def test_linear(num_lines_nonzero, x, patch_surface_data):
4961
"""
5062
Test non-zero Z2 invariant with linear WCC evolution.

z2pack/invariant.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ def z2(surface_result, check_kramers_pairs=True): # pylint: disable=invalid-nam
4646
print(z2pack.invariant.z2(result)) # Prints the Z2 invariant
4747
"""
4848
wcc = surface_result.wcc
49-
if check_kramers_pairs and len(wcc) > 0: # pylint: disable=len-as-condition
50-
if not _check_kramers_pairs(list(wcc[0])) and _check_kramers_pairs(
51-
list(wcc[-1])
49+
if check_kramers_pairs and wcc:
50+
if not (
51+
_check_kramers_pairs(list(wcc[0]))
52+
and _check_kramers_pairs(list(wcc[-1]))
5253
):
5354
raise ValueError(
5455
'The given WCC are not degenerate Kramers pairs at the edges of the surface.'

0 commit comments

Comments
 (0)