def test_get_cure_test_total_height_must_exceed_base_height(self, mock_load):
        mock_load.return_value = self.default_config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(10,1,1,2)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,1,1,2)
    def test_get_cure_test_total_height_must_exceed_base_height(self, mock_load):
        mock_load.return_value = self.DEFAULT_CONFIG
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(10,1,1,2)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,1,1,2)
    def test_get_cure_test_final_speed_exceeds_start_speed(self, mock_load):
        mock_load.return_value = self.DEFAULT_CONFIG
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1)

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,1,1)
    def test_get_cure_test_final_speed_exceeds_start_speed(self, mock_load):
        mock_load.return_value = self.default_config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1)

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,1,1)
 def test_get_cure_test_returns_a_layer_generator(self, mock_load):
     mock_load.return_value = self.DEFAULT_CONFIG
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     cure_test = configuration_API.get_cure_test(0,1,1,2)
     cure_test.next()
 def test_get_cure_test_returns_a_layer_generator(self, mock_load):
     mock_load.return_value = self.default_config
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     cure_test = configuration_API.get_cure_test(0,1,1,2)
     cure_test.next()
    def test_get_cure_test_values_must_be_positive_non_0_numbers_for_all_but_base(self, mock_load):
        mock_load.return_value = self.DEFAULT_CONFIG
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test('a',10,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,'a',10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,'a',1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,'a')
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1,'a')
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(-1,10,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,-10,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,-1,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,-1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1,-1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,0,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,0,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,0)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1,0)
    def test_get_cure_test_values_must_be_positive_non_0_numbers_for_all_but_base(self, mock_load):
        mock_load.return_value = self.default_config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test('a',10,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,'a',10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,'a',1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,'a')
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1,'a')
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(-1,10,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,-10,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,-1,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,-1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1,-1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,0,10,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,0,1)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,0)
        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1,0)
class CureTestUI(PeachyFrame):

    def initialize(self):
        self.grid()
        self._current_printer = self.kwargs['printer']
        self._configuration_api = ConfigurationAPI(self._configuration_manager)
        self._configuration_api.load_printer(self._current_printer)

        self._base_height = IntVar()
        self._base_height.set(3)
        self._total_height = IntVar()
        self._total_height.set(23)
        self._start_speed = IntVar()
        self._start_speed.set(50)
        self._stop_speed = IntVar()
        self._stop_speed.set(250)
        self._best_height = IntVar()
        self._best_height.set(0)

        Label(self, text = 'Printer: ').grid(column=0,row=10)
        Label(self, text = self._configuration_api.current_printer()).grid(column=1,row=10)
        Button(self, text='?', command=self._help).grid(column=2, row=10,stick=N+E)

        Label(self).grid(column=1,row=15)

        Label(self, text = "Base Height (mm)" ).grid(column=0,row=20)
        Entry(self, textvariable = self._base_height).grid(column=1, row=20)

        Label(self, text = "Total Height (mm)" ).grid(column=0,row=30)
        Entry(self, textvariable = self._total_height).grid(column=1, row=30)

        Label(self, text = "Start Speed (mm)" ).grid(column=0,row=40)
        Entry(self, textvariable = self._start_speed).grid(column=1, row=40)

        Label(self, text = "Finish Speed (mm)" ).grid(column=0,row=50)
        Entry(self, textvariable = self._stop_speed).grid(column=1, row=50)
        Label(self).grid(column=1,row=60)

        Button(self, text ="Run Test", command = self._start).grid(column=2,row=70,sticky=N+S+E)

        Label(self).grid(column=1,row=80)

        Label(self, text = "Best height above base (mm)" ).grid(column=0,row=90)
        self._best_height_field = Entry(self, textvariable = self._best_height)
        self._best_height_field.grid(column=1, row=90)
        
        Label(self).grid(column=1,row=100)

        Button(self, text ="Save", command = self._save).grid(column=2,row=110,sticky=N+S+W)
        Button(self, text ="Back", command = self._back).grid(column=0,row=110,sticky=N+S+W)

        self.update()

    def _back(self):
        self.navigate(SetupUI)

    def _help(self):
        PopUp(self,'Help', help_text.cure_test_help)

    def _save(self):
        try:
            speed = self._configuration_api.get_speed_at_height(
                    self._base_height.get(),
                    self._total_height.get(),
                    self._start_speed.get(),
                    self._stop_speed.get(),
                    self._best_height.get()
                    )
            self._configuration_api.set_speed(speed)
            self.navigate(SetupUI)
        except Exception as ex:
            tkMessageBox.showwarning("Error", ex.message)

    def _start(self):
        try:
            cure_test = self._configuration_api.get_cure_test(
                self._base_height.get(),
                self._total_height.get(),
                self._start_speed.get(),
                self._stop_speed.get()
                )
            self.navigate(PrintStatusUI,layer_generator = cure_test, config = self._configuration_api.get_current_config(), calling_class = CureTestUI, printer = self._current_printer)
        except Exception as ex:
            tkMessageBox.showwarning("Error", ex.message)

    def close(self):
        pass
class CureTestUI(PeachyFrame):
    def initialize(self):
        self.grid()
        self._current_printer = self.kwargs['printer']
        self._configuration_api = ConfigurationAPI(self._configuration_manager)
        self._configuration_api.load_printer(self._current_printer)

        self._base_height = IntVar()
        self._base_height.set(3)
        self._total_height = IntVar()
        self._total_height.set(23)
        self._start_speed = IntVar()
        self._start_speed.set(50)
        self._stop_speed = IntVar()
        self._stop_speed.set(250)
        self._best_height = IntVar()
        self._best_height.set(0)

        Label(self, text='Printer: ').grid(column=0, row=10)
        Label(self,
              text=self._configuration_api.current_printer()).grid(column=1,
                                                                   row=10)
        Button(self, text='?', command=self._help).grid(column=2,
                                                        row=10,
                                                        stick=N + E)

        Label(self).grid(column=1, row=15)

        Label(self, text="Base Height (mm)").grid(column=0, row=20)
        Entry(self, textvariable=self._base_height).grid(column=1, row=20)

        Label(self, text="Total Height (mm)").grid(column=0, row=30)
        Entry(self, textvariable=self._total_height).grid(column=1, row=30)

        Label(self, text="Start Speed (mm)").grid(column=0, row=40)
        Entry(self, textvariable=self._start_speed).grid(column=1, row=40)

        Label(self, text="Finish Speed (mm)").grid(column=0, row=50)
        Entry(self, textvariable=self._stop_speed).grid(column=1, row=50)
        Label(self).grid(column=1, row=60)

        Button(self, text="Run Test",
               command=self._start).grid(column=2, row=70, sticky=N + S + E)

        Label(self).grid(column=1, row=80)

        Label(self, text="Best height above base (mm)").grid(column=0, row=90)
        self._best_height_field = Entry(self, textvariable=self._best_height)
        self._best_height_field.grid(column=1, row=90)

        Label(self).grid(column=1, row=100)

        Button(self, text="Save", command=self._save).grid(column=2,
                                                           row=110,
                                                           sticky=N + S + W)
        Button(self, text="Back", command=self._back).grid(column=0,
                                                           row=110,
                                                           sticky=N + S + W)

        self.update()

    def _back(self):
        self.navigate(SetupUI)

    def _help(self):
        PopUp(self, 'Help', help_text.cure_test_help)

    def _save(self):
        try:
            speed = self._configuration_api.get_speed_at_height(
                self._base_height.get(), self._total_height.get(),
                self._start_speed.get(), self._stop_speed.get(),
                self._best_height.get())
            self._configuration_api.set_speed(speed)
            self.navigate(SetupUI)
        except Exception as ex:
            tkMessageBox.showwarning("Error", ex.message)

    def _start(self):
        try:
            cure_test = self._configuration_api.get_cure_test(
                self._base_height.get(), self._total_height.get(),
                self._start_speed.get(), self._stop_speed.get())
            self.navigate(PrintStatusUI,
                          layer_generator=cure_test,
                          config=self._configuration_api.get_current_config(),
                          calling_class=CureTestUI,
                          printer=self._current_printer)
        except Exception as ex:
            tkMessageBox.showwarning("Error", ex.message)

    def close(self):
        pass