def __getattribute__(self, attr_name):
        """ Attribute getter that does lazy loading of result file for output.
        """
        if attr_name == "output":
            if isfile(self.cadet_filepath):
                try:
                    output = self.load_results()
                    # Since sim has run, output should not be editable
                    walk_dataelement_editable(output,
                                              False,
                                              skip_traits=[
                                                  'source_experiment'
                                              ])  # noqa
                except Exception as e:
                    msg = "Failed to retrieve the output data from CADET " \
                          "file. Error was {}".format(e)
                    logger.info(msg)
                    output = None
            else:
                output = None

            return output
        else:
            return super(LazyLoadingSimulation,
                         self).__getattribute__(attr_name)
    def test_skip_traits_walker(self):
        # test functionality to skip traits
        sim = self.simulation
        sim.method.method_steps[1].editable = True

        walk_dataelement_editable(sim, False, ['method_steps'])

        self.assertEqual(sim.method.method_steps[1].editable, True)
    def set_as_run(self):
        """ Reset the run flags to be run.

        Note: run_status not set because it depends how the run went.
        """
        walk_dataelement_editable(self, False,
                                  skip_traits=['source_experiment'])
        self.has_run = True
 def set_as_not_run(self):
     """ Reset to not be run: updates flags and deletes output.
     """
     self.output = None
     walk_dataelement_editable(self, True,
                               skip_traits=['source_experiment'])
     self.has_run = False
     self.run_status = SIM_NOT_RUN
    def test_sim_walker(self):
        # test a couple items in simulation object tree are flipped properly
        sim = self.simulation
        sim.editable = True
        sim.method.method_steps[1].editable = True

        walk_dataelement_editable(sim, False)

        self.assertEqual(sim.editable, False)
        assert (not sim.method.method_steps[1].editable)