def __init__(self, x_prefix, y_prefix, z_prefix, z_offset, z_dir, E, att_obj, lcls_obj=None, mono_obj=None, *args, path, lens_set=None, **kwargs): self.path = path self.lens_pack = self.read_lens() if lens_set is None: # Defaulting this a the first set in the file for now lens_set = calcs.get_lens_set(1, self.path) super().__init__( x_prefix, y_prefix, z_prefix, lens_set, z_offset, z_dir, E, att_obj, *args, **kwargs )
def set_lens_set(self, index): """ Temporary method to get the set from the lens set file at the index. TODO: this method will obviously change when we know how we want to get the lens, for now it is merely choosing it manually. Parameters ---------- index : int Index to indicate which set in the list to get. Examples -------- >>> set_lens_set(2) """ self.lens_set = calcs.get_lens_set(index, self.path)
def read_lens(self, print_only=False): """ Read the lens sets from file provided in the path. Parameters ---------- print_only : bool To indicate if printing out the currents sets only. If `False` the `self.lens_pack` will be set to get the current file sets. Returns ------- sets : list Pack of lens sets. """ lens_pack = calcs.get_lens_set(None, self.path, get_all=True) if print_only: logger.info(lens_pack) else: self.lens_pack = lens_pack return self.lens_pack
def test_get_lens_set_no_file(): be_lens_calcs.LENS_SET_FILE = None with pytest.raises(ValueError): be_lens_calcs.get_lens_set(1)
def test_get_lens_set(): first_set = [3, 0.0001, 1, 0.0002] lens_set = be_lens_calcs.get_lens_set(1, PATH) logger.debug(f'result: {lens_set}') assert lens_set == first_set
def test_lens_file_with_multiple_sets(): be_lens_calcs.set_lens_set_to_file(SETS_SAMPLE, PATH, False) lens_set = be_lens_calcs.get_lens_set(2, PATH) expected = [1, 0.0001, 1, 0.0003, 1, 0.0005] assert expected == lens_set
def test_get_lens_set_file_one_set(): first_set = [3, 0.0001, 1, 0.0002] be_lens_calcs.set_lens_set_to_file(first_set, PATH, False) lens_set = be_lens_calcs.get_lens_set(1, PATH) logger.debug(f'result: {lens_set}') assert lens_set == first_set
def test_get_lens_set_with_empty_file(): be_lens_calcs.set_lens_set_to_file("", PATH, False) # file should be empty with pytest.raises(ValueError): be_lens_calcs.get_lens_set(1, PATH)
def test_get_lens_set_with_bad_path(): with pytest.raises(FileNotFoundError): be_lens_calcs.get_lens_set(1, BAD_PATH)