Skip to content

Commit

Permalink
test: ✅ add some more tests on registration and instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
dubusster committed Mar 6, 2024
1 parent 23b1afe commit cd2ea45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/python/librir/video_io/IRMovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import tempfile
from pathlib import Path
from typing import List, Union
from typing import List, Optional, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -145,6 +145,7 @@ def __init__(self, handle):
self._frame_attributes_d = {}
self._file_attributes = FileAttributes(self.filename)
self._file_attributes.attributes = get_global_attributes(self.handle)
self._registration_file = None

self.calibration = "DL"

Expand Down Expand Up @@ -227,13 +228,13 @@ def close(self):
self.__tempfile__ = None

@property
def registration_file(self) -> Path:
def registration_file(self) -> Optional[Path]:
"""
Returns the registration file name for this camera, and tries to download it
from ARCADE if not already done.
"""

return self._registration_file
if self._registration_file:
return self._registration_file

@registration_file.setter
def registration_file(self, value) -> None:
Expand All @@ -249,7 +250,7 @@ def registration(self) -> bool:
"""
Returns True is video registration is activated, false otherwise
"""
if self._registration_file.exists():
if self._registration_file is not None and self._registration_file.exists():
return motion_correction_enabled(self.handle)
return False

Expand Down
11 changes: 11 additions & 0 deletions tests/python/test_IRMovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ def test_IRMovie_with_filename_as_input(filename):
assert mov.filename == filename


@pytest.mark.instantiation
def test_IRMovie_with_handle_as_input(array):
with IRMovie.from_numpy_array(array) as movie:
new_mov = IRMovie(movie.handle)
assert new_mov.handle == movie.handle
new_mov.__tempfile__ = None
movie.__tempfile__ = None
with pytest.raises(RuntimeError):
IRMovie(0)


@pytest.mark.instantiation
def test_IRMovie_instantiation_with_2D_numpy_array(valid_2D_array):
mov = IRMovie.from_numpy_array(valid_2D_array)
Expand Down
3 changes: 3 additions & 0 deletions tests/python/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def test_set_registration_file_to_IRMovie(
movie_with_polygon_drawn: IRMovie, reg: MaskedRegistratorECC
):
images = movie_with_polygon_drawn.data
assert not movie_with_polygon_drawn.registration

# Set the first image
reg.start(images[0])
Expand All @@ -124,6 +125,8 @@ def test_set_registration_file_to_IRMovie(
reg.to_reg_file(reg_file)
movie_with_polygon_drawn.registration_file = reg_file
movie_with_polygon_drawn[0]
assert movie_with_polygon_drawn.registration

os.unlink(reg_file)


Expand Down

0 comments on commit cd2ea45

Please sign in to comment.