Coverage for tests/test_filtering.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.15.1, created at 2026-07-18 05:24 +0000

1import numpy as np 

2import pytest 

3from evutils.filtering import mask_events 

4from evutils.types import Event_dtype 

5 

6def test_mask_events(): 

7 events = np.array( 

8 [(100, 0, 0, 1), (200, 1, 1, 1), (300, 2, 2, 0)], 

9 dtype=Event_dtype 

10 ) 

11 mask = np.array([ 

12 [1, 0, 0], 

13 [0, 0, 0], 

14 [0, 0, 1] 

15 ]) 

16 

17 # Normal case 

18 masked = mask_events(events, mask) 

19 assert len(masked) == 2 

20 assert masked['x'].tolist() == [0, 2] 

21 

22 # Empty events 

23 empty_events = np.array([], dtype=Event_dtype) 

24 assert len(mask_events(empty_events, mask)) == 0 

25 

26 # ValueError: 1D mask 

27 with pytest.raises(ValueError, match="Mask must be a 2D array"): 

28 mask_events(events, np.array([1, 0, 1])) 

29 

30 # ValueError: Out of bounds 

31 out_of_bounds = np.array([(100, 3, 3, 1)], dtype=Event_dtype) 

32 with pytest.raises(ValueError, match="Events x and y coordinates must be within the mask dimensions"): 

33 mask_events(out_of_bounds, mask) 

34 

35 # ValueError: negative coordinates (using generic dtype since Event_dtype has unsigned x/y) 

36 # Event_dtype has x, y as u2 (unsigned 16-bit), so negative values wrap around to large positive. 

37 # Therefore, negative values are effectively out of bounds.