diff --git a/libpyvinyl/Instrument.py b/libpyvinyl/Instrument.py index bf849c0..f350289 100644 --- a/libpyvinyl/Instrument.py +++ b/libpyvinyl/Instrument.py @@ -16,9 +16,9 @@ def __init__(self, name, calculators=None): :param calculators: A collection of Calculator objects. :type calculators: dict """ - self.name = name - self.calculators = {} - self.parameters = InstrumentParameters() + self.__name = name + self.__calculators = {} + self.__parameters = InstrumentParameters() if calculators is not None: for calculator in calculators: self.add_calculator(calculator) @@ -26,6 +26,28 @@ def __init__(self, name, calculators=None): def add_master_parameter(self, name, links, **kwargs): self.parameters.add_master_parameter(name, links, **kwargs) + @property + def name(self): + """The name of this instrument.""" + return self.__name + + @name.setter + def name(self, value: str): + self.__name = value + + @property + def calculators(self): + """The list of calculators. It's modified either when constructing the class instance + or using the `add_calculator` function. + """ + return self.__calculators + + @property + def parameters(self): + """The parameter collection of each calculator in the instrument. These parameters are links to the + exact parameters of each calculator.""" + return self.__parameters + @property def master(self): return self.parameters.master @@ -33,8 +55,8 @@ def master(self): def set_base_path(self, base: str): """Set each calculator's output_path as 'base_path/calculator.name'. - Args: - base (str): The base path to be set. + :param base: The base path to be set. + :type base: str """ self.base_path = base basePath = Path(base) @@ -54,9 +76,9 @@ def list_parameters(self): print(self.parameters) def add_calculator(self, calculator): - self.calculators[calculator.name] = calculator - self.parameters.add(calculator.name, calculator.parameters) + self.__calculators[calculator.name] = calculator + self.__parameters.add(calculator.name, calculator.parameters) def remove_calculator(self, calculator_name): - del self.calculators[calculator_name] - del self.parameters[calculator_name] + del self.__calculators[calculator_name] + del self.__parameters[calculator_name] diff --git a/tests/InstrumentTest.py b/tests/InstrumentTest.py index 6c12602..3d2613e 100644 --- a/tests/InstrumentTest.py +++ b/tests/InstrumentTest.py @@ -10,7 +10,6 @@ class InstrumentTest(unittest.TestCase): """ Test class for the Detector class. """ - @classmethod def setUpClass(cls): """ Setting up the test class. """ @@ -77,13 +76,14 @@ def testRemoveCalculator(self): self.assertEqual(len(my_instrument.calculators), 2) my_instrument.remove_calculator(self.calculator1.name) self.assertEqual(len(my_instrument.calculators), 1) - + def testEditCalculator(self): """ Testing edit calculator """ my_instrument = Instrument('myInstrument') my_instrument.add_calculator(self.calculator1) my_instrument.parameters['test1']['photon_energy'] = 15 - energy1 = my_instrument.calculators['test1'].parameters['photon_energy'].value + energy1 = my_instrument.calculators['test1'].parameters[ + 'photon_energy'].value self.assertEqual(energy1, 15) def testAddMaster(self): @@ -95,8 +95,10 @@ def testAddMaster(self): links = {'test1': 'photon_energy', 'test2': 'photon_energy'} my_instrument.add_master_parameter('photon_energy', links) my_instrument.master['photon_energy'] = 10 - energy1 = my_instrument.calculators['test1'].parameters['photon_energy'].value - energy2 = my_instrument.calculators['test2'].parameters['photon_energy'].value + energy1 = my_instrument.calculators['test1'].parameters[ + 'photon_energy'].value + energy2 = my_instrument.calculators['test2'].parameters[ + 'photon_energy'].value self.assertEqual(energy1, 10) self.assertEqual(energy2, 10) @@ -107,8 +109,11 @@ def testSetBasePath(self): my_instrument.add_calculator(self.calculator1) my_instrument.add_calculator(self.calculator2) my_instrument.set_base_path('test') - self.assertEqual(my_instrument.calculators["test1"].output_path, 'test/test1') - self.assertEqual(my_instrument.calculators["test2"].output_path, 'test/test2') + self.assertEqual(my_instrument.calculators["test1"].output_path, + 'test/test1') + self.assertEqual(my_instrument.calculators["test2"].output_path, + 'test/test2') + + if __name__ == '__main__': unittest.main() -